From c2bcbfe56f319c1e3612e631a7c09750670ac07c Mon Sep 17 00:00:00 2001 From: Mrbysco Date: Mon, 4 Mar 2024 21:38:02 +0100 Subject: [PATCH] Rest of the tiles done --- .../mod/tile/TileEntityFluidCollector.java | 4 +--- .../mod/tile/TileEntityHeatCollector.java | 1 - .../tile/TileEntityItemInterfaceHopping.java | 10 ++++----- .../mod/tile/TileEntityLaserRelayEnergy.java | 16 +++++++------- .../mod/tile/TileEntityLaserRelayFluids.java | 18 ++++++++------- .../mod/tile/TileEntityLaserRelayItem.java | 5 ++--- .../TileEntityLaserRelayItemAdvanced.java | 3 ++- .../mod/tile/TileEntityLeafGenerator.java | 4 +--- .../mod/tile/TileEntityLongRangeBreaker.java | 4 +--- .../mod/tile/TileEntityOilGenerator.java | 2 +- .../mod/tile/TileEntityPhantomEnergyface.java | 16 +++++++++----- .../mod/tile/TileEntityPhantomItemface.java | 16 +++++++++----- .../mod/tile/TileEntityPhantomLiquiface.java | 18 ++++++++++----- .../tile/TileEntityPhantomRedstoneface.java | 6 ----- .../mod/tile/TileEntityPhantomface.java | 22 ------------------- .../mod/tile/TileEntityPlayerInterface.java | 12 +++++----- .../mod/tile/TileEntityPoweredFurnace.java | 13 +++++------ .../mod/tile/TileEntityShockSuppressor.java | 20 ++++++++--------- .../mod/tile/TileEntityVerticalDigger.java | 8 +++---- .../actuallyadditions/mod/util/WorldUtil.java | 6 ++--- 20 files changed, 92 insertions(+), 112 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java index 819a076bc..088100c44 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFluidCollector.java @@ -34,7 +34,6 @@ import net.minecraft.world.level.block.LiquidBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.IFluidBlock; @@ -73,7 +72,6 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing return super.drain(resource, action); } }; - public final LazyOptional lazyTank = LazyOptional.of(() -> this.tank); private int lastTankAmount; private int currentTime; private int lastCompare; @@ -147,7 +145,7 @@ public class TileEntityFluidCollector extends TileEntityBase implements ISharing @Override public IFluidHandler getFluidHandler(Direction facing) { - return this.lazyTank; + return this.tank; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java index dcebcf24b..46d539a05 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityHeatCollector.java @@ -22,7 +22,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.MagmaBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java index ae7ed51ea..604593595 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityItemInterfaceHopping.java @@ -26,11 +26,11 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.world.phys.AABB; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.items.IItemHandler; import java.util.List; +import java.util.Optional; public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { @@ -77,7 +77,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { // } } - LazyOptional handler = tile.itemHandler.getNormalHandler(); + Optional handler = Optional.ofNullable(tile.itemHandler.getNormalHandler()); handler.ifPresent(cap -> { for (int i = 0; i < cap.getSlots(); i++) { ItemStack left = cap.insertItem(i, item.getItem(), false); @@ -111,7 +111,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { BlockEntity from = this.level.getBlockEntity(this.getBlockPos().relative(Direction.UP)); if (from != null && !(from instanceof TileEntityItemInterface)) { - LazyOptional normal = from.getCapability(Capabilities.ITEM_HANDLER, Direction.DOWN); + IItemHandler normal = this.level.getCapability(Capabilities.ItemHandler.BLOCK, from.getBlockPos(), Direction.DOWN); Object slotless = null; // TODO: [port] add back @@ -132,7 +132,7 @@ public class TileEntityItemInterfaceHopping extends TileEntityItemInterface { if (this.level.isLoaded(toPos)) { BlockEntity to = this.level.getBlockEntity(toPos); if (to != null && !(to instanceof TileEntityItemInterface)) { - LazyOptional normal = to.getCapability(Capabilities.ITEM_HANDLER, facing.getOpposite()); + IItemHandler normal = this.level.getCapability(Capabilities.ItemHandler.BLOCK, to.getBlockPos(), facing.getOpposite()); Object slotless = null; // TODO: [port] Add back diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java index 04c7c712e..1061d8406 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayEnergy.java @@ -30,12 +30,12 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.HashMap; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -115,9 +115,9 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { // TODO: [port] this is super hacky, review and fix up @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return LazyOptional.of(() -> this.energyStorages[facing == null - ? 0 - : facing.ordinal()]); + return this.energyStorages[facing == null + ? 0 + : facing.ordinal()]; } @Override @@ -136,7 +136,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityLaserRelay)) { - if (tile.getCapability(Capabilities.ENERGY, side.getOpposite()).isPresent()) { + if (this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), side.getOpposite()) != null) { this.receiversAround.put(side, tile); BlockEntity oldTile = old.get(side); @@ -179,7 +179,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { Direction opp = facing.getOpposite(); if (tile != null) { - Boolean received = tile.getCapability(Capabilities.ENERGY, opp).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false); + Boolean received = Optional.ofNullable(this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), opp)).map(cap -> cap.receiveEnergy(maxTransfer, true) > 0).orElse(false); if (received) { totalReceiverAmount++; workedOnce = true; @@ -213,7 +213,7 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay { if (!alreadyChecked.contains(tile.getBlockPos())) { alreadyChecked.add(tile.getBlockPos()); if (theRelay != this || side != from) { - transmitted += tile.getCapability(Capabilities.ENERGY, opp).map(cap -> { + transmitted += Optional.ofNullable(this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), opp)).map(cap -> { int trans = 0; int theoreticalReceived = cap.receiveEnergy(Math.min(amountPer, lowestCap), true); if (theoreticalReceived > 0) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java index 6299c9bf5..38be98e98 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayFluids.java @@ -28,8 +28,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.capability.IFluidHandler; @@ -37,6 +36,7 @@ import javax.annotation.Nonnull; import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -112,7 +112,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { super.serverTick(); if (this.mode == Mode.INPUT_ONLY) { for (Direction side : this.handlersAround.keySet()) { - WorldUtil.doFluidInteraction(this.handlersAround.get(side), this, side.getOpposite(), Integer.MAX_VALUE); + WorldUtil.doFluidInteraction(this.level, this.handlersAround.get(side).getBlockPos(), this.getBlockPos(), side.getOpposite(), Integer.MAX_VALUE); } } } @@ -133,7 +133,7 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityLaserRelay)) { - if (tile.getCapability(Capabilities.FLUID_HANDLER, side.getOpposite()).isPresent()) { + if (this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), side.getOpposite()) != null) { this.handlersAround.put(side, tile); BlockEntity oldTile = old.get(side); @@ -156,9 +156,9 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { // TODO: [port] super hacky, find better way of handling this. @Override public IFluidHandler getFluidHandler(Direction facing) { - return LazyOptional.of(() -> this.fluidHandlers[facing == null + return this.fluidHandlers[facing == null ? 0 - : facing.ordinal()]); + : facing.ordinal()]; } private int transmitFluid(Direction from, FluidStack stack, IFluidHandler.FluidAction action) { @@ -194,7 +194,8 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { BlockEntity tile = theRelay.handlersAround.get(facing); Direction opp = facing.getOpposite(); - boolean received = tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false); + boolean received = Optional.ofNullable(this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), opp)) + .map(cap -> cap.fill(stack, IFluidHandler.FluidAction.SIMULATE) > 0).orElse(false); if (received) { totalReceiverAmount++; workedOnce = true; @@ -225,7 +226,8 @@ public class TileEntityLaserRelayFluids extends TileEntityLaserRelay { if (!alreadyChecked.contains(tile.getBlockPos())) { alreadyChecked.add(tile.getBlockPos()); if (theRelay != this || side != from) { - transmitted += tile.getCapability(Capabilities.FLUID_HANDLER, opp).map(cap -> { + transmitted += Optional.ofNullable(this.level.getCapability(Capabilities.FluidHandler.BLOCK, tile.getBlockPos(), opp)) + .map(cap -> { int trans = 0; FluidStack copy = stack.copy(); copy.setAmount(amountPer); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java index b85bf4261..535ee4f3f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItem.java @@ -31,8 +31,7 @@ import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.items.IItemHandler; import java.util.HashMap; @@ -92,7 +91,7 @@ public class TileEntityLaserRelayItem extends TileEntityLaserRelay { if (this.level.hasChunkAt(pos)) { BlockEntity tile = this.level.getBlockEntity(pos); if (tile != null && !(tile instanceof TileEntityItemInterface) && !(tile instanceof TileEntityLaserRelay)) { - LazyOptional itemHandler = tile.getCapability(Capabilities.ITEM_HANDLER, side.getOpposite()); + IItemHandler itemHandler = this.level.getCapability(Capabilities.ItemHandler.BLOCK, tile.getBlockPos(), side.getOpposite()); Object slotlessHandler = null; // TODO: [port] add this back maybe? diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java index e95625d47..7f5a640ec 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLaserRelayItemAdvanced.java @@ -31,6 +31,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import javax.annotation.Nullable; +import java.util.Optional; public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem implements IButtonReactor, MenuProvider { @@ -99,7 +100,7 @@ public class TileEntityLaserRelayItemAdvanced extends TileEntityLaserRelayItem i private void addWhitelistSmart(boolean output) { for (SlotlessableItemHandlerWrapper handler : this.handlersAround.values()) { - handler.getNormalHandler().ifPresent(itemHandler -> { + Optional.ofNullable(handler.getNormalHandler()).ifPresent(itemHandler -> { for (int i = 0; i < itemHandler.getSlots(); i++) { ItemStack stack = itemHandler.getStackInSlot(i); if (!stack.isEmpty()) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java index 5e4263222..d41c9754e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLeafGenerator.java @@ -22,7 +22,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.LeavesBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; @@ -32,7 +31,6 @@ import java.util.List; public class TileEntityLeafGenerator extends TileEntityBase implements ISharingEnergyProvider, IEnergyDisplay { public final CustomEnergyStorage storage = new CustomEnergyStorage(35000, 0, 450); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int nextUseCounter; private int oldEnergy; @@ -140,6 +138,6 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java index 107324e79..f12fc68c5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityLongRangeBreaker.java @@ -30,7 +30,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nullable; @@ -41,7 +40,6 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen public static final int RANGE = 8; public static final int ENERGY_USE = 5; public final CustomEnergyStorage storage = new CustomEnergyStorage(10000, 20, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int lastEnergy; private int currentTime; @@ -142,7 +140,7 @@ public class TileEntityLongRangeBreaker extends TileEntityInventoryBase implemen @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java index 5cf78e177..4afd3f977 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityOilGenerator.java @@ -137,7 +137,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements ISharingEn } else if (!tile.isRedstonePowered) { RecipeHolder recipeHolder = tile.getRecipeForCurrentFluid(); - if (recipeHolder != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipeHolder.getFuelAmount()) { + if (recipeHolder != null && tile.storage.getEnergyStored() < tile.storage.getMaxEnergyStored() && tile.tank.getFluidAmount() >= recipeHolder.value().getFuelAmount()) { LiquidFuelRecipe recipe = recipeHolder.value(); tile.fuelUsage = recipe.getFuelAmount(); tile.currentEnergyProduce = recipe.getTotalEnergy() / recipe.getBurnTime(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java index c0e0b91be..14a2e6adf 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomEnergyface.java @@ -17,8 +17,8 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.capabilities.Capability; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.energy.IEnergyStorage; public class TileEntityPhantomEnergyface extends TileEntityPhantomface implements ISharingEnergyProvider { @@ -45,7 +45,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement BlockEntity tile = this.level.getBlockEntity(this.boundPosition); if (tile != null && !(tile instanceof TileEntityLaserRelayEnergy)) { for (Direction facing : Direction.values()) { - if (tile.getCapability(Capabilities.ENERGY, facing).isPresent()) { + if (this.level.getCapability(Capabilities.EnergyStorage.BLOCK, tile.getBlockPos(), facing) != null) { return true; } } @@ -55,8 +55,14 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement } @Override - protected boolean isCapabilitySupported(Capability capability) { - return capability == Capabilities.ENERGY; + public IEnergyStorage getEnergyStorage(Direction facing) { + if (this.isBoundThingInRange()) { + BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); + if (tile != null) { + return this.level.getCapability(Capabilities.EnergyStorage.BLOCK, this.getBoundPosition(), facing); + } + } + return null; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java index ba7131ba7..3ca3dfd39 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomItemface.java @@ -19,8 +19,8 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.capabilities.Capability; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.items.IItemHandler; public class TileEntityPhantomItemface extends TileEntityPhantomface { @@ -52,7 +52,7 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface { BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); if (tile != null) { for (Direction facing : Direction.values()) { - if (tile.getCapability(Capabilities.ITEM_HANDLER, facing).isPresent()) { + if (this.level.getCapability(Capabilities.ItemHandler.BLOCK, this.getBoundPosition(), facing) != null) { return true; } } @@ -62,8 +62,14 @@ public class TileEntityPhantomItemface extends TileEntityPhantomface { } @Override - protected boolean isCapabilitySupported(Capability capability) { - return capability == Capabilities.ITEM_HANDLER; + public IItemHandler getItemHandler(Direction facing) { + if (this.isBoundThingInRange()) { + BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); + if (tile != null) { + return this.level.getCapability(Capabilities.ItemHandler.BLOCK, this.getBoundPosition(), facing); + } + } + return null; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java index 12185f52c..bd5a1a5dd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomLiquiface.java @@ -17,8 +17,8 @@ import net.minecraft.core.Direction; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.capabilities.Capability; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements ISharingFluidHandler { @@ -42,10 +42,10 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements @Override public boolean isBoundThingInRange() { if (super.isBoundThingInRange()) { - BlockEntity tile = this.level.getBlockEntity(this.boundPosition); + BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); if (tile != null && !(tile instanceof TileEntityLaserRelayFluids)) { for (Direction facing : Direction.values()) { - if (tile.getCapability(Capabilities.FLUID_HANDLER, facing).isPresent()) { + if (this.level.getCapability(Capabilities.FluidHandler.BLOCK, this.getBoundPosition(), facing) != null) { return true; } } @@ -55,8 +55,14 @@ public class TileEntityPhantomLiquiface extends TileEntityPhantomface implements } @Override - protected boolean isCapabilitySupported(Capability capability) { - return capability == Capabilities.FLUID_HANDLER; + public IFluidHandler getFluidHandler(Direction facing) { + if (this.isBoundThingInRange()) { + BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); + if (tile != null) { + return this.level.getCapability(Capabilities.FluidHandler.BLOCK, this.getBoundPosition(), facing); + } + } + return null; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java index 0c63ca29a..a046924a9 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomRedstoneface.java @@ -17,7 +17,6 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.capabilities.Capability; import java.util.Arrays; @@ -71,9 +70,4 @@ public class TileEntityPhantomRedstoneface extends TileEntityPhantomface { super.onUpdateSent(); } - - @Override - protected boolean isCapabilitySupported(Capability capability) { - return false; - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java index 3dbf4405b..88eebcb9d 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPhantomface.java @@ -14,21 +14,14 @@ import de.ellpeck.actuallyadditions.api.tile.IPhantomTile; import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks; import de.ellpeck.actuallyadditions.mod.blocks.BlockPhantom; import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; -import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.neoforged.api.distmarker.Dist; import net.neoforged.api.distmarker.OnlyIn; -import net.neoforged.neoforge.common.capabilities.Capability; -import net.neoforged.neoforge.common.util.LazyOptional; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; public abstract class TileEntityPhantomface extends TileEntityInventoryBase implements IPhantomTile { public static final int RANGE = 16; @@ -186,21 +179,6 @@ public abstract class TileEntityPhantomface extends TileEntityInventoryBase impl return this.range; } - protected abstract boolean isCapabilitySupported(Capability capability); - - @Nonnull - @Override - public LazyOptional getCapability(@Nonnull Capability capability, @Nullable Direction side) { - if (this.isBoundThingInRange() && this.isCapabilitySupported(capability)) { - BlockEntity tile = this.level.getBlockEntity(this.getBoundPosition()); - if (tile != null) { - return tile.getCapability(capability, side); - } - } - - return LazyOptional.empty(); - } - @Override public int getComparatorStrength() { if (this.isBoundThingInRange()) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java index 92777175e..449dadb47 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPlayerInterface.java @@ -20,19 +20,18 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.capabilities.Capabilities; -import net.neoforged.neoforge.common.util.LazyOptional; +import net.neoforged.neoforge.capabilities.Capabilities; import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.items.wrapper.PlayerInvWrapper; +import java.util.Optional; import java.util.UUID; public class TileEntityPlayerInterface extends TileEntityBase implements IEnergyDisplay { public static final int DEFAULT_RANGE = 32; private final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 50, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public UUID connectedPlayer; public String playerName; private IItemHandler playerHandler; @@ -69,7 +68,7 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy : new PlayerInvWrapper(player.getInventory()); } - return LazyOptional.of(() -> this.playerHandler); + return this.playerHandler; } public static void clientTick(Level level, BlockPos pos, BlockState state, T t) { @@ -93,7 +92,8 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy ItemStack slot = player.getInventory().getItem(i); if (StackUtil.isValid(slot) && slot.getCount() == 1) { - int received = slot.getCapability(Capabilities.ENERGY).map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); + int received = Optional.ofNullable(slot.getCapability(Capabilities.EnergyStorage.ITEM)) + .map(cap -> cap.receiveEnergy(tile.storage.getEnergyStored(), false)).orElse(0); if (received > 0) { tile.storage.extractEnergyInternal(received, false); } @@ -149,6 +149,6 @@ public class TileEntityPlayerInterface extends TileEntityBase implements IEnergy @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java index ea7806ef1..5ddcd6966 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityPoweredFurnace.java @@ -27,6 +27,7 @@ import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.item.crafting.RecipeType; import net.minecraft.world.item.crafting.SmeltingRecipe; import net.minecraft.world.level.Level; @@ -34,7 +35,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import javax.annotation.Nonnull; @@ -50,7 +50,6 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements public static final int ENERGY_USE = 25; private static final int SMELT_TIME = 80; public final CustomEnergyStorage storage = new CustomEnergyStorage(30000, 150, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public int firstSmeltTime; public int secondSmeltTime; public boolean isAutoSplit; @@ -194,10 +193,10 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements } public Optional getOutputForInput(ItemStack stack) { - return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level).map(recipe -> recipe.getResultItem(this.level.registryAccess())); + return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level).map(recipe -> recipe.value().getResultItem(this.level.registryAccess())); } - public Optional getRecipeForInput(ItemStack stack) { + public Optional> getRecipeForInput(ItemStack stack) { return level.getServer().getRecipeManager().getRecipeFor(RecipeType.SMELTING, new SingleItem(stack), level); } @@ -215,8 +214,8 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements ItemStack input = this.inv.getStackInSlot(theInput); ItemStack output = this.inv.getStackInSlot(theOutput); if (!input.isEmpty()) { - Optional recipe = getRecipeForInput(input); - return recipe.map($ -> output.isEmpty() || ItemStack.isSameItem(output, $.getResultItem(this.level.registryAccess())) && output.getCount() <= output.getMaxStackSize() - $.getResultItem(this.level.registryAccess()).getCount()).orElse(false); + Optional> recipe = getRecipeForInput(input); + return recipe.map($ -> output.isEmpty() || ItemStack.isSameItem(output, $.value().getResultItem(this.level.registryAccess())) && output.getCount() <= output.getMaxStackSize() - $.value().getResultItem(this.level.registryAccess()).getCount()).orElse(false); } return false; } @@ -250,7 +249,7 @@ public class TileEntityPoweredFurnace extends TileEntityInventoryBase implements @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } @Nonnull diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java index 5bf4707c7..87c9bd8f6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityShockSuppressor.java @@ -17,7 +17,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import java.util.ArrayList; @@ -31,7 +30,6 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy public static final int RANGE = 5; public CustomEnergyStorage storage = new CustomEnergyStorage(300000, 400, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); private int oldEnergy; public TileEntityShockSuppressor(BlockPos pos, BlockState state) { @@ -47,14 +45,14 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy } } - @Override - public void invalidateCaps() { - super.invalidateCaps(); - - if (!this.level.isClientSide) { - SUPPRESSORS.remove(this); - } - } +// @Override +// public void invalidateCaps() { +// super.invalidateCaps(); +// +// if (!this.level.isClientSide) { +// SUPPRESSORS.remove(this); +// } +// } public static void clientTick(Level level, BlockPos pos, BlockState state, T t) { if (t instanceof TileEntityShockSuppressor tile) { @@ -100,6 +98,6 @@ public class TileEntityShockSuppressor extends TileEntityBase implements IEnergy @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java index e58360bdd..ca0406e85 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityVerticalDigger.java @@ -20,6 +20,7 @@ import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; @@ -38,10 +39,8 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.common.TierSortingRegistry; import net.neoforged.neoforge.common.util.FakePlayerFactory; -import net.neoforged.neoforge.common.util.LazyOptional; import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.fluids.IFluidBlock; -import net.neoforged.neoforge.registries.BuiltInRegistries; import javax.annotation.Nullable; import java.util.List; @@ -51,7 +50,6 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements public static final int ENERGY_USE_PER_BLOCK = 650; public static final int DEFAULT_RANGE = 2; public final CustomEnergyStorage storage = new CustomEnergyStorage(200000, 2000, 0); - public final LazyOptional lazyEnergy = LazyOptional.of(() -> this.storage); public boolean onlyMineOres; public int checkX; public int checkY = -1; @@ -210,7 +208,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements } private boolean isBlacklisted(Block block) { - String reg = BuiltInRegistries.BLOCK.getKey(block).toString(); + String reg = BuiltInRegistries.BLOCK.getKey(block).toString(); if (!reg.isEmpty()) { for (String string : ConfigStringListValues.MINER_BLACKLIST.getValue()) { if (reg.equals(string)) { @@ -250,7 +248,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements @Override public IEnergyStorage getEnergyStorage(Direction facing) { - return this.lazyEnergy; + return this.storage; } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java index 8d9eafd85..c135916c4 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/WorldUtil.java @@ -186,9 +186,9 @@ public final class WorldUtil { //Everything else try { FakePlayer fake = FakePlayerFactory.getMinecraft((ServerLevel) level); - if (fake.connection == null) { - fake.connection = new NetHandlerSpaghettiServer(fake); - } +// if (fake.connection == null) { +// fake.connection = new NetHandlerSpaghettiServer(fake); +// } //ItemStack heldBefore = fake.getMainHandItem(); setHandItemWithoutAnnoyingSound(fake, InteractionHand.MAIN_HAND, stack.copy()); BlockHitResult ray = new BlockHitResult(new Vec3(0.5, 0.5, 0.5), side.getOpposite(), offsetPos, true);