Skip to content

Commit

Permalink
Fix transmitters not always rendering connections on first load (fail…
Browse files Browse the repository at this point in the history
…ing to update the model data), and also make it so that the model data for transmitters only gets refreshed if something that affects the model data changed
  • Loading branch information
pupnewfster committed Jan 18, 2025
1 parent 83fcef4 commit eef90c7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -363,6 +363,7 @@ public void handleUpdateTag(@NotNull CompoundTag tag, @NotNull HolderLookup.Prov
addStack(compound.getInt(SerializationConstants.INDEX), stack);
}
}
return refreshModelData;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eef90c7

Please sign in to comment.