Always send Banner patterns to the client

The mojang client will not remove patterns from a Banner when none
are sent inside of an update packet, given that this is not an expected
flow for them, this is not all too surprising. So, we shall resort to always
sending the patterns over the network for update packets.
This commit is contained in:
Shane Freeder 2024-10-20 18:23:59 +01:00
parent 3d14e7af19
commit 8f7365707a

View file

@ -19,6 +19,15 @@
public DyeColor baseColor;
private BannerPatternLayers patterns;
@@ -53,7 +57,7 @@
@Override
protected void saveAdditional(CompoundTag nbt, HolderLookup.Provider registries) {
super.saveAdditional(nbt, registries);
- if (!this.patterns.equals(BannerPatternLayers.EMPTY)) {
+ if (!this.patterns.equals(BannerPatternLayers.EMPTY) || serialisingForNetwork.get()) { // Paper - always send patterns to client
nbt.put("patterns", (Tag) BannerPatternLayers.CODEC.encodeStart(registries.createSerializationContext(NbtOps.INSTANCE), this.patterns).getOrThrow());
}
@@ -74,7 +78,7 @@
BannerPatternLayers.CODEC.parse(registries.createSerializationContext(NbtOps.INSTANCE), nbt.get("patterns")).resultOrPartial((s) -> {
BannerBlockEntity.LOGGER.error("Failed to parse banner patterns: '{}'", s);
@ -28,7 +37,26 @@
});
}
@@ -108,7 +112,7 @@
@@ -85,9 +89,18 @@
return ClientboundBlockEntityDataPacket.create(this);
}
+ // Paper start - always send patterns to client
+ ThreadLocal<Boolean> serialisingForNetwork = ThreadLocal.withInitial(() -> Boolean.FALSE);
@Override
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
+ final Boolean wasSerialisingForNetwork = serialisingForNetwork.get();
+ try {
+ serialisingForNetwork.set(Boolean.TRUE);
return this.saveWithoutMetadata(registries);
+ } finally {
+ serialisingForNetwork.set(wasSerialisingForNetwork);
+ }
+ // Paper end - always send patterns to client
}
public BannerPatternLayers getPatterns() {
@@ -108,7 +121,7 @@
@Override
protected void applyImplicitComponents(BlockEntity.DataComponentInput components) {
super.applyImplicitComponents(components);
@ -37,7 +65,7 @@
this.name = (Component) components.get(DataComponents.CUSTOM_NAME);
}
@@ -124,4 +128,13 @@
@@ -124,4 +137,13 @@
nbt.remove("patterns");
nbt.remove("CustomName");
}