From 94f57ddb97dc126c8e12ca327801705fc76c236b Mon Sep 17 00:00:00 2001 From: Chuanwise Date: Tue, 1 Nov 2022 20:31:16 +0800 Subject: [PATCH] add 1.19 support --- .../zcraft/quartzlib/components/nbt/NBT.java | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/fr/zcraft/quartzlib/components/nbt/NBT.java b/src/main/java/fr/zcraft/quartzlib/components/nbt/NBT.java index aced4c8d..2282e18e 100644 --- a/src/main/java/fr/zcraft/quartzlib/components/nbt/NBT.java +++ b/src/main/java/fr/zcraft/quartzlib/components/nbt/NBT.java @@ -301,20 +301,30 @@ private static Object getMcNBTCompound(ItemStack item) throws NMSException { try { Object tagCompound; try { - //1.18 - tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); + // 1.19 + tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "getTagClone"); } catch (Exception e) { - //1.17 try { - tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "getTag"); - } catch (Exception e2) { - tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "a"); + // 1.18 + tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "t"); + } catch (Exception e1) { + // 1.17 + try { + tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "getTag"); + } catch (Exception e2) { + tagCompound = Reflection.call(mcItemStack.getClass(), mcItemStack, "a"); + } } } if (tagCompound == null) { tagCompound = Reflection.instantiate(MC_NBT_TAG_COMPOUND); - Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tagCompound); + try { + // 1.19 + Reflection.call(MC_ITEM_STACK, mcItemStack, "setTagClone", tagCompound); + } catch (Exception e) { + Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tagCompound); + } } return tagCompound; @@ -327,11 +337,16 @@ private static Object getMcNBTCompound(ItemStack item) throws NMSException { tag = Reflection.instantiate(MC_NBT_TAG_COMPOUND); try { - Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tag); - } catch (NoSuchMethodException e) { - // If the set method change—more resilient, - // as the setTag will only update the field without any kind of callback. - Reflection.setFieldValue(MC_ITEM_STACK, mcItemStack, "tag", tag); + // 1.19 + Reflection.call(MC_ITEM_STACK, mcItemStack, "setTagClone", tag); + } catch (Exception e) { + try { + Reflection.call(MC_ITEM_STACK, mcItemStack, "setTag", tag); + } catch (NoSuchMethodException e2) { + // If the set method change—more resilient, + // as the setTag will only update the field without any kind of callback. + Reflection.setFieldValue(MC_ITEM_STACK, mcItemStack, "tag", tag); + } } }