diff --git a/src/main/java/de/ellpeck/naturesaura/Helper.java b/src/main/java/de/ellpeck/naturesaura/Helper.java index 9fd2c6f6..e6dfdd4d 100644 --- a/src/main/java/de/ellpeck/naturesaura/Helper.java +++ b/src/main/java/de/ellpeck/naturesaura/Helper.java @@ -140,7 +140,7 @@ public final class Helper { public static ActionResultType putStackOnTile(PlayerEntity player, Hand hand, BlockPos pos, int slot, boolean sound) { TileEntity tile = player.world.getTileEntity(pos); if (tile instanceof TileEntityImpl) { - IItemHandlerModifiable handler = ((TileEntityImpl) tile).getItemHandler(null); + IItemHandlerModifiable handler = ((TileEntityImpl) tile).getItemHandler(); if (handler != null) { ItemStack handStack = player.getHeldItem(hand); if (!handStack.isEmpty()) { @@ -176,18 +176,17 @@ public final class Helper { public static ICapabilityProvider makeRechargeProvider(ItemStack stack, boolean needsSelected) { return new ICapabilityProvider() { - private final IAuraRecharge recharge = (container, containerSlot, itemSlot, isSelected) -> { - if (isSelected || !needsSelected) { + private final LazyOptional recharge = LazyOptional.of(() -> (container, containerSlot, itemSlot, isSelected) -> { + if (isSelected || !needsSelected) return rechargeAuraItem(stack, container, 300); - } return false; - }; + }); @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { if (capability == NaturesAuraAPI.capAuraRecharge) - return LazyOptional.of(() -> (T) this.recharge); + return this.recharge.cast(); return LazyOptional.empty(); } }; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java index 50698de4..c06b1379 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockAncientLeaves.java @@ -63,7 +63,7 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP if (rand.nextFloat() >= 0.95F && !worldIn.getBlockState(pos.down()).isOpaqueCube(worldIn, pos)) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityAncientLeaves) { - if (((TileEntityAncientLeaves) tile).getAuraContainer(null).getStoredAura() > 0) { + if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() > 0) { NaturesAuraAPI.instance().spawnMagicParticle( pos.getX() + rand.nextDouble(), pos.getY(), pos.getZ() + rand.nextDouble(), 0F, 0F, 0F, 0xCC4780, @@ -82,7 +82,7 @@ public class BlockAncientLeaves extends LeavesBlock implements IModItem, IColorP if (!worldIn.isRemote) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityAncientLeaves) { - if (((TileEntityAncientLeaves) tile).getAuraContainer(null).getStoredAura() <= 0) { + if (((TileEntityAncientLeaves) tile).getAuraContainer().getStoredAura() <= 0) { worldIn.setBlockState(pos, ModBlocks.DECAYED_LEAVES.getDefaultState()); } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java index e8b8af38..7eae6a95 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/BlockGratedChute.java @@ -131,7 +131,7 @@ public class BlockGratedChute extends BlockContainerImpl implements ICustomBlock public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { TileEntity tile = worldIn.getTileEntity(pos); if (tile instanceof TileEntityGratedChute) { - IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler(null); + IItemHandler handler = ((TileEntityGratedChute) tile).getItemHandler(); ItemStack stack = handler.getStackInSlot(0); if (stack.isEmpty()) return 0; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java index 5f088999..c12eb83b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAncientLeaves.java @@ -29,7 +29,7 @@ public class TileEntityAncientLeaves extends TileEntityImpl { } @Override - public IAuraContainer getAuraContainer(Direction facing) { + public IAuraContainer getAuraContainer() { return this.container; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAuraTimer.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAuraTimer.java index 7e3bfe77..3df5b1d8 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAuraTimer.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityAuraTimer.java @@ -101,7 +101,7 @@ public class TileEntityAuraTimer extends TileEntityImpl implements ITickableTile } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return this.itemHandler; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityBlastFurnaceBooster.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityBlastFurnaceBooster.java index 9769e948..6481a79e 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityBlastFurnaceBooster.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityBlastFurnaceBooster.java @@ -80,7 +80,7 @@ public class TileEntityBlastFurnaceBooster extends TileEntityImpl implements ITi } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { TileEntity below = this.world.getTileEntity(this.pos.down()); if (!(below instanceof BlastFurnaceTileEntity)) return null; diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEndFlower.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEndFlower.java index f66e299d..c8090537 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEndFlower.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEndFlower.java @@ -105,7 +105,7 @@ public class TileEntityEndFlower extends TileEntityImpl implements ITickableTile } @Override - public IAuraContainer getAuraContainer(Direction facing) { + public IAuraContainer getAuraContainer() { return this.container; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEnderCrate.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEnderCrate.java index 58915931..fdce259d 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEnderCrate.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityEnderCrate.java @@ -80,7 +80,7 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { if (this.canOpen()) return this.wrappedEnderStorage; return null; @@ -146,6 +146,6 @@ public class TileEntityEnderCrate extends TileEntityImpl implements INamedContai @Nullable @Override public Container createMenu(int window, PlayerInventory inv, PlayerEntity player) { - return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler(null)); + return new ContainerEnderCrate(ModContainers.ENDER_CRATE, window, player, this.getItemHandler()); } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityGratedChute.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityGratedChute.java index c7e4a9c5..a44f5bbd 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityGratedChute.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityGratedChute.java @@ -145,7 +145,7 @@ public class TileEntityGratedChute extends TileEntityImpl implements ITickableTi } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return this.items; } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java index 064a3892..3ab5d76c 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityImpl.java @@ -28,6 +28,8 @@ import java.util.stream.Stream; public class TileEntityImpl extends TileEntity { public int redstonePower; + private LazyOptional itemHandler; + private LazyOptional auraContainer; public TileEntityImpl(TileEntityType tileEntityTypeIn) { super(tileEntityTypeIn); @@ -96,11 +98,11 @@ public class TileEntityImpl extends TileEntity { entities.forEach(e -> e.connection.sendPacket(packet)); } - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return null; } - public IAuraContainer getAuraContainer(Direction facing) { + public IAuraContainer getAuraContainer() { return null; } @@ -108,18 +110,33 @@ public class TileEntityImpl extends TileEntity { @Override public LazyOptional getCapability(Capability capability, @Nullable Direction facing) { if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { - IItemHandler handler = this.getItemHandler(facing); - return handler == null ? LazyOptional.empty() : LazyOptional.of(() -> (T) handler); + if (this.itemHandler == null) { + IItemHandler handler = this.getItemHandler(); + this.itemHandler = handler == null ? LazyOptional.empty() : LazyOptional.of(() -> handler); + } + return this.itemHandler.cast(); } else if (capability == NaturesAuraAPI.capAuraContainer) { - IAuraContainer container = this.getAuraContainer(facing); - return container == null ? LazyOptional.empty() : LazyOptional.of(() -> (T) container); + if (this.auraContainer == null) { + IAuraContainer container = this.getAuraContainer(); + this.auraContainer = container == null ? LazyOptional.empty() : LazyOptional.of(() -> container); + } + return this.auraContainer.cast(); } else { return super.getCapability(capability, facing); } } + @Override + public void remove() { + super.remove(); + if (this.itemHandler != null) + this.itemHandler.invalidate(); + if (this.auraContainer != null) + this.auraContainer.invalidate(); + } + public void dropInventory() { - IItemHandler handler = this.getItemHandler(null); + IItemHandler handler = this.getItemHandler(); if (handler != null) { for (int i = 0; i < handler.getSlots(); i++) { ItemStack stack = handler.getStackInSlot(i); diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java index ac9bf2f4..99bb1ba0 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityNatureAltar.java @@ -259,12 +259,12 @@ public class TileEntityNatureAltar extends TileEntityImpl implements ITickableTi } @Override - public IAuraContainer getAuraContainer(Direction facing) { + public IAuraContainer getAuraContainer() { return this.container; } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return this.items; } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityOfferingTable.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityOfferingTable.java index d1206cc4..bae1b34c 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityOfferingTable.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityOfferingTable.java @@ -139,7 +139,7 @@ public class TileEntityOfferingTable extends TileEntityImpl implements ITickable } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return this.items; } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityRFConverter.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityRFConverter.java index 8494ce22..52a5fbae 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityRFConverter.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityRFConverter.java @@ -22,6 +22,7 @@ import javax.annotation.Nullable; public class TileEntityRFConverter extends TileEntityImpl implements ITickableTileEntity { public final RFStorage storage = new RFStorage(); + private final LazyOptional storageOptional = LazyOptional.of(() -> this.storage); private int lastEnergy; public TileEntityRFConverter() { @@ -92,11 +93,17 @@ public class TileEntityRFConverter extends TileEntityImpl implements ITickableTi @Override public LazyOptional getCapability(Capability capability, @Nullable Direction facing) { if (capability == CapabilityEnergy.ENERGY) - return LazyOptional.of(() -> (T) this.storage); + return this.storageOptional.cast(); else return super.getCapability(capability, facing); } + @Override + public void remove() { + super.remove(); + this.storageOptional.invalidate(); + } + public static class RFStorage extends EnergyStorage { public RFStorage() { diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpring.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpring.java index b73ab439..67cd5cda 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpring.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntitySpring.java @@ -27,7 +27,7 @@ import net.minecraftforge.fluids.capability.templates.FluidTank; public class TileEntitySpring extends TileEntityImpl implements ITickableTileEntity { - private final IFluidHandler tank = new InfiniteTank(); + private final LazyOptional tank = LazyOptional.of(() -> new InfiniteTank()); private AABBTicket waterTicket; public TileEntitySpring() { @@ -124,7 +124,7 @@ public class TileEntitySpring extends TileEntityImpl implements ITickableTileEnt @Override public LazyOptional getCapability(Capability capability, Direction facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) - return LazyOptional.of(() -> (T) this.tank); + return this.tank.cast(); return LazyOptional.empty(); } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java index da8423dd..9e25d98b 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/TileEntityWoodStand.java @@ -220,7 +220,7 @@ public class TileEntityWoodStand extends TileEntityImpl implements ITickableTile } @Override - public IItemHandlerModifiable getItemHandler(Direction facing) { + public IItemHandlerModifiable getItemHandler() { return this.items; } } diff --git a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/render/RenderAuraTimer.java b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/render/RenderAuraTimer.java index 21a86d90..cb4109ea 100644 --- a/src/main/java/de/ellpeck/naturesaura/blocks/tiles/render/RenderAuraTimer.java +++ b/src/main/java/de/ellpeck/naturesaura/blocks/tiles/render/RenderAuraTimer.java @@ -27,7 +27,7 @@ public class RenderAuraTimer extends TileEntityRenderer { @Override public void render(TileEntityAuraTimer tile, float partialTicks, MatrixStack stack, IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) { - ItemStack bottle = tile.getItemHandler(null).getStackInSlot(0); + ItemStack bottle = tile.getItemHandler().getStackInSlot(0); if (bottle.isEmpty()) return; stack.push(); diff --git a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java index f83f9430..079f399b 100644 --- a/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java +++ b/src/main/java/de/ellpeck/naturesaura/chunk/AuraChunkProvider.java @@ -17,6 +17,7 @@ import javax.annotation.Nullable; public class AuraChunkProvider implements ICapabilityProvider, INBTSerializable { private final Chunk chunk; + private final LazyOptional lazyChunk = LazyOptional.of(this::getAuraChunk); private IAuraChunk auraChunk; public AuraChunkProvider(Chunk chunk) { @@ -32,7 +33,7 @@ public class AuraChunkProvider implements ICapabilityProvider, INBTSerializable< @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - return capability == NaturesAuraAPI.capAuraChunk ? LazyOptional.of(() -> (T) this.getAuraChunk()) : LazyOptional.empty(); + return capability == NaturesAuraAPI.capAuraChunk ? this.lazyChunk.cast() : LazyOptional.empty(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java index dfdfe881..21cf66b3 100644 --- a/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java +++ b/src/main/java/de/ellpeck/naturesaura/compat/CuriosCompat.java @@ -60,28 +60,30 @@ public class CuriosCompat implements ICompat { ItemStack stack = event.getObject(); if (TYPES.containsKey(stack.getItem())) { event.addCapability(new ResourceLocation(NaturesAura.MOD_ID, "curios"), new ICapabilityProvider() { + private final LazyOptional curio = LazyOptional.of(() -> new ICurio() { + @Override + public void curioTick(String identifier, int index, LivingEntity livingEntity) { + stack.getItem().inventoryTick(stack, livingEntity.world, livingEntity, -1, false); + + } + + @Override + public boolean canRightClickEquip() { + return true; + } + + @Override + public boolean canSync(String identifier, int index, LivingEntity livingEntity) { + return true; + } + }); + @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability cap, @Nullable Direction side) { if (cap != CuriosCapability.ITEM) return LazyOptional.empty(); - return LazyOptional.of(() -> (T) new ICurio() { - @Override - public void curioTick(String identifier, int index, LivingEntity livingEntity) { - stack.getItem().inventoryTick(stack, livingEntity.world, livingEntity, -1, false); - - } - - @Override - public boolean canRightClickEquip() { - return true; - } - - @Override - public boolean canSync(String identifier, int index, LivingEntity livingEntity) { - return true; - } - }); + return this.curio.cast(); } }); } diff --git a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java index 53d756e6..f8aec773 100644 --- a/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java +++ b/src/main/java/de/ellpeck/naturesaura/events/ClientEvents.java @@ -389,7 +389,7 @@ public class ClientEvents { mc, res, 35, blockStack.getDisplayName().getString(), null); if (tile instanceof TileEntityNatureAltar) { - ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler(null).getStackInSlot(0); + ItemStack tileStack = ((TileEntityNatureAltar) tile).getItemHandler().getStackInSlot(0); if (!tileStack.isEmpty()) { IAuraContainer stackCont = tileStack.getCapability(NaturesAuraAPI.capAuraContainer, null).orElse(null); if (stackCont != null) { @@ -405,7 +405,7 @@ public class ClientEvents { storage.getEnergyStored() + " / " + storage.getMaxEnergyStored() + " RF"); } else if (tile instanceof TileEntityGratedChute) { TileEntityGratedChute chute = (TileEntityGratedChute) tile; - ItemStack itemStack = chute.getItemHandler(null).getStackInSlot(0); + ItemStack itemStack = chute.getItemHandler().getStackInSlot(0); if (itemStack.isEmpty()) mc.fontRenderer.drawStringWithShadow(stack, @@ -430,7 +430,7 @@ public class ClientEvents { GlStateManager.enableDepthTest(); } else if (tile instanceof TileEntityAuraTimer) { TileEntityAuraTimer timer = (TileEntityAuraTimer) tile; - ItemStack itemStack = timer.getItemHandler(null).getStackInSlot(0); + ItemStack itemStack = timer.getItemHandler().getStackInSlot(0); if (!itemStack.isEmpty()) { Helper.renderItemInGui(itemStack, x - 20, y - 20, 1); mc.fontRenderer.drawStringWithShadow(stack, TextFormatting.GRAY + this.createTimeString(timer.getTotalTime()), x + 5, y - 11, 0xFFFFFF); diff --git a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java index 10fbe3e0..cf4fabd9 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java +++ b/src/main/java/de/ellpeck/naturesaura/items/ItemAuraCache.java @@ -99,13 +99,13 @@ public class ItemAuraCache extends ItemImpl implements ITrinketItem { @Override public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundNBT nbt) { return new ICapabilityProvider() { - private final ItemAuraContainer container = new ItemAuraContainer(stack, null, ItemAuraCache.this.capacity); + private final LazyOptional container = LazyOptional.of(() -> new ItemAuraContainer(stack, null, ItemAuraCache.this.capacity)); @Nonnull @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { if (capability == NaturesAuraAPI.capAuraContainer) { - return LazyOptional.of(() -> (T) this.container); + return this.container.cast(); } else { return LazyOptional.empty(); } diff --git a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java index b32dedfa..6e90e5f1 100644 --- a/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java +++ b/src/main/java/de/ellpeck/naturesaura/misc/WorldData.java @@ -31,11 +31,12 @@ public class WorldData implements IWorldData { public final List recentlyConvertedMossStones = new ArrayList<>(); private final Map enderStorages = new HashMap<>(); public final Set spawnLamps = new HashSet<>(); + private final LazyOptional lazyThis = LazyOptional.of(() -> this); @Nullable @Override public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction facing) { - return capability == NaturesAuraAPI.capWorldData ? LazyOptional.of(() -> (T) this) : LazyOptional.empty(); + return capability == NaturesAuraAPI.capWorldData ? this.lazyThis.cast() : LazyOptional.empty(); } @Override diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 970442e7..5bccab69 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -254,7 +254,7 @@ public final class ModRegistry { IForgeContainerType.create((windowId, inv, data) -> { TileEntity tile = inv.player.world.getTileEntity(data.readBlockPos()); if (tile instanceof TileEntityEnderCrate) - return new ContainerEnderCrate(ModContainers.ENDER_CRATE, windowId, inv.player, ((TileEntityEnderCrate) tile).getItemHandler(null)); + return new ContainerEnderCrate(ModContainers.ENDER_CRATE, windowId, inv.player, ((TileEntityEnderCrate) tile).getItemHandler()); return null; }).setRegistryName("ender_crate"), IForgeContainerType.create((windowId, inv, data) -> {