Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-11-16 04:50:10 +01:00
Convert components in sign block entities in 1.12->1.11 (#845)
Dieser Commit ist enthalten in:
Ursprung
f4bc485408
Commit
24f994ff2a
@ -18,6 +18,7 @@
|
||||
|
||||
package com.viaversion.viabackwards.protocol.v1_12to1_11_1.rewriter;
|
||||
|
||||
import com.viaversion.nbt.tag.StringTag;
|
||||
import com.viaversion.viabackwards.api.rewriters.LegacyBlockItemRewriter;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.Protocol1_12To1_11_1;
|
||||
import com.viaversion.viabackwards.protocol.v1_12to1_11_1.data.MapColorMappings1_11_1;
|
||||
@ -38,6 +39,9 @@ import com.viaversion.viaversion.protocols.v1_11_1to1_12.packet.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ServerboundPackets1_9_3;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<ClientboundPackets1_12, ServerboundPackets1_9_3, Protocol1_12To1_11_1> {
|
||||
@ -133,6 +137,15 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
Chunk chunk = wrapper.passthrough(type);
|
||||
|
||||
handleChunk(chunk);
|
||||
for (final CompoundTag tag : chunk.getBlockEntities()) {
|
||||
final String id = tag.getString("id");
|
||||
if (id == null) {
|
||||
continue;
|
||||
}
|
||||
if (Key.stripMinecraftNamespace(id).equals("sign")) {
|
||||
handleSignText(tag);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12.BLOCK_ENTITY_DATA, new PacketHandlers() {
|
||||
@ -143,9 +156,14 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
map(Types.NAMED_COMPOUND_TAG); // 2 - NBT
|
||||
|
||||
handler(wrapper -> {
|
||||
// Remove bed color
|
||||
if (wrapper.get(Types.UNSIGNED_BYTE, 0) == 11)
|
||||
final short type = wrapper.get(Types.UNSIGNED_BYTE, 0);
|
||||
if (type == 9) {
|
||||
final CompoundTag tag = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
||||
handleSignText(tag);
|
||||
} else if (type == 11) {
|
||||
// Remove bed color
|
||||
wrapper.cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -170,6 +188,18 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
||||
});
|
||||
}
|
||||
|
||||
private void handleSignText(final CompoundTag tag) {
|
||||
// Push signs through component conversion, fixes https://github.com/ViaVersion/ViaBackwards/issues/835
|
||||
for (int i = 0; i < 4; i++) {
|
||||
final StringTag lineTag = tag.getStringTag("Text" + (i + 1));
|
||||
if (lineTag == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lineTag.setValue(ComponentUtil.convertJsonOrEmpty(lineTag.getValue(), SerializerVersion.V1_12, SerializerVersion.V1_9).toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Item handleItemToClient(UserConnection connection, Item item) {
|
||||
if (item == null) return null;
|
||||
|
@ -24,7 +24,6 @@ import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockPosition;
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.protocol.AbstractProtocol;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_9_1;
|
||||
@ -60,9 +59,9 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
wrapper.setPacketType(ClientboundPackets1_9.UPDATE_SIGN);
|
||||
wrapper.write(Types.BLOCK_POSITION1_8, position); // Position
|
||||
for (int i = 1; i < 5; i++) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
// Should technically be written as COMPONENT, but left as String for simplification/to remove redundant wrapping for VR
|
||||
StringTag textTag = tag.getStringTag("Text" + i);
|
||||
StringTag textTag = tag.getStringTag("Text" + (i + 1));
|
||||
String line = textTag != null ? textTag.getValue() : "";
|
||||
wrapper.write(Types.STRING, line); // Sign line
|
||||
}
|
||||
@ -122,4 +121,4 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
||||
userConnection.put(new ClientWorld());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren