diff --git a/src/main/java/mekanism/common/content/network/transmitter/DiversionTransporter.java b/src/main/java/mekanism/common/content/network/transmitter/DiversionTransporter.java index 161d78c516b..d3b3f95bf53 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/DiversionTransporter.java +++ b/src/main/java/mekanism/common/content/network/transmitter/DiversionTransporter.java @@ -120,9 +120,10 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider, } @Override - public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - super.handleUpdateTag(tag, provider); + public boolean handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + boolean refreshModelData = super.handleUpdateTag(tag, provider); readModes(tag); + return refreshModelData; } public void updateMode(Direction side, DiversionControl mode) { diff --git a/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporter.java b/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporter.java index 55f9bdc29b0..07a8afacfff 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporter.java +++ b/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporter.java @@ -109,8 +109,14 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider, } @Override - public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - super.handleUpdateTag(tag, provider); - setColor(NBTUtils.getEnum(tag, SerializationConstants.COLOR, EnumColor.BY_ID)); + public boolean handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + boolean refreshModelData = super.handleUpdateTag(tag, provider); + EnumColor color = NBTUtils.getEnum(tag, SerializationConstants.COLOR, EnumColor.BY_ID); + if (this.color != color) { + setColor(color); + //Color changed, mark the model data as needing to be refreshed + refreshModelData = true; + } + return refreshModelData; } } \ No newline at end of file diff --git a/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java b/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java index cb3fae235ae..32a3c3684bd 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java +++ b/src/main/java/mekanism/common/content/network/transmitter/LogisticalTransporterBase.java @@ -352,8 +352,8 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider, } @Override - public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - super.handleUpdateTag(tag, provider); + public boolean handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + boolean refreshModelData = super.handleUpdateTag(tag, provider); transit.clear(); if (tag.contains(SerializationConstants.ITEMS, Tag.TAG_LIST)) { ListTag tagList = tag.getList(SerializationConstants.ITEMS, Tag.TAG_COMPOUND); @@ -363,6 +363,7 @@ public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Prov addStack(compound.getInt(SerializationConstants.INDEX), stack); } } + return refreshModelData; } @Override diff --git a/src/main/java/mekanism/common/content/network/transmitter/ThermodynamicConductor.java b/src/main/java/mekanism/common/content/network/transmitter/ThermodynamicConductor.java index 9bbb3adaa14..01422c260dc 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/ThermodynamicConductor.java +++ b/src/main/java/mekanism/common/content/network/transmitter/ThermodynamicConductor.java @@ -125,9 +125,10 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider, } @Override - public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - super.handleUpdateTag(tag, provider); + public boolean handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + boolean refreshModelData= super.handleUpdateTag(tag, provider); NBTUtils.setDoubleIfPresent(tag, SerializationConstants.TEMPERATURE, buffer::setHeat); + return refreshModelData; } public Color getBaseColor() { diff --git a/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java b/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java index 460257f7cbb..c78683d1dbc 100644 --- a/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java +++ b/src/main/java/mekanism/common/content/network/transmitter/Transmitter.java @@ -446,15 +446,34 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider, return updateTag; } - public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + /** + * @return true if the model data was changed by this update + */ + public boolean handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { + boolean refreshModelData = false; + ConnectionType[] oldConnectionData = new ConnectionType[EnumUtils.DIRECTIONS.length]; + for (Direction side : EnumUtils.DIRECTIONS) { + oldConnectionData[side.ordinal()] = getConnectionType(side); + } + NBTUtils.setByteIfPresent(tag, SerializationConstants.CURRENT_CONNECTIONS, connections -> currentTransmitterConnections = connections); NBTUtils.setByteIfPresent(tag, SerializationConstants.CURRENT_ACCEPTORS, acceptors -> acceptorCache.currentAcceptorConnections = acceptors); readRawConnections(tag); + + for (Direction side : EnumUtils.DIRECTIONS) { + //If the visible connection data changed, mark that we need to update the model data + if (getConnectionType(side) != oldConnectionData[side.ordinal()]) { + refreshModelData = true; + break; + } + } + //Transmitter - NBTUtils.setUUIDIfPresentElse(tag, SerializationConstants.NETWORK, networkID -> { + if (tag.hasUUID(SerializationConstants.NETWORK)) { + UUID networkID = tag.getUUID(SerializationConstants.NETWORK); if (hasTransmitterNetwork() && getTransmitterNetwork().getUUID().equals(networkID)) { - //Nothing needs to be done - return; + //Nothing needs to be done to update the client network + return refreshModelData; } DynamicNetwork clientNetwork = TransmitterNetworkRegistry.getClientNetwork(networkID); if (clientNetwork == null) { @@ -466,7 +485,10 @@ public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Prov //TODO: Validate network type? updateClientNetwork((NETWORK) clientNetwork); } - }, () -> setTransmitterNetwork(null)); + } else { + setTransmitterNetwork(null); + } + return refreshModelData; } protected void updateClientNetwork(@NotNull NETWORK network) { diff --git a/src/main/java/mekanism/common/network/to_client/PacketUpdateTile.java b/src/main/java/mekanism/common/network/to_client/PacketUpdateTile.java index 31f47e9bc8a..3815b5b23c5 100644 --- a/src/main/java/mekanism/common/network/to_client/PacketUpdateTile.java +++ b/src/main/java/mekanism/common/network/to_client/PacketUpdateTile.java @@ -43,7 +43,7 @@ public void handle(IPayloadContext context) { Mekanism.logger.warn("Update tile packet received for position: {} in world: {}, but no valid tile was found.", pos, world.dimension().location()); } else { - tile.handleUpdatePacket(updateTag, world.registryAccess()); + tile.handleUpdateTag(updateTag, world.registryAccess()); } } } diff --git a/src/main/java/mekanism/common/tile/base/TileEntityUpdateable.java b/src/main/java/mekanism/common/tile/base/TileEntityUpdateable.java index 75ebe0fba32..756d1e67a1b 100644 --- a/src/main/java/mekanism/common/tile/base/TileEntityUpdateable.java +++ b/src/main/java/mekanism/common/tile/base/TileEntityUpdateable.java @@ -157,14 +157,10 @@ public void onDataPacket(@NotNull Connection net, @NotNull ClientboundBlockEntit //Handle the update tag when we are on the client CompoundTag tag = pkt.getTag(); if (!tag.isEmpty()) { - handleUpdatePacket(tag, provider); + handleUpdateTag(tag, provider); } } - public void handleUpdatePacket(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - handleUpdateTag(tag, provider); - } - public void sendUpdatePacket() { sendUpdatePacket(this); } diff --git a/src/main/java/mekanism/common/tile/transmitter/TileEntityTransmitter.java b/src/main/java/mekanism/common/tile/transmitter/TileEntityTransmitter.java index 50a17dc8863..3e3ebb637c1 100644 --- a/src/main/java/mekanism/common/tile/transmitter/TileEntityTransmitter.java +++ b/src/main/java/mekanism/common/tile/transmitter/TileEntityTransmitter.java @@ -115,14 +115,10 @@ public CompoundTag getReducedUpdateTag(@NotNull HolderLookup.Provider provider) @Override public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { super.handleUpdateTag(tag, provider); - getTransmitter().handleUpdateTag(tag, provider); - } - - @Override - public void handleUpdatePacket(@NotNull CompoundTag tag, @NotNull HolderLookup.Provider provider) { - super.handleUpdatePacket(tag, provider); - //Delay requesting the model data update and actually updating the packet until we have finished parsing the update tag - updateModelData(); + if (getTransmitter().handleUpdateTag(tag, provider)) { + //Only update the model data if something got updated that caused the model data to change + updateModelData(); + } } @Override