3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Handle block entities to identifier correctly 1.10->1.11 (TODO handle correctly in ViaBackwards)

Dieser Commit ist enthalten in:
Matsv 2018-04-07 18:00:18 +02:00
Ursprung b61b52c57e
Commit 495d162ef2
2 geänderte Dateien mit 63 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,49 @@
package us.myles.ViaVersion.protocols.protocol1_11to1_10;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
public class BlockEntityRewriter {
private static BiMap<String, String> oldToNewNames = HashBiMap.create();
// Source: https://www.minecraftforum.net/forums/minecraft-java-edition/redstone-discussion-and/commands-command-blocks-and/2724507-1-11-nbt-changes-and-additions#AllTiles
static {
rewrite("Furnace", "furnace");
rewrite("Chest", "chest");
rewrite("EnderChest", "ender_chest");
rewrite("RecordPlayer", "jukebox");
rewrite("Trap", "dispenser");
rewrite("Dropper", "dropper");
rewrite("Sign", "sign");
rewrite("MobSpawner", "mob_spawner");
rewrite("Music", "noteblock");
rewrite("Piston", "piston");
rewrite("Cauldron", "brewing_stand");
rewrite("EnchantTable", "enchanting_table");
rewrite("Airportal", "end_portal");
rewrite("Beacon", "beacon");
rewrite("Skull", "skull");
rewrite("DLDetector", "daylight_detector");
rewrite("Hopper", "hopper");
rewrite("Comparator", "comparator");
rewrite("FlowerPot", "flower_pot");
rewrite("Banner", "banner");
rewrite("Structure", "structure_block");
rewrite("EndGateway", "end_gateway");
rewrite("Control", "command_block");
}
private static void rewrite(String oldName, String newName) {
oldToNewNames.put(oldName, "minecraft:" + newName);
}
public static BiMap<String, String> inverse() {
return oldToNewNames.inverse();
}
public static String toNewIdentifier(String oldId) {
if (oldToNewNames.containsKey(oldId))
return oldToNewNames.get(oldId);
return oldId;
}
}

Datei anzeigen

@ -259,10 +259,14 @@ public class Protocol1_11To1_10 extends Protocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1) {
CompoundTag tag = wrapper.get(Type.NBT, 0);
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
EntityIdRewriter.toClientSpawner(tag);
}
if (tag.contains("id"))
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
}
});
}
@ -285,9 +289,13 @@ public class Protocol1_11To1_10 extends Protocol {
if (chunk.getBlockEntities() == null) return;
for (CompoundTag tag : chunk.getBlockEntities()) {
if (tag.contains("id") &&
((StringTag) tag.get("id")).getValue().equals("MobSpawner")) {
if (tag.contains("id")) {
String identifier = ((StringTag) tag.get("id")).getValue();
if (identifier.equals("MobSpawner"))
EntityIdRewriter.toClientSpawner(tag);
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
}
}
}