Skip to content

Commit

Permalink
Add more version ids, test loading 1.12.2 items in 1.20.5
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Apr 25, 2024
1 parent b74b0b8 commit 027f2a2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTContainer;
import de.tr7zw.changeme.nbtapi.NBTReflectionUtil;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ClassWrapper;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.MojangToMapping;
import de.tr7zw.changeme.nbtapi.utils.nmsmappings.ReflectionMethod;

public class DataFixerUtil {

public static final int VERSION1_20_4 = 3700; // 1.20.4
public static final int VERSION1_20_5 = 3837; // 1.20.5
public static final int VERSION1_12_2 = 1343;
public static final int VERSION1_16_5 = 2586;
public static final int VERSION1_17_1 = 2730;
public static final int VERSION1_18_2 = 2975;
public static final int VERSION1_19_2 = 3120;
public static final int VERSION1_19_4 = 3337;
public static final int VERSION1_20_1 = 3465;
public static final int VERSION1_20_2 = 3578;
public static final int VERSION1_20_4 = 3700;
public static final int VERSION1_20_5 = 3837;

@SuppressWarnings("unchecked")
public static Object fixUpRawItemData(Object nbt, int fromVersion, int toVersion)
Expand All @@ -30,9 +39,9 @@ public static Object fixUpRawItemData(Object nbt, int fromVersion, int toVersion
return fixed.getValue();
}

public static NBTCompound fixUpItemData(NBTCompound nbt, int fromVersion, int toVersion)
public static ReadWriteNBT fixUpItemData(ReadWriteNBT nbt, int fromVersion, int toVersion)
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
return new NBTContainer(fixUpRawItemData(NBTReflectionUtil.getToCompount(nbt.getCompound(), nbt), fromVersion, toVersion));
return new NBTContainer(fixUpRawItemData(NBTReflectionUtil.getToCompount(((NBTCompound) nbt).getCompound(), ((NBTCompound) nbt)), fromVersion, toVersion));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@

import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NbtApiException;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.utils.DataFixerUtil;
import de.tr7zw.nbtapi.plugin.tests.Test;

public class LegacyItemTest implements Test {

@Override
public void test() throws Exception {
ItemStack item = NBT.itemStackFromNBT(NBT.parseNBT("{id:cobblestone,Count:42,tag:{Enchantments:[{lvl:3,id:unbreaking}]}}"));
if(item.getType() != Material.COBBLESTONE || item.getAmount() != 42 || item.getEnchantmentLevel(Enchantment.DURABILITY) != 3) {
ItemStack item = NBT
.itemStackFromNBT(NBT.parseNBT("{id:cobblestone,Count:42,tag:{Enchantments:[{lvl:3,id:unbreaking}]}}"));
if (item.getType() != Material.COBBLESTONE || item.getAmount() != 42
|| item.getEnchantmentLevel(Enchantment.DURABILITY) != 3) {
throw new NbtApiException("1.20 item didn't load correctly! " + item);
}
ReadWriteNBT nbt = NBT
.parseNBT("{id:cobblestone,Count:42,tag:{display:{Name:\"test\"},ench:[{lvl:3,id:34}]}}");
nbt = DataFixerUtil.fixUpItemData(nbt, DataFixerUtil.VERSION1_12_2, DataFixerUtil.VERSION1_20_5);
item = NBT.itemStackFromNBT(nbt);
if (item.getType() != Material.COBBLESTONE || item.getAmount() != 42
|| item.getEnchantmentLevel(Enchantment.DURABILITY) != 3
|| !"test".equals(item.getItemMeta().getDisplayName())) {
throw new NbtApiException("1.12.2 item didn't load correctly! " + item);
}
}

}

0 comments on commit 027f2a2

Please sign in to comment.