NBT-API

NBT-API

98.9k Downloads

Merging Compound Sometimes Behaviors Weirdly

DefinitlyEvil opened this issue ยท 0 comments

commented

Sometimes instead of merging that portion of the compound, it merges its top parent compounds leading to data leakage (for tile entities this caused map corruption for me).

It will only have this issue if you're merging a compound from another sub-compound. In my case I was trying to merge a sub-compound of tile entity into a newly created NBTContainer.

My temporary fix is to grab the raw object and wrap it to NBTContainer manually when reading the compound that you're about to merge into other compounds.

Thanks for yout time,
Tobias.

Code I used to FIX the problem:

    public static void putCIFData(NBTCompound nbtCompound, CIFItem item, NBTCompound data) {
        nbtCompound.setString("Type", item.type());
        if(data != null && NBTReflectionUtil.valideCompound(data)) {
            try {
                NBTReflectionUtil.set(nbtCompound, "Data", NBTTools.gettoCompount(data.getCompound(), data));
            } catch (NbtApiException ex) {
                ex.printStackTrace();
            }
        }
    }

    public static CIFItemInstance getCIFData(NBTCompound nbtCompound) {
        if(nbtCompound == null) return null;
        if(!nbtCompound.hasKey("Type")) return null;
        CIFItem type = ItemRegister.get(nbtCompound.getString("Type"));
        if(type == null) return null;
        NBTCompound data = null;
        if(nbtCompound.hasKey("Data")) {
            data = nbtCompound.getCompound("Data");
            data = new NBTContainer(NBTTools.gettoCompount(data.getCompound(), data));
        }
        return new CIFItemInstance(type, data);
    }