From 90ecc7c220f7bc8f9b355c01ece6f495da9316cf Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:03:09 +0100 Subject: [PATCH] Fix #127: Re-enable joints when placing attachments --- .../moderndynamics/pipe/PipeBlockEntity.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/technici4n/moderndynamics/pipe/PipeBlockEntity.java b/src/main/java/dev/technici4n/moderndynamics/pipe/PipeBlockEntity.java index 580ee13..b2809df 100644 --- a/src/main/java/dev/technici4n/moderndynamics/pipe/PipeBlockEntity.java +++ b/src/main/java/dev/technici4n/moderndynamics/pipe/PipeBlockEntity.java @@ -321,10 +321,7 @@ public void updateCachedShape(int pipeConnections, int inventoryConnections) { cachedShape = PipeBoundingBoxes.getPipeShape(pipeConnections, inventoryConnections, attachments); } - /** - * Update connection blacklist for a side, and schedule a node update, on the server side. - */ - protected void updateConnection(Direction side, boolean addConnection) { + private void updateConnectionBlacklist(Direction side, boolean addConnection) { if (level.isClientSide()) { throw new IllegalStateException("updateConnections() should not be called client-side."); } @@ -347,6 +344,13 @@ protected void updateConnection(Direction side, boolean addConnection) { } neighborPipe.setChanged(); } + } + + /** + * Update connection blacklist for a side, and schedule a node update, on the server side. + */ + protected void updateConnection(Direction side, boolean addConnection) { + updateConnectionBlacklist(side, addConnection); // Schedule inventory and network updates. refreshHosts(); @@ -441,6 +445,11 @@ public ItemInteractionResult useItemOn(Player player, InteractionHand hand, Bloc for (var host : getHosts()) { if (host.acceptsAttachment(attachmentItem, stack)) { if (!level.isClientSide) { + // Re-enable connection when an attachment is added to it if was previously disabled. + // (Attachments on disabled connections don't work as expected, + // yet there is no visual indication. So we just disallow that.) + updateConnectionBlacklist(hitSide, true); + host.setAttachment(hitSide, attachmentItem, new CompoundTag(), level.registryAccess()); host.getAttachment(hitSide).onPlaced(player); level.blockUpdated(worldPosition, getBlockState().getBlock());