diff --git a/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java b/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java index c8b7a8996..bc360e0cd 100644 --- a/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java +++ b/src/main/java/techreborn/blockentity/cable/CableBlockEntity.java @@ -145,6 +145,57 @@ public class CableBlockEntity extends BlockEntity energyContainer.amount = energy; } + void appendTargets(List targetStorages) { + ServerWorld serverWorld = (ServerWorld) world; + if (serverWorld == null) { return; } + + // Update our targets if necessary. + if (targets == null) { + BlockState newBlockState = getCachedState(); + + targets = new ArrayList<>(); + for (Direction direction : Direction.values()) { + boolean foundSomething = false; + + BlockPos adjPos = getPos().offset(direction); + BlockEntity adjBe = serverWorld.getBlockEntity(adjPos); + + if (adjBe instanceof CableBlockEntity adjCable) { + if (adjCable.getCableType().transferRate == getCableType().transferRate) { + // Make sure cables are not used as regular targets. + foundSomething = true; + } + } else if (EnergyStorage.SIDED.find(serverWorld, adjPos, null, adjBe, direction.getOpposite()) != null) { + foundSomething = true; + targets.add(new CableTarget( + direction, + BlockApiCache.create(EnergyStorage.SIDED, serverWorld, adjPos) + )); + } + + newBlockState = newBlockState.with(CableBlock.PROPERTY_MAP.get(direction), foundSomething); + } + + serverWorld.setBlockState(getPos(), newBlockState); + } + + // Fill the list. + for (CableTarget target : targets) { + EnergyStorage storage = target.find(); + + if (storage == null) { + // Schedule a rebuild next tick. + // This is just a reference change, the iterator remains valid. + targets = null; + } else { + targetStorages.add(new OfferedEnergyStorage(this, target.directionTo, storage)); + } + } + + // Reset blocked sides. + blockedSides = 0; + } + // BlockEntity @Override public NbtCompound toInitialChunkDataNbt() { @@ -185,7 +236,7 @@ public class CableBlockEntity extends BlockEntity targets = null; } - // Tickable + // BlockEntityTicker @Override public void tick(World world, BlockPos pos, BlockState state, CableBlockEntity blockEntity2) { if (world == null || world.isClient) { @@ -228,62 +279,7 @@ public class CableBlockEntity extends BlockEntity return new ItemStack(getCableType().block); } - void appendTargets(List targetStorages) { - ServerWorld serverWorld = (ServerWorld) world; - - // Update our targets if necessary. - if (targets == null) { - BlockState newBlockState = getCachedState(); - - targets = new ArrayList<>(); - for (Direction direction : Direction.values()) { - boolean foundSomething = false; - - BlockPos adjPos = getPos().offset(direction); - BlockEntity adjBe = serverWorld.getBlockEntity(adjPos); - - if (adjBe instanceof CableBlockEntity adjCable && adjCable.getCableType() == getCableType()) { - // Make sure cables are not used as regular targets. - foundSomething = true; - } else if (EnergyStorage.SIDED.find(serverWorld, adjPos, null, adjBe, direction.getOpposite()) != null) { - foundSomething = true; - targets.add(new CableTarget( - direction, - BlockApiCache.create(EnergyStorage.SIDED, serverWorld, adjPos) - )); - } - - newBlockState = newBlockState.with(CableBlock.PROPERTY_MAP.get(direction), foundSomething); - } - - serverWorld.setBlockState(getPos(), newBlockState); - } - - // Fill the list. - for (CableTarget target : targets) { - EnergyStorage storage = target.find(); - - if (storage == null) { - // Schedule a rebuild next tick. - // This is just a reference change, the iterator remains valid. - targets = null; - } else { - targetStorages.add(new OfferedEnergyStorage(this, target.directionTo, storage)); - } - } - - // Reset blocked sides. - blockedSides = 0; - } - - private static final class CableTarget { - private final Direction directionTo; - private final BlockApiCache cache; - - CableTarget(Direction directionTo, BlockApiCache cache) { - this.directionTo = directionTo; - this.cache = cache; - } + private record CableTarget(Direction directionTo, BlockApiCache cache) { @Nullable EnergyStorage find() { diff --git a/src/main/java/techreborn/blocks/cable/CableBlock.java b/src/main/java/techreborn/blocks/cable/CableBlock.java index 7ea28f8f0..ed7330885 100644 --- a/src/main/java/techreborn/blocks/cable/CableBlock.java +++ b/src/main/java/techreborn/blocks/cable/CableBlock.java @@ -58,7 +58,6 @@ import org.jetbrains.annotations.Nullable; import reborncore.api.ToolManager; import reborncore.common.blocks.BlockWrenchEventHandler; import reborncore.common.util.WrenchUtils; -import team.reborn.energy.api.EnergyStorage; import techreborn.api.events.CableElectrocutionEvent; import techreborn.blockentity.cable.CableBlockEntity; import techreborn.config.TechRebornConfig; @@ -102,7 +101,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable { BlockWrenchEventHandler.wrenableBlocks.add(this); } - // BlockContainer + // BlockWithEntity @Override public BlockRenderType getRenderType(BlockState state) { return BlockRenderType.MODEL;