From 0da10a28647ad6ba02b499decc29cd4a76bc33f9 Mon Sep 17 00:00:00 2001 From: Nassim <28825609+KennyTV@users.noreply.github.com> Date: Sun, 13 Oct 2019 22:20:52 +0200 Subject: [PATCH] Fix 1.11 enchant remapping, arrow velocity and bed handling (#159) * Arrow velocity and entity meta error fix * Fix 1.11 enchant remapping, some minor cleanup --- .../api/rewriters/BlockItemRewriter.java | 32 +++-- .../api/rewriters/EnchantmentRewriter.java | 124 +++++++++++++++++ .../rewriters/LegacyEnchantmentRewriter.java | 126 ++++++++++++++++++ .../viabackwards/api/rewriters/Rewriter.java | 2 +- .../packets/BlockItemPackets1_11.java | 44 ++++++ .../packets/BlockItemPackets1_12.java | 1 - .../packets/ItemPackets1_11_1.java | 44 +++++- .../packets/BlockItemPackets1_13.java | 38 +----- .../packets/BlockItemPackets1_14.java | 114 ++++------------ .../packets/EntityPackets1_14.java | 87 ++++++------ 10 files changed, 435 insertions(+), 177 deletions(-) create mode 100644 core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java create mode 100644 core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java index dc252f65..bdcb1d71 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/BlockItemRewriter.java @@ -31,8 +31,16 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public abstract class BlockItemRewriter extends Rewriter { + private static final CompoundTagConverter converter = new CompoundTagConverter(); private final Map replacementData = new ConcurrentHashMap<>(); + protected String nbtTagName; + + @Override + public void register(T protocol) { + nbtTagName = "ViaBackwards|" + protocol.getClass().getSimpleName(); + super.register(protocol); + } protected BlockItemSettings rewrite(int itemId) { BlockItemSettings settings = new BlockItemSettings(itemId); @@ -80,7 +88,7 @@ public abstract class BlockItemRewriter extends Rew i.setData(original.getData()); } if (data.hasItemTagHandler()) { - if (!i.getTag().contains("ViaBackwards|" + getProtocolName())) + if (!i.getTag().contains(nbtTagName)) i.getTag().put(createViaNBT(original)); data.getItemHandler().handle(i); } @@ -93,20 +101,20 @@ public abstract class BlockItemRewriter extends Rew if (item.getTag() == null) return item; CompoundTag tag = item.getTag(); - if (tag.contains("ViaBackwards|" + getProtocolName())) { - CompoundTag via = tag.get("ViaBackwards|" + getProtocolName()); + if (tag.contains(nbtTagName)) { + CompoundTag via = tag.get(nbtTagName); short id = (short) via.get("id").getValue(); short data = (short) via.get("data").getValue(); byte amount = (byte) via.get("amount").getValue(); CompoundTag extras = via.get("extras"); - item.setId(id); + item.setIdentifier(id); item.setData(data); item.setAmount(amount); item.setTag(converter.convert("", converter.convert(extras))); // Remove data tag - tag.remove("ViaBackwards|" + getProtocolName()); + tag.remove(nbtTagName); } return item; } @@ -205,19 +213,22 @@ public abstract class BlockItemRewriter extends Rew } protected boolean containsBlock(int block) { - return replacementData.containsKey(block) && replacementData.get(block).hasRepBlock(); + final BlockItemSettings settings = replacementData.get(block); + return settings != null && settings.hasRepBlock(); } protected boolean hasBlockEntityHandler(int block) { - return replacementData.containsKey(block) && replacementData.get(block).hasEntityHandler(); + final BlockItemSettings settings = replacementData.get(block); + return settings != null && settings.hasEntityHandler(); } protected boolean hasItemTagHandler(int block) { - return replacementData.containsKey(block) && replacementData.get(block).hasItemTagHandler(); + final BlockItemSettings settings = replacementData.get(block); + return settings != null && settings.hasItemTagHandler(); } private CompoundTag createViaNBT(Item i) { - CompoundTag tag = new CompoundTag("ViaBackwards|" + getProtocolName()); + CompoundTag tag = new CompoundTag(nbtTagName); tag.put(new ShortTag("id", i.getId())); tag.put(new ShortTag("data", i.getData())); tag.put(new ByteTag("amount", i.getAmount())); @@ -243,7 +254,8 @@ public abstract class BlockItemRewriter extends Rew @AllArgsConstructor @ToString @EqualsAndHashCode - private class Pos { + private static class Pos { + private int x, y, z; } } diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java new file mode 100644 index 00000000..f3265320 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EnchantmentRewriter.java @@ -0,0 +1,124 @@ +package nl.matsv.viabackwards.api.rewriters; + +import us.myles.viaversion.libs.opennbt.tag.builtin.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EnchantmentRewriter { + + private final Map enchantmentMappings = new HashMap<>(); + private final String nbtTagName; + + public EnchantmentRewriter(final String nbtTagName) { + this.nbtTagName = nbtTagName; + } + + public void registerEnchantment(String key, String replacementLore) { + enchantmentMappings.put(key, replacementLore); + } + + public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { + String key = storedEnchant ? "StoredEnchantments" : "Enchantments"; + ListTag enchantments = tag.get(key); + ListTag remappedEnchantments = new ListTag(nbtTagName + "|" + key, CompoundTag.class); + List lore = new ArrayList<>(); + for (Tag enchantmentEntry : enchantments.clone()) { + String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); + String enchantmentName = enchantmentMappings.get(newId); + if (enchantmentName != null) { + enchantments.remove(enchantmentEntry); + Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); + lore.add(new StringTag("", enchantmentName + " " + getRomanNumber(level.shortValue()))); + remappedEnchantments.add(enchantmentEntry); + } + } + if (!lore.isEmpty()) { + if (!storedEnchant && enchantments.size() == 0) { + CompoundTag dummyEnchantment = new CompoundTag(""); + dummyEnchantment.put(new StringTag("id", "")); + dummyEnchantment.put(new ShortTag("lvl", (short) 0)); + enchantments.add(dummyEnchantment); + + tag.put(new ByteTag(nbtTagName + "|dummyEnchant")); + } + + tag.put(remappedEnchantments); + + CompoundTag display = tag.get("display"); + if (display == null) { + tag.put(display = new CompoundTag("display")); + } + ListTag loreTag = display.get("Lore"); + if (loreTag == null) { + display.put(loreTag = new ListTag("Lore", StringTag.class)); + } + + lore.addAll(loreTag.getValue()); + loreTag.setValue(lore); + } + } + + public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { + String key = storedEnchant ? "StoredEnchantments" : "Enchantments"; + ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key); + ListTag enchantments = tag.contains(key) ? tag.get(key) : new ListTag(key, CompoundTag.class); + if (!storedEnchant && tag.contains(nbtTagName + "|dummyEnchant")) { + tag.remove(nbtTagName + "|dummyEnchant"); + + for (Tag enchantment : enchantments.clone()) { + String id = (String) ((CompoundTag) enchantment).get("id").getValue(); + if (id.isEmpty()) { + enchantments.remove(enchantment); + } + } + } + + CompoundTag display = tag.get("display"); + // A few null checks just to be safe, though they shouldn't actually be + ListTag lore = display != null ? display.get("Lore") : null; + for (Tag enchantment : remappedEnchantments.clone()) { + enchantments.add(enchantment); + if (lore != null && lore.size() != 0) { + lore.remove(lore.get(0)); + } + } + if (lore != null && lore.size() == 0) { + display.remove("Lore"); + if (display.isEmpty()) { + tag.remove("display"); + } + } + tag.put(enchantments); + tag.remove(remappedEnchantments.getName()); + } + + public static String getRomanNumber(int number) { + switch (number) { + case 1: + return "I"; + case 2: + return "II"; + case 3: + return "III"; + case 4: + return "IV"; + case 5: + return "V"; + case 6: + return "VI"; + case 7: + return "VII"; + case 8: + return "VIII"; + case 9: + return "IX"; + case 10: + return "X"; + default: + return Integer.toString(number); + } + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java new file mode 100644 index 00000000..ff04ae90 --- /dev/null +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/LegacyEnchantmentRewriter.java @@ -0,0 +1,126 @@ +package nl.matsv.viabackwards.api.rewriters; + +import us.myles.viaversion.libs.opennbt.tag.builtin.*; + +import java.util.*; + +public class LegacyEnchantmentRewriter { + + private final Map enchantmentMappings = new HashMap<>(); + private final String nbtTagName; + private Set hideLevelForEnchants; + + public LegacyEnchantmentRewriter(final String nbtTagName) { + this.nbtTagName = nbtTagName; + } + + public void registerEnchantment(int id, String replacementLore) { + enchantmentMappings.put((short) id, replacementLore); + } + + public void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) { + String key = storedEnchant ? "StoredEnchantments" : "ench"; + ListTag enchantments = tag.get(key); + ListTag remappedEnchantments = new ListTag(nbtTagName + "|" + key, CompoundTag.class); + List lore = new ArrayList<>(); + for (Tag enchantmentEntry : enchantments.clone()) { + Short newId = (Short) ((CompoundTag) enchantmentEntry).get("id").getValue(); + String enchantmentName = enchantmentMappings.get(newId); + if (enchantmentName != null) { + enchantments.remove(enchantmentEntry); + Number level = (Number) ((CompoundTag) enchantmentEntry).get("lvl").getValue(); + if (hideLevelForEnchants != null && hideLevelForEnchants.contains(newId)) { + lore.add(new StringTag("", enchantmentName)); + } else { + lore.add(new StringTag("", enchantmentName + " " + EnchantmentRewriter.getRomanNumber(level.shortValue()))); + } + remappedEnchantments.add(enchantmentEntry); + } + } + if (!lore.isEmpty()) { + if (!storedEnchant && enchantments.size() == 0) { + CompoundTag dummyEnchantment = new CompoundTag(""); + dummyEnchantment.put(new ShortTag("id", (short) 0)); + dummyEnchantment.put(new ShortTag("lvl", (short) 0)); + enchantments.add(dummyEnchantment); + + tag.put(new ByteTag(nbtTagName + "|dummyEnchant")); + + IntTag hideFlags = tag.get("HideFlags"); + if (hideFlags == null) { + hideFlags = new IntTag("HideFlags"); + } else { + tag.put(new IntTag(nbtTagName + "|oldHideFlags", hideFlags.getValue())); + } + + int flags = hideFlags.getValue() | 1; + hideFlags.setValue(flags); + tag.put(hideFlags); + } + + tag.put(remappedEnchantments); + + CompoundTag display = tag.get("display"); + if (display == null) { + tag.put(display = new CompoundTag("display")); + } + ListTag loreTag = display.get("Lore"); + if (loreTag == null) { + display.put(loreTag = new ListTag("Lore", StringTag.class)); + } + + lore.addAll(loreTag.getValue()); + loreTag.setValue(lore); + } + } + + public void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) { + String key = storedEnchant ? "StoredEnchantments" : "ench"; + ListTag remappedEnchantments = tag.get(nbtTagName + "|" + key); + ListTag enchantments = tag.contains(key) ? tag.get(key) : new ListTag(key, CompoundTag.class); + if (!storedEnchant && tag.contains(nbtTagName + "|dummyEnchant")) { + tag.remove(nbtTagName + "|dummyEnchant"); + + for (Tag enchantment : enchantments.clone()) { + Short id = (Short) ((CompoundTag) enchantment).get("id").getValue(); + Short level = (Short) ((CompoundTag) enchantment).get("lvl").getValue(); + if (id == 0 && level == 0) { + enchantments.remove(enchantment); + } + } + + IntTag hideFlags = tag.get(nbtTagName + "|oldHideFlags"); + if (hideFlags != null) { + tag.put(new IntTag("HideFlags", hideFlags.getValue())); + tag.remove(nbtTagName + "|oldHideFlags"); + } else { + tag.remove("HideFlags"); + } + } + + CompoundTag display = tag.get("display"); + // A few null checks just to be safe, though they shouldn't actually be + ListTag lore = display != null ? display.get("Lore") : null; + for (Tag enchantment : remappedEnchantments.clone()) { + enchantments.add(enchantment); + if (lore != null && lore.size() != 0) { + lore.remove(lore.get(0)); + } + } + if (lore != null && lore.size() == 0) { + display.remove("Lore"); + if (display.isEmpty()) { + tag.remove("display"); + } + } + tag.put(enchantments); + tag.remove(remappedEnchantments.getName()); + } + + public void setHideLevelForEnchants(Integer... enchants) { + this.hideLevelForEnchants = new HashSet<>(); + for (Integer enchant : enchants) { + hideLevelForEnchants.add(enchant.shortValue()); + } + } +} diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/Rewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/Rewriter.java index b958f8c1..61080c52 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/Rewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/Rewriter.java @@ -22,7 +22,7 @@ public abstract class Rewriter { * * @param protocol Protocol instance */ - public final void register(T protocol) { + public void register(T protocol) { this.protocol = protocol; registerPackets(protocol); registerRewrites(); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 49110340..0d5f4078 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -13,6 +13,7 @@ package nl.matsv.viabackwards.protocol.protocol1_10to1_11.packets; import net.md_5.bungee.api.ChatColor; import nl.matsv.viabackwards.api.entities.storage.EntityTracker; import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter; +import nl.matsv.viabackwards.api.rewriters.LegacyEnchantmentRewriter; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.EntityTypeNames; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.Protocol1_10To1_11; import nl.matsv.viabackwards.protocol.protocol1_10to1_11.storage.ChestedHorseStorage; @@ -34,12 +35,16 @@ import us.myles.ViaVersion.packets.State; import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type; import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; +import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import java.util.Arrays; import java.util.Optional; public class BlockItemPackets1_11 extends BlockItemRewriter { + + private LegacyEnchantmentRewriter enchantmentRewriter; + @Override protected void registerPackets(Protocol1_10To1_11 protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); @@ -375,6 +380,45 @@ public class BlockItemPackets1_11 extends BlockItemRewriter // Shulker shell to Popped Chorus Fruit rewrite(450).repItem(new Item((short) 433, (byte) 1, (short) 0, getNamedTag("1.11 Shulker Shell"))); + enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName); + enchantmentRewriter.registerEnchantment(71, "§cCurse of Vanishing"); + enchantmentRewriter.registerEnchantment(10, "§cCurse of Binding"); + + enchantmentRewriter.setHideLevelForEnchants(71, 10); // Curses do not display their level + } + + @Override + protected Item handleItemToClient(final Item item) { + if (item == null) return null; + super.handleItemToClient(item); + + CompoundTag tag = item.getTag(); + if (tag == null) return item; + + if (tag.get("ench") instanceof ListTag) { + enchantmentRewriter.rewriteEnchantmentsToClient(tag, false); + } + if (tag.get("StoredEnchantments") instanceof ListTag) { + enchantmentRewriter.rewriteEnchantmentsToClient(tag, true); + } + return item; + } + + @Override + protected Item handleItemToServer(final Item item) { + if (item == null) return null; + super.handleItemToServer(item); + + CompoundTag tag = item.getTag(); + if (tag == null) return item; + + if (tag.contains(nbtTagName + "|ench")) { + enchantmentRewriter.rewriteEnchantmentsToServer(tag, false); + } + if (tag.contains(nbtTagName + "|StoredEnchantments")) { + enchantmentRewriter.rewriteEnchantmentsToServer(tag, true); + } + return item; } private boolean isLlama(UserConnection user) { diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java index 2767dd1e..87ead1c8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_11_1to1_12/packets/BlockItemPackets1_12.java @@ -292,6 +292,5 @@ public class BlockItemPackets1_12 extends BlockItemRewriter { + private LegacyEnchantmentRewriter enchantmentRewriter; + @Override protected void registerPackets(Protocol1_11To1_11_1 protocol) { ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer); @@ -86,6 +91,43 @@ public class ItemPackets1_11_1 extends BlockItemRewriter { @Override protected void registerRewrites() { - rewrite(452).repItem(new Item((short) 265, (byte) 1, (short) 0, getNamedTag("1.11.2 Iron Nugget"))); + rewrite(452).repItem(new Item(265, (byte) 1, (short) 0, getNamedTag("1.11.2 Iron Nugget"))); + + enchantmentRewriter = new LegacyEnchantmentRewriter(nbtTagName); + enchantmentRewriter.registerEnchantment(22, "§7Sweeping Edge"); + } + + @Override + protected Item handleItemToClient(final Item item) { + if (item == null) return null; + super.handleItemToClient(item); + + CompoundTag tag = item.getTag(); + if (tag == null) return item; + + if (tag.get("ench") instanceof ListTag) { + enchantmentRewriter.rewriteEnchantmentsToClient(tag, false); + } + if (tag.get("StoredEnchantments") instanceof ListTag) { + enchantmentRewriter.rewriteEnchantmentsToClient(tag, true); + } + return item; + } + + @Override + protected Item handleItemToServer(final Item item) { + if (item == null) return null; + super.handleItemToServer(item); + + CompoundTag tag = item.getTag(); + if (tag == null) return item; + + if (tag.contains(nbtTagName + "|ench")) { + enchantmentRewriter.rewriteEnchantmentsToServer(tag, false); + } + if (tag.contains(nbtTagName + "|StoredEnchantments")) { + enchantmentRewriter.rewriteEnchantmentsToServer(tag, true); + } + return item; } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index e9039878..fbbe2e07 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -12,6 +12,7 @@ package nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets; import nl.matsv.viabackwards.ViaBackwards; import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter; +import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.Protocol1_12_2To1_13; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.block_entity_handlers.FlowerPotHandler; import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.data.BackwardsMappings; @@ -759,9 +760,11 @@ public class BlockItemPackets1_13 extends BlockItemRewriter { - private static final String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName(); - private final Map enchantmentMappings = new HashMap<>(); + private EnchantmentRewriter enchantmentRewriter; @Override protected void registerPackets(Protocol1_13_2To1_14 protocol) { @@ -249,13 +253,14 @@ public class BlockItemPackets1_14 extends BlockItemRewriter removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting"); - // Declare Recipes protocol.registerOutgoing(State.PLAY, 0x5A, 0x54, new PacketRemapper() { // c @Override public void registerMap() { handler(new PacketHandler() { + + private final Set removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting"); + @Override public void handle(PacketWrapper wrapper) throws Exception { int size = wrapper.passthrough(Type.VAR_INT); @@ -685,9 +690,10 @@ public class BlockItemPackets1_14 extends BlockItemRewriter lore = new ArrayList<>(); - for (Tag enchantmentEntry : enchantments.clone()) { - String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue(); - String enchantmentName = enchantmentMappings.get(newId); - if (enchantmentName != null) { - enchantments.remove(enchantmentEntry); - lore.add(new StringTag("", enchantmentMappings.get(newId) + " " + BlockItemPackets1_13.getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()))); - noMapped.add(enchantmentEntry); - } - } - if (!lore.isEmpty()) { - if (!storedEnchant && enchantments.size() == 0) { - CompoundTag dummyEnchantment = new CompoundTag(""); - dummyEnchantment.put(new StringTag("id", "")); - dummyEnchantment.put(new ShortTag("lvl", (short) 0)); - enchantments.add(dummyEnchantment); - - tag.put(new ByteTag(NBT_TAG_NAME + "|dummyEnchant")); - } - - tag.put(noMapped); - - CompoundTag display = tag.get("display"); - if (display == null) { - tag.put(display = new CompoundTag("display")); - } - ListTag loreTag = display.get("Lore"); - if (loreTag == null) { - display.put(loreTag = new ListTag("Lore", StringTag.class)); - } - - lore.addAll(loreTag.getValue()); - loreTag.setValue(lore); - } - } - @Override public Item handleItemToServer(Item item) { if (item == null) return null; @@ -784,7 +750,7 @@ public class BlockItemPackets1_14 extends BlockItemRewriter { @Override protected void registerPackets(Protocol1_13_2To1_14 protocol) { // Spawn Object - protocol.registerOutgoing(State.PLAY, 0x0, 0x0, new PacketRemapper() { + protocol.registerOutgoing(State.PLAY, 0x00, 0x00, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity id @@ -47,6 +47,9 @@ public class EntityPackets1_14 extends EntityRewriter { map(Type.BYTE); // 6 - Pitch map(Type.BYTE); // 7 - Yaw map(Type.INT); // 8 - Data + map(Type.SHORT); // 9 - Velocity X + map(Type.SHORT); // 10 - Velocity Y + map(Type.SHORT); // 11 - Velocity Z handler(getObjectTrackerHandler()); @@ -55,9 +58,9 @@ public class EntityPackets1_14 extends EntityRewriter { public void handle(PacketWrapper wrapper) throws Exception { int id = wrapper.get(Type.BYTE, 0); Entity1_13Types.EntityType entityType = Entity1_13Types.getTypeFromId(EntityTypeMapping.getOldId(id).orElse(id), false); - Optional type; + Entity1_13Types.ObjectType objectType; if (entityType.isOrHasParent(Entity1_13Types.EntityType.MINECART_ABSTRACT)) { - type = Optional.of(Entity1_13Types.ObjectType.MINECART); + objectType = Entity1_13Types.ObjectType.MINECART; int data = 0; switch (entityType) { case CHEST_MINECART: @@ -82,31 +85,21 @@ public class EntityPackets1_14 extends EntityRewriter { if (data != 0) wrapper.set(Type.INT, 0, data); } else { - type = Entity1_13Types.ObjectType.fromEntityType(entityType); + objectType = Entity1_13Types.ObjectType.fromEntityType(entityType).orElse(null); } - if (type.isPresent()) { - wrapper.set(Type.BYTE, 0, (byte) type.get().getId()); - } - if (type.isPresent() && type.get() == Entity1_13Types.ObjectType.FALLING_BLOCK) { + if (objectType == null) return; + + wrapper.set(Type.BYTE, 0, (byte) objectType.getId()); + + int data = wrapper.get(Type.INT, 0); + if (objectType == Entity1_13Types.ObjectType.FALLING_BLOCK) { int blockState = wrapper.get(Type.INT, 0); int combined = BlockItemPackets1_13.toOldId(blockState); combined = ((combined >> 4) & 0xFFF) | ((combined & 0xF) << 12); wrapper.set(Type.INT, 0, combined); - } else if (type.isPresent() && type.get() == Entity1_13Types.ObjectType.ITEM_FRAME) { - int data = wrapper.get(Type.INT, 0); - switch (data) { - case 3: - data = 0; - break; - case 4: - data = 1; - break; - case 5: - data = 3; - break; - } - wrapper.set(Type.INT, 0, data); + } else if (entityType.isOrHasParent(Entity1_13Types.EntityType.ABSTRACT_ARROW)) { + wrapper.set(Type.INT, 0, data + 1); } } }); @@ -114,7 +107,7 @@ public class EntityPackets1_14 extends EntityRewriter { }); // Spawn mob packet - protocol.registerOutgoing(State.PLAY, 0x3, 0x3, new PacketRemapper() { + protocol.registerOutgoing(State.PLAY, 0x03, 0x03, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // 0 - Entity ID @@ -136,11 +129,8 @@ public class EntityPackets1_14 extends EntityRewriter { public void handle(PacketWrapper wrapper) throws Exception { int type = wrapper.get(Type.VAR_INT, 1); Entity1_14Types.EntityType entityType = Entity1_14Types.getTypeFromId(type); - addTrackedEntity( - wrapper.user(), - wrapper.get(Type.VAR_INT, 0), - entityType - ); + addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), entityType); + Optional oldId = EntityTypeMapping.getOldId(type); if (!oldId.isPresent()) { Optional oldType = getEntityData(entityType); @@ -168,7 +158,24 @@ public class EntityPackets1_14 extends EntityRewriter { registerExtraTracker(0x02, Entity1_14Types.EntityType.LIGHTNING_BOLT); // Spawn painting - registerExtraTracker(0x04, Entity1_14Types.EntityType.PAINTING); + protocol.registerOutgoing(State.PLAY, 0x04, 0x04, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.VAR_INT); + map(Type.UUID); + map(Type.VAR_INT); + map(Type.POSITION1_14, Type.POSITION); + map(Type.BYTE); + + // Track entity + handler(new PacketHandler() { + @Override + public void handle(PacketWrapper wrapper) throws Exception { + addTrackedEntity(wrapper.user(), wrapper.get(Type.VAR_INT, 0), Entity1_14Types.EntityType.PAINTING); + } + }); + } + }); // Spawn player packet protocol.registerOutgoing(State.PLAY, 0x05, 0x05, new PacketRemapper() { @@ -264,7 +271,7 @@ public class EntityPackets1_14 extends EntityRewriter { meta.setValue(getProtocol().getBlockItemPackets().handleItemToClient(item)); } else if (type == MetaType1_13_2.BlockID) { int blockstate = (Integer) meta.getValue(); - meta.setValue(getProtocol().getNewBlockStateId(blockstate)); + meta.setValue(Protocol1_13_2To1_14.getNewBlockStateId(blockstate)); } return meta; @@ -361,26 +368,18 @@ public class EntityPackets1_14 extends EntityRewriter { if (index == 12) { Position position = (Position) meta.getValue(); if (position != null) { + // Use bed + PacketWrapper wrapper = new PacketWrapper(0x33, null, e.getUser()); + wrapper.write(Type.VAR_INT, e.getEntity().getEntityId()); + wrapper.write(Type.POSITION, position); + try { - //Use bed - PacketWrapper wrapper = new PacketWrapper(0x33, null, e.getUser()); - wrapper.write(Type.VAR_INT, e.getEntity().getEntityId()); - wrapper.write(Type.POSITION, position); - wrapper.send(Protocol1_13_2To1_14.class); - } catch (Exception ex) { - ex.printStackTrace(); - } - } else { - try { - //Animation leave bed - PacketWrapper wrapper = new PacketWrapper(0x6, null, e.getUser()); - wrapper.write(Type.VAR_INT, e.getEntity().getEntityId()); - wrapper.write(Type.UNSIGNED_BYTE, (short) 2); wrapper.send(Protocol1_13_2To1_14.class); } catch (Exception ex) { ex.printStackTrace(); } } + throw RemovedValueException.EX; } else if (index > 12) { meta.setId(index - 1);