-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start work on caps for forge, needed to make WorldlyContainer work
- Loading branch information
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
...n/java/dev/ithundxr/createnumismatics/forge/mixin/self/VendorBlockEntityCapabilities.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package dev.ithundxr.createnumismatics.forge.mixin.self; | ||
|
||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity; | ||
import dev.ithundxr.createnumismatics.content.vendor.VendorBlockEntity; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.WorldlyContainer; | ||
import net.minecraft.world.level.block.entity.BlockEntityType; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraftforge.common.capabilities.*; | ||
import net.minecraftforge.common.util.LazyOptional; | ||
import net.minecraftforge.items.IItemHandler; | ||
import net.minecraftforge.items.wrapper.SidedInvWrapper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
@Mixin(VendorBlockEntity.class) | ||
public abstract class VendorBlockEntityCapabilities extends SmartBlockEntity implements ICapabilityProvider { | ||
public VendorBlockEntityCapabilities(BlockEntityType<?> type, BlockPos pos, BlockState state) { | ||
super(type, pos, state); | ||
} | ||
|
||
private static Direction[] dirs = {Direction.UP, Direction.DOWN, Direction.NORTH}; | ||
LazyOptional<? extends IItemHandler>[] createNumismatics$handlers = SidedInvWrapper.create((WorldlyContainer) this, dirs); | ||
|
||
@Override | ||
public <T> @NotNull LazyOptional<T> getCapability(@NotNull Capability<T> capability, @Nullable Direction facing) { | ||
if (remove || facing == null || capability != ForgeCapabilities.ITEM_HANDLER) { | ||
return super.getCapability(capability, facing); | ||
} else if (facing == Direction.UP) { | ||
return createNumismatics$handlers[0].cast(); | ||
} else { | ||
return facing == Direction.DOWN ? createNumismatics$handlers[1].cast() : createNumismatics$handlers[2].cast(); | ||
} | ||
} | ||
|
||
@Override | ||
public void invalidateCaps() { | ||
super.invalidateCaps(); | ||
|
||
for (LazyOptional<? extends IItemHandler> createNumismatics$handler : createNumismatics$handlers) { | ||
createNumismatics$handler.invalidate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters