3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-07-10 09:18:04 +02:00

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
Dieser Commit ist enthalten in:
Nassim 2019-10-13 22:20:52 +02:00 committet von Myles
Ursprung b21fce2506
Commit 0da10a2864
10 geänderte Dateien mit 435 neuen und 177 gelöschten Zeilen

Datei anzeigen

@ -31,8 +31,16 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public abstract class BlockItemRewriter<T extends BackwardsProtocol> extends Rewriter<T> {
private static final CompoundTagConverter converter = new CompoundTagConverter();
private final Map<Integer, BlockItemSettings> 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<T extends BackwardsProtocol> 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<T extends BackwardsProtocol> 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<T extends BackwardsProtocol> 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<T extends BackwardsProtocol> extends Rew
@AllArgsConstructor
@ToString
@EqualsAndHashCode
private class Pos {
private static class Pos {
private int x, y, z;
}
}

Datei anzeigen

@ -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<String, String> 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<Tag> 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);
}
}
}

Datei anzeigen

@ -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<Short, String> enchantmentMappings = new HashMap<>();
private final String nbtTagName;
private Set<Short> 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<Tag> 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());
}
}
}

Datei anzeigen

@ -22,7 +22,7 @@ public abstract class Rewriter<T extends BackwardsProtocol> {
*
* @param protocol Protocol instance
*/
public final void register(T protocol) {
public void register(T protocol) {
this.protocol = protocol;
registerPackets(protocol);
registerRewrites();

Datei anzeigen

@ -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<Protocol1_10To1_11> {
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<Protocol1_10To1_11>
// 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) {

Datei anzeigen

@ -292,6 +292,5 @@ public class BlockItemPackets1_12 extends BlockItemRewriter<Protocol1_11_1To1_12
// Handle beds
rewrite(355).repItem(new Item((short) 355, (byte) 1, (short) 0, getNamedTag("1.12 %viabackwards_color% Bed")));
}
}

Datei anzeigen

@ -11,6 +11,7 @@
package nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.packets;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.api.rewriters.LegacyEnchantmentRewriter;
import nl.matsv.viabackwards.protocol.protocol1_11to1_11_1.Protocol1_11To1_11_1;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
@ -20,9 +21,13 @@ import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.ListTag;
public class ItemPackets1_11_1 extends BlockItemRewriter<Protocol1_11To1_11_1> {
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<Protocol1_11To1_11_1> {
@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;
}
}

Datei anzeigen

@ -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<Protocol1_12_2To1_13
for (Tag enchantmentEntry : enchantments.clone()) {
CompoundTag enchEntry = new CompoundTag("");
String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
if (enchantmentMappings.containsKey(newId)) {
lore.add(new StringTag("", enchantmentMappings.get(newId) + " "
+ getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())));
String mappedEnchantmentId = enchantmentMappings.get(newId);
if (mappedEnchantmentId != null) {
lore.add(new StringTag("", mappedEnchantmentId + " "
+ EnchantmentRewriter.getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())));
noMapped.add(enchantmentEntry);
} else if (!newId.isEmpty()) {
Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
@ -778,7 +781,7 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
name = "§7" + Character.toUpperCase(name.charAt(0)) + name.substring(1).toLowerCase(Locale.ENGLISH);
lore.add(new StringTag("", name + " "
+ getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())));
+ EnchantmentRewriter.getRomanNumber((Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue())));
}
if (Via.getManager().isDebug())
@ -1070,31 +1073,4 @@ public class BlockItemPackets1_13 extends BlockItemRewriter<Protocol1_12_2To1_13
}
}
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);
}
}
}

Datei anzeigen

@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableSet;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.BlockItemRewriter;
import nl.matsv.viabackwards.protocol.protocol1_12_2to1_13.packets.BlockItemPackets1_13;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import us.myles.ViaVersion.api.PacketWrapper;
@ -31,14 +31,18 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.opennbt.conversion.ConverterRegistry;
import us.myles.viaversion.libs.opennbt.tag.builtin.*;
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 us.myles.viaversion.libs.opennbt.tag.builtin.Tag;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14> {
private static final String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName();
private final Map<String, String> 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<Protocol1_13_2To1_14
}
});
Set<String> 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<String> 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<Protocol1_13_2To1_14
rewrite(741).repItem(new Item((short) 698, (byte) 1, (short) -1, getNamedTag("1.14 Trader Llama Spawn Egg")));
rewrite(747).repItem(new Item((short) 739, (byte) 1, (short) -1, getNamedTag("1.14 Wandering Trader Spawn Egg")));
enchantmentMappings.put("minecraft:multishot", "§7Multishot");
enchantmentMappings.put("minecraft:quick_charge", "§7Quick Charge");
enchantmentMappings.put("minecraft:piercing", "§7Piercing");
enchantmentRewriter = new EnchantmentRewriter(nbtTagName);
enchantmentRewriter.registerEnchantment("minecraft:multishot", "§7Multishot");
enchantmentRewriter.registerEnchantment("minecraft:quick_charge", "§7Quick Charge");
enchantmentRewriter.registerEnchantment("minecraft:piercing", "§7Piercing");
}
@Override
@ -703,7 +709,7 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
CompoundTag display = tag.get("display");
if (((CompoundTag) tag.get("display")).get("Lore") instanceof ListTag) {
ListTag lore = display.get("Lore");
ListTag via = display.get(NBT_TAG_NAME + "|Lore");
ListTag via = display.get(nbtTagName + "|Lore");
if (via != null) {
display.put(ConverterRegistry.convertToTag("Lore", ConverterRegistry.convertToValue(via)));
} else {
@ -717,60 +723,20 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
}
}
}
display.remove(NBT_TAG_NAME + "|Lore");
display.remove(nbtTagName + "|Lore");
}
}
if (tag.get("Enchantments") instanceof ListTag) {
rewriteEnchantmentsToClient(tag, false);
enchantmentRewriter.rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
rewriteEnchantmentsToClient(tag, true);
enchantmentRewriter.rewriteEnchantmentsToClient(tag, true);
}
}
return item;
}
private void rewriteEnchantmentsToClient(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
ListTag enchantments = tag.get(key);
ListTag noMapped = new ListTag(NBT_TAG_NAME + "|" + key, CompoundTag.class);
List<Tag> 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<Protocol1_13_2To1_14
CompoundTag display = tag.get("display");
if (display.get("Lore") instanceof ListTag) {
ListTag lore = display.get("Lore");
display.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|Lore", ConverterRegistry.convertToValue(lore)));
display.put(ConverterRegistry.convertToTag(nbtTagName + "|Lore", ConverterRegistry.convertToValue(lore)));
for (Tag loreEntry : lore) {
if (loreEntry instanceof StringTag) {
((StringTag) loreEntry).setValue(
@ -797,46 +763,16 @@ public class BlockItemPackets1_14 extends BlockItemRewriter<Protocol1_13_2To1_14
}
}
if (tag.contains(NBT_TAG_NAME + "|Enchantments")) {
rewriteEnchantmentsToServer(tag, false);
if (tag.contains(nbtTagName + "|Enchantments")) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, false);
}
if (tag.contains(NBT_TAG_NAME + "|StoredEnchantments")) {
rewriteEnchantmentsToServer(tag, true);
if (tag.contains(nbtTagName + "|StoredEnchantments")) {
enchantmentRewriter.rewriteEnchantmentsToServer(tag, true);
}
}
return item;
}
private void rewriteEnchantmentsToServer(CompoundTag tag, boolean storedEnchant) {
String key = storedEnchant ? "StoredEnchantments" : "Enchantments";
ListTag newEnchantments = tag.get(NBT_TAG_NAME + "|" + key);
ListTag enchantments = tag.contains(key) ? tag.get(key) : new ListTag(key, CompoundTag.class);
if (!storedEnchant && tag.contains(NBT_TAG_NAME + "|dummyEnchant")) {
tag.remove(NBT_TAG_NAME + "|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 : newEnchantments.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(newEnchantments.getName());
}
@Override
protected CompoundTag getNamedTag(String text) {
CompoundTag tag = new CompoundTag("");

Datei anzeigen

@ -35,7 +35,7 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
@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<Protocol1_13_2To1_14> {
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<Protocol1_13_2To1_14> {
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<Entity1_13Types.ObjectType> 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<Protocol1_13_2To1_14> {
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<Protocol1_13_2To1_14> {
});
// 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<Protocol1_13_2To1_14> {
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<Integer> oldId = EntityTypeMapping.getOldId(type);
if (!oldId.isPresent()) {
Optional<EntityData> oldType = getEntityData(entityType);
@ -168,7 +158,24 @@ public class EntityPackets1_14 extends EntityRewriter<Protocol1_13_2To1_14> {
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<Protocol1_13_2To1_14> {
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<Protocol1_13_2To1_14> {
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);