diff --git a/all/pom.xml b/all/pom.xml
index 60b3d8b3..db2a2d94 100644
--- a/all/pom.xml
+++ b/all/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index dff52654..8f98e030 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
diff --git a/bungee/pom.xml b/bungee/pom.xml
index e531a2a0..d8f73ff1 100644
--- a/bungee/pom.xml
+++ b/bungee/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
diff --git a/core/pom.xml b/core/pom.xml
index b428704c..f6a7e408 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
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 7cfd9096..bef1d754 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
@@ -698,133 +698,12 @@ public class BlockItemPackets1_13 extends BlockItemRewriter lore = new ArrayList<>();
- boolean dummyEnchatment = true;
- for (Tag enchantmentEntry : enchantments.clone()) {
- if (enchantmentEntry instanceof CompoundTag) {
- CompoundTag enchEntry = new CompoundTag("");
- String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
- if (enchantmentMappings.containsKey(newId)) {
- lore.add(new StringTag("", enchantmentMappings.get(newId)));
- noMapped.add(enchantmentEntry);
- } else {
- dummyEnchatment = false;
- Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
- if (oldId == null && newId.startsWith("viaversion:legacy/")) {
- oldId = Short.valueOf(newId.substring(18));
- }
- enchEntry.put(
- new ShortTag(
- "id",
- oldId
- )
- );
- enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
- ench.add(enchEntry);
- }
- }
- }
- if (dummyEnchatment && enchantments.size() > 0) {
- ByteTag hideFlags = tag.get("HideFlags");
- if (hideFlags == null) {
- hideFlags = new ByteTag("HideFlags");
- tag.put(new ByteTag(NBT_TAG_NAME + "|noHideFlags"));
- }
- tag.put(new ByteTag(NBT_TAG_NAME + "|dummyEnchatment", hideFlags.getValue()));
-
- CompoundTag enchEntry = new CompoundTag("");
- enchEntry.put(new ShortTag("id", (short) 0));
- enchEntry.put(new ShortTag("lvl", (short) 1));
-
- byte value = hideFlags.getValue();
- hideFlags.setValue(value |= 1);
- tag.put(hideFlags);
-
- ench.add(enchEntry);
- }
- tag.remove("Enchantment");
- tag.put(noMapped);
- tag.put(ench);
-
- if (!lore.isEmpty()) {
- CompoundTag display = tag.get("display");
- if (display == null) {
- tag.put(display = new CompoundTag("display"));
- tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
- }
- ListTag loreTag = display.get("Lore");
- if (loreTag == null) {
- display.put(loreTag = new ListTag("Lore", StringTag.class));
- }
-
- ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
- Iterator iterator = lore.iterator();
- while (iterator.hasNext()) {
- oldLore.add(iterator.next().clone());
- }
- display.put(oldLore);
-
- lore.addAll(loreTag.getValue());
- loreTag.setValue(lore);
- }
+ rewriteEnchantmentsToClient(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
- ListTag storedEnch = tag.get("StoredEnchantments");
- ListTag noMapped = new ListTag(NBT_TAG_NAME + "|StoredEnchantments", CompoundTag.class);
- ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class);
- List lore = new ArrayList<>();
- for (Tag enchantmentEntry : storedEnch) {
- if (enchantmentEntry instanceof CompoundTag) {
- CompoundTag enchEntry = new CompoundTag("");
- String newId = (String) ((CompoundTag) enchantmentEntry).get("id").getValue();
- if (enchantmentMappings.containsKey(newId)) {
- lore.add(new StringTag("", enchantmentMappings.get(newId)));
- noMapped.add(enchantmentEntry);
- } else {
- Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
- if (oldId == null && newId.startsWith("viaversion:legacy/")) {
- oldId = Short.valueOf(newId.substring(18));
- }
- enchEntry.put(
- new ShortTag(
- "id",
- oldId
- )
- );
- enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
- newStoredEnch.add(enchEntry);
- }
- }
- }
- tag.remove("StoredEnchantments");
- tag.put(noMapped);
- tag.put(newStoredEnch);
-
- if (!lore.isEmpty()) {
- CompoundTag display = tag.get("display");
- if (display == null) {
- tag.put(display = new CompoundTag("display"));
- tag.put(new ByteTag(NBT_TAG_NAME + "|noDisplay"));
- }
- ListTag loreTag = display.get("Lore");
- if (loreTag == null) {
- display.put(loreTag = new ListTag("Lore", StringTag.class));
- }
-
- ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
- Iterator iterator = lore.iterator();
- while (iterator.hasNext()) {
- oldLore.add(iterator.next().clone());
- }
- display.put(oldLore);
-
- lore.addAll(loreTag.getValue());
- loreTag.setValue(lore);
- }
+ rewriteEnchantmentsToClient(tag, true);
}
+
if (tag.get(NBT_TAG_NAME + "|CanPlaceOn") instanceof ListTag) {
tag.put(ConverterRegistry.convertToTag(
"CanPlaceOn",
@@ -877,6 +756,81 @@ public class BlockItemPackets1_13 extends BlockItemRewriter lore = new ArrayList<>();
+ boolean hasValidEnchants = false;
+ 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())));
+ noMapped.add(enchantmentEntry);
+ } else if (!newId.isEmpty()) {
+ Short oldId = MappingData.oldEnchantmentsIds.inverse().get(newId);
+ if (oldId == null && newId.startsWith("viaversion:legacy/")) {
+ oldId = Short.valueOf(newId.substring(18));
+ }
+ Short level = (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue();
+ if (level != 0)
+ hasValidEnchants = true;
+ enchEntry.put(new ShortTag("id", oldId));
+ enchEntry.put(new ShortTag("lvl", level));
+ newEnchantments.add(enchEntry);
+ }
+ }
+
+ // Put here to hide empty enchantment from 1.14 rewrites
+ if (!storedEnch && !hasValidEnchants) {
+ IntTag hideFlags = tag.get("HideFlags");
+ if (hideFlags == null) {
+ hideFlags = new IntTag("HideFlags");
+ } else {
+ tag.put(new IntTag(NBT_TAG_NAME + "|OldHideFlags", hideFlags.getValue()));
+ }
+
+ if (newEnchantments.size() == 0) {
+ CompoundTag enchEntry = new CompoundTag("");
+ enchEntry.put(new ShortTag("id", (short) 0));
+ enchEntry.put(new ShortTag("lvl", (short) 0));
+ newEnchantments.add(enchEntry);
+ }
+
+ int value = hideFlags.getValue() | 1;
+ hideFlags.setValue(value);
+ tag.put(hideFlags);
+ }
+
+ if (!lore.isEmpty()) {
+ 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));
+ }
+
+ ListTag oldLore = new ListTag(NBT_TAG_NAME + "|OldLore", StringTag.class);
+ for (Tag value : lore) {
+ oldLore.add(value.clone());
+ }
+ display.put(oldLore);
+
+ lore.addAll(loreTag.getValue());
+ loreTag.setValue(lore);
+ }
+
+ tag.remove("Enchantments");
+ tag.put(newEnchantments);
+ }
+
@Override
protected Item handleItemToServer(Item item) {
if (item == null) return null;
@@ -949,116 +903,12 @@ public class BlockItemPackets1_13 extends BlockItemRewriter iterator = noMapped.iterator();
- while (iterator.hasNext()) {
- enchantments.add(iterator.next());
- }
- tag.remove(NBT_TAG_NAME + "|Enchantments");
- }
- tag.remove("ench");
- tag.put(enchantments);
+ rewriteEnchantmentsToServer(tag, false);
}
if (tag.get("StoredEnchantments") instanceof ListTag) {
- ListTag storedEnch = tag.get("StoredEnchantments");
- ListTag newStoredEnch = new ListTag("StoredEnchantments", CompoundTag.class);
- for (Tag enchEntry : storedEnch) {
- if (enchEntry instanceof CompoundTag) {
- CompoundTag enchantmentEntry = new CompoundTag("");
- short oldId = ((Number) ((CompoundTag) enchEntry).get("id").getValue()).shortValue();
- String newId = MappingData.oldEnchantmentsIds.get(oldId);
- if (newId == null) {
- newId = "viaversion:legacy/" + oldId;
- }
- enchantmentEntry.put(new StringTag("id",
- newId
- ));
- enchantmentEntry.put(new ShortTag("lvl", ((Number) ((CompoundTag) enchEntry).get("lvl").getValue()).shortValue()));
- newStoredEnch.add(enchantmentEntry);
- }
- }
- if (tag.get(NBT_TAG_NAME + "|Enchantments") instanceof ListTag) {
- ListTag noMapped = tag.get(NBT_TAG_NAME + "|StoredEnchantments");
- Iterator iterator = noMapped.iterator();
- while (iterator.hasNext()) {
- newStoredEnch.add(iterator.next());
- }
- }
- tag.remove("StoredEnchantments");
- tag.put(newStoredEnch);
- }
- if (tag.get("CanPlaceOn") instanceof ListTag) {
- ListTag old = tag.get("CanPlaceOn");
- ListTag newCanPlaceOn = new ListTag("CanPlaceOn", StringTag.class);
- tag.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|CanPlaceOn", ConverterRegistry.convertToValue(old))); // There will be data losing
- for (Tag oldTag : old) {
- Object value = oldTag.getValue();
- String[] newValues = BlockIdData.blockIdMapping.get(value instanceof String
- ? ((String) value).replace("minecraft:", "")
- : null);
- if (newValues != null) {
- for (String newValue : newValues) {
- newCanPlaceOn.add(new StringTag("", newValue));
- }
- } else {
- newCanPlaceOn.add(oldTag);
- }
- }
- tag.put(newCanPlaceOn);
- }
- if (tag.get("CanDestroy") instanceof ListTag) {
- ListTag old = tag.get("CanDestroy");
- ListTag newCanDestroy = new ListTag("CanDestroy", StringTag.class);
- tag.put(ConverterRegistry.convertToTag(NBT_TAG_NAME + "|CanDestroy", ConverterRegistry.convertToValue(old))); // There will be data losing
- for (Tag oldTag : old) {
- Object value = oldTag.getValue();
- String[] newValues = BlockIdData.blockIdMapping.get(value instanceof String
- ? ((String) value).replace("minecraft:", "")
- : null);
- if (newValues != null) {
- for (String newValue : newValues) {
- newCanDestroy.add(new StringTag("", newValue));
- }
- } else {
- newCanDestroy.add(oldTag);
- }
- }
- tag.put(newCanDestroy);
+ rewriteEnchantmentsToServer(tag, true);
}
+
// Handle SpawnEggs
if (item.getId() == 383) {
if (tag.get("EntityTag") instanceof CompoundTag) {
@@ -1110,6 +960,68 @@ public class BlockItemPackets1_13 extends BlockItemRewriter {
- private static String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName();
+
+ private static final String NBT_TAG_NAME = "ViaBackwards|" + Protocol1_13_2To1_14.class.getSimpleName();
+ private final Map enchantmentMappings = new HashMap<>();
@Override
protected void registerPackets(Protocol1_13_2To1_14 protocol) {
@@ -736,6 +734,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;
@@ -797,10 +846,47 @@ public class BlockItemPackets1_14 extends BlockItemRewriter
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
diff --git a/pom.xml b/pom.xml
index b98a0e31..2bdb04c3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -16,7 +16,7 @@
nl.matsv
viabackwards-parent
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
pom
Allow newer clients to join older server versions.
diff --git a/sponge/pom.xml b/sponge/pom.xml
index e2c0d36f..0ab7811a 100644
--- a/sponge/pom.xml
+++ b/sponge/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0
diff --git a/velocity/pom.xml b/velocity/pom.xml
index e96ec60c..162c5196 100644
--- a/velocity/pom.xml
+++ b/velocity/pom.xml
@@ -15,7 +15,7 @@
viabackwards-parent
nl.matsv
- 3.0.0-1.14.3
+ 3.0.0-SNAPSHOT
4.0.0