diff --git a/src/main/java/dev/galacticraft/mod/api/pipe/impl/PipeNetworkImpl.java b/src/main/java/dev/galacticraft/mod/api/pipe/impl/PipeNetworkImpl.java index 79a27927e..3b72481ba 100644 --- a/src/main/java/dev/galacticraft/mod/api/pipe/impl/PipeNetworkImpl.java +++ b/src/main/java/dev/galacticraft/mod/api/pipe/impl/PipeNetworkImpl.java @@ -60,7 +60,7 @@ public class PipeNetworkImpl extends SnapshotParticipant { long insert = (long) (requested * ratio); if (insert > 0) { diff --git a/src/main/java/dev/galacticraft/mod/content/block/special/aluminumwire/tier1/AluminumWireBlock.java b/src/main/java/dev/galacticraft/mod/content/block/special/aluminumwire/tier1/AluminumWireBlock.java index 792aab182..8dbf04fb6 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/special/aluminumwire/tier1/AluminumWireBlock.java +++ b/src/main/java/dev/galacticraft/mod/content/block/special/aluminumwire/tier1/AluminumWireBlock.java @@ -97,8 +97,8 @@ public void onPlace(BlockState blockState, Level level, BlockPos blockPos, Block } if (changed) { wire.setChanged(); + level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); } - level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); } } @@ -112,9 +112,9 @@ public void neighborChanged(BlockState blockState, Level level, BlockPos blockPo if (direction != null) { if (!level.isClientSide && wire.getConnections()[direction.ordinal()] != (wire.getConnections()[direction.ordinal()] = wire.canConnect(direction) && EnergyStorage.SIDED.find(level, neighborPos, direction.getOpposite()) != null)) { level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); + wire.setChanged(); } } - wire.setChanged(); } } diff --git a/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/GlassFluidPipeBlock.java b/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/GlassFluidPipeBlock.java index 0d7b42822..c826c6ad3 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/GlassFluidPipeBlock.java +++ b/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/GlassFluidPipeBlock.java @@ -29,6 +29,7 @@ import dev.galacticraft.mod.content.block.entity.networked.GlassFluidPipeBlockEntity; import dev.galacticraft.mod.content.item.StandardWrenchItem; import dev.galacticraft.mod.util.ConnectingBlockUtil; +import dev.galacticraft.mod.util.DirectionUtil; import dev.galacticraft.mod.util.FluidUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -80,11 +81,16 @@ public void setPlacedBy(Level level, BlockPos blockPos, BlockState blockState, @ livingEntity.setItemInHand(interactionHand, copy); } } + + // Regular Stuff + var changed = false; for (var direction : Constant.Misc.DIRECTIONS) { - var otherBlockEntity = level.getBlockEntity(blockPos.relative(direction)); - glassPipe.getConnections()[direction.ordinal()] = (otherBlockEntity instanceof Pipe pipe && pipe.canConnect(direction.getOpposite())) || FluidUtil.canAccessFluid(level, blockPos.relative(direction), direction); + changed |= glassPipe.getConnections()[direction.ordinal()] = glassPipe.canConnect(direction) && FluidUtil.canAccessFluid(level, blockPos.relative(direction), direction); + } + if (changed) { + glassPipe.setChanged(); + level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); } - level.updateNeighborsAt(blockPos, blockState.getBlock()); } } @@ -125,14 +131,20 @@ public InteractionResult use(BlockState blockState, Level level, BlockPos blockP @Override public void neighborChanged(BlockState blockState, Level level, BlockPos blockPos, Block block, BlockPos fromPos, boolean notify) { super.neighborChanged(blockState, level, blockPos, block, fromPos, notify); - var neighborState = level.getBlockState(fromPos); - var delta = fromPos.subtract(blockPos); - var direction = Direction.fromDelta(delta.getX(), delta.getY(), delta.getZ()); - - if (direction != null && level.getBlockEntity(blockPos) instanceof GlassFluidPipeBlockEntity glassPipe) { - var otherBlockEntity = level.getBlockEntity(fromPos); - glassPipe.getConnections()[direction.ordinal()] = !neighborState.isAir() && ((otherBlockEntity instanceof Pipe pipe && pipe.canConnect(direction.getOpposite())) || FluidUtil.canAccessFluid(level, fromPos, direction)); - level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); + + if (level.getBlockEntity(blockPos) instanceof PipeBlockEntity glassPipe) { + var direction = DirectionUtil.fromNormal(fromPos.getX() - blockPos.getX(), fromPos.getY() - blockPos.getY(), fromPos.getZ() - blockPos.getZ()); + + if (direction != null) { + if (!level.isClientSide + && glassPipe.getConnections()[direction.ordinal()] + != (glassPipe.getConnections()[direction.ordinal()] + = glassPipe.canConnect(direction) && FluidUtil.canAccessFluid(level, fromPos, direction)) + ) { + level.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_IMMEDIATE); + glassPipe.setChanged(); + } + } } } diff --git a/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/PipeBlockEntity.java b/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/PipeBlockEntity.java index d44c9d398..b1a882f57 100644 --- a/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/PipeBlockEntity.java +++ b/src/main/java/dev/galacticraft/mod/content/block/special/fluidpipe/PipeBlockEntity.java @@ -25,6 +25,7 @@ import dev.galacticraft.mod.api.pipe.Pipe; import dev.galacticraft.mod.api.pipe.PipeNetwork; import dev.galacticraft.mod.api.pipe.impl.PipeNetworkImpl; +import dev.galacticraft.mod.util.FluidUtil; import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; import net.fabricmc.fabric.api.transfer.v1.storage.Storage; import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; @@ -36,11 +37,11 @@ import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.DyeColor; +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 org.jetbrains.annotations.Nullable; -import team.reborn.energy.api.EnergyStorage; import java.util.Collections; import java.util.Iterator; @@ -103,7 +104,7 @@ public boolean[] getConnections() { @Override public void updateConnection(BlockState state, BlockPos pos, BlockPos neighborPos, Direction direction) { - boolean connected = this.canConnect(direction) && EnergyStorage.SIDED.find(this.level, neighborPos, direction.getOpposite()) != null; + boolean connected = this.canConnect(direction) && FluidUtil.canAccessFluid(this.level, neighborPos, direction); if (this.connections[direction.get3DDataValue()] != connected) { this.connections[direction.get3DDataValue()] = connected; this.level.sendBlockUpdated(pos, state, state, 0); @@ -138,7 +139,7 @@ public boolean supportsExtraction() { @Override public boolean supportsInsertion() { - return true; + return this.maxTransferRate > 0; } @Override @@ -161,6 +162,10 @@ public void load(CompoundTag nbt) { super.load(nbt); this.readColorNbt(nbt); this.readConnectionNbt(nbt); + + if (this.level != null && this.level.isClientSide) { + this.level.sendBlockUpdated(this.getBlockPos(), this.getBlockState(), this.getBlockState(), Block.UPDATE_IMMEDIATE); + } } @Override