-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Datafixer. Auto update 1.20.4 items to 1.20.5
- Loading branch information
Showing
11 changed files
with
105 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
item-nbt-api/src/main/java/de/tr7zw/changeme/nbtapi/utils/DataFixerUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package de.tr7zw.changeme.nbtapi.utils; | ||
|
||
import com.mojang.datafixers.DSL.TypeReference; | ||
import com.mojang.datafixers.DataFixer; | ||
import com.mojang.serialization.Dynamic; | ||
import com.mojang.serialization.DynamicOps; | ||
|
||
import de.tr7zw.changeme.nbtapi.NBTCompound; | ||
import de.tr7zw.changeme.nbtapi.NBTContainer; | ||
import de.tr7zw.changeme.nbtapi.NBTReflectionUtil; | ||
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 = 3817; // 1.20.4 | ||
public static final int VERSION1_20_5 = 3825; // 1.20.5 | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Object fixUpRawItemData(Object nbt, int fromVersion, int toVersion) | ||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | ||
DataFixer dataFixer = (DataFixer) ReflectionMethod.GET_DATAFIXER.run(null); | ||
TypeReference itemStackReference = (TypeReference) ClassWrapper.NMS_REFERENCES.getClazz() | ||
.getField(MojangToMapping.getMapping().get("net.minecraft.util.datafix.fixes.References#ITEM_STACK")) | ||
.get(null); | ||
DynamicOps<Object> nbtOps = (DynamicOps<Object>) ClassWrapper.NMS_NBTOPS.getClazz() | ||
.getField(MojangToMapping.getMapping().get("net.minecraft.nbt.NbtOps#INSTANCE")).get(null); | ||
Dynamic<Object> fixed = dataFixer.update(itemStackReference, new Dynamic<Object>(nbtOps, nbt), fromVersion, toVersion); | ||
return fixed.getValue(); | ||
} | ||
|
||
public static NBTCompound fixUpItemData(NBTCompound nbt, int fromVersion, int toVersion) | ||
throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { | ||
return new NBTContainer(fixUpRawItemData(NBTReflectionUtil.getToCompount(nbt.getCompound(), nbt), fromVersion, toVersion)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
item-nbt-plugin/src/main/java/de/tr7zw/nbtapi/plugin/tests/items/LegacyItemTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package de.tr7zw.nbtapi.plugin.tests.items; | ||
|
||
import org.bukkit.Material; | ||
import org.bukkit.enchantments.Enchantment; | ||
import org.bukkit.inventory.ItemStack; | ||
|
||
import de.tr7zw.changeme.nbtapi.NBT; | ||
import de.tr7zw.changeme.nbtapi.NbtApiException; | ||
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) { | ||
throw new NbtApiException("1.20 item didn't load correctly! " + item); | ||
} | ||
} | ||
|
||
} |