mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 08:57:39 +01:00
Rewrite signs and books components on 1.16 (#2712)
This commit is contained in:
parent
2533619339
commit
43ad855499
@ -60,6 +60,7 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
public static final MappingData MAPPINGS = new MappingData();
|
public static final MappingData MAPPINGS = new MappingData();
|
||||||
private final EntityRewriter metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
|
private final EntityRewriter metadataRewriter = new MetadataRewriter1_16To1_15_2(this);
|
||||||
private final ItemRewriter itemRewriter = new InventoryPackets(this);
|
private final ItemRewriter itemRewriter = new InventoryPackets(this);
|
||||||
|
private final ComponentRewriter componentRewriter = new TranslationMappings(this);
|
||||||
private TagRewriter tagRewriter;
|
private TagRewriter tagRewriter;
|
||||||
|
|
||||||
public Protocol1_16To1_15_2() {
|
public Protocol1_16To1_15_2() {
|
||||||
@ -131,7 +132,6 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ComponentRewriter componentRewriter = new TranslationMappings(this);
|
|
||||||
// Handle (relevant) component cases for translatable and score changes
|
// Handle (relevant) component cases for translatable and score changes
|
||||||
registerClientbound(ClientboundPackets1_15.CHAT_MESSAGE, new PacketRemapper() {
|
registerClientbound(ClientboundPackets1_15.CHAT_MESSAGE, new PacketRemapper() {
|
||||||
@Override
|
@Override
|
||||||
@ -301,4 +301,8 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol<ClientboundPackets1_1
|
|||||||
public ItemRewriter getItemRewriter() {
|
public ItemRewriter getItemRewriter() {
|
||||||
return itemRewriter;
|
return itemRewriter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ComponentRewriter getComponentRewriter() {
|
||||||
|
return componentRewriter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,8 +155,9 @@ public class InventoryPackets extends ItemRewriter<Protocol1_16To1_15_2> {
|
|||||||
public Item handleItemToClient(Item item) {
|
public Item handleItemToClient(Item item) {
|
||||||
if (item == null) return null;
|
if (item == null) return null;
|
||||||
|
|
||||||
if (item.identifier() == 771 && item.tag() != null) {
|
CompoundTag tag = item.tag();
|
||||||
CompoundTag tag = item.tag();
|
|
||||||
|
if (item.identifier() == 771 && tag != null) {
|
||||||
Tag ownerTag = tag.get("SkullOwner");
|
Tag ownerTag = tag.get("SkullOwner");
|
||||||
if (ownerTag instanceof CompoundTag) {
|
if (ownerTag instanceof CompoundTag) {
|
||||||
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
|
CompoundTag ownerCompundTag = (CompoundTag) ownerTag;
|
||||||
@ -166,6 +167,17 @@ public class InventoryPackets extends ItemRewriter<Protocol1_16To1_15_2> {
|
|||||||
ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(id)));
|
ownerCompundTag.put("Id", new IntArrayTag(UUIDIntArrayType.uuidToIntArray(id)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (item.identifier() == 759 && tag != null) {
|
||||||
|
Tag pages = tag.get("pages");
|
||||||
|
if (pages instanceof ListTag) {
|
||||||
|
for (Tag pageTag : (ListTag) pages) {
|
||||||
|
if (!(pageTag instanceof StringTag)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
StringTag page = (StringTag) pageTag;
|
||||||
|
page.setValue(protocol.getComponentRewriter().processText(page.getValue()).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldToNewAttributes(item);
|
oldToNewAttributes(item);
|
||||||
|
@ -22,6 +22,7 @@ import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
import com.viaversion.viaversion.api.minecraft.Position;
|
import com.viaversion.viaversion.api.minecraft.Position;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||||
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
|
||||||
@ -85,7 +86,7 @@ public class WorldPackets {
|
|||||||
|
|
||||||
if (chunk.getBlockEntities() == null) return;
|
if (chunk.getBlockEntities() == null) return;
|
||||||
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
for (CompoundTag blockEntity : chunk.getBlockEntities()) {
|
||||||
handleBlockEntity(blockEntity);
|
handleBlockEntity(protocol, blockEntity);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -98,7 +99,7 @@ public class WorldPackets {
|
|||||||
Position position = wrapper.passthrough(Type.POSITION1_14);
|
Position position = wrapper.passthrough(Type.POSITION1_14);
|
||||||
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
short action = wrapper.passthrough(Type.UNSIGNED_BYTE);
|
||||||
CompoundTag tag = wrapper.passthrough(Type.NBT);
|
CompoundTag tag = wrapper.passthrough(Type.NBT);
|
||||||
handleBlockEntity(tag);
|
handleBlockEntity(protocol, tag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -106,7 +107,7 @@ public class WorldPackets {
|
|||||||
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
|
blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void handleBlockEntity(CompoundTag compoundTag) {
|
private static void handleBlockEntity(Protocol1_16To1_15_2 protocol, CompoundTag compoundTag) {
|
||||||
StringTag idTag = compoundTag.get("id");
|
StringTag idTag = compoundTag.get("id");
|
||||||
if (idTag == null) return;
|
if (idTag == null) return;
|
||||||
|
|
||||||
@ -132,6 +133,14 @@ public class WorldPackets {
|
|||||||
skullOwnerTag.put(entry.getKey(), entry.getValue());
|
skullOwnerTag.put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
compoundTag.put("SkullOwner", skullOwnerTag);
|
compoundTag.put("SkullOwner", skullOwnerTag);
|
||||||
|
} else if (id.equals("minecraft:sign")) {
|
||||||
|
for (int i = 1; i <= 4; i++) {
|
||||||
|
Tag line = compoundTag.get("Text" + i);
|
||||||
|
if (line instanceof StringTag) {
|
||||||
|
JsonElement text = protocol.getComponentRewriter().processText(((StringTag) line).getValue());
|
||||||
|
compoundTag.put("Text" + i, new StringTag(text.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user