Search in sources :

Example 1 with InventoryHolder

use of com.bgsoftware.wildchests.objects.inventory.InventoryHolder in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_18_R1 method deserialze.

@Override
public InventoryHolder[] deserialze(String serialized) {
    byte[] buff;
    if (serialized.toCharArray()[0] == '*') {
        buff = Base64.getDecoder().decode(serialized.substring(1));
    } else {
        buff = new BigInteger(serialized, 32).toByteArray();
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(buff);
    InventoryHolder[] inventories = new InventoryHolder[0];
    try {
        NBTTagCompound tagCompound = NBTCompressedStreamTools.a(new DataInputStream(inputStream), NBTReadLimiter.a);
        int length = getInt(tagCompound, "Length");
        inventories = new InventoryHolder[length];
        for (int i = 0; i < length; i++) {
            if (hasKey(tagCompound, i + "")) {
                NBTTagCompound nbtTagCompound = getCompound(tagCompound, i + "");
                inventories[i] = deserialize(nbtTagCompound);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return inventories;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BigInteger(java.math.BigInteger) DataInputStream(java.io.DataInputStream) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 2 with InventoryHolder

use of com.bgsoftware.wildchests.objects.inventory.InventoryHolder in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_18_R2 method deserialize.

private static InventoryHolder deserialize(NBTTagCompound tagCompound) {
    InventoryHolder inventory = new InventoryHolder(getInt(tagCompound, "Size"), "Chest");
    NBTTagList itemsList = getList(tagCompound, "Items", 10);
    for (int i = 0; i < itemsList.size(); i++) {
        NBTTagCompound nbtTagCompound = getCompound(itemsList, i);
        inventory.setItem(getByte(nbtTagCompound, "Slot"), CraftItemStack.asBukkitCopy(ItemStack.a(nbtTagCompound)));
    }
    return inventory;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 3 with InventoryHolder

use of com.bgsoftware.wildchests.objects.inventory.InventoryHolder in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_16_R3 method deserialize.

private static InventoryHolder deserialize(NBTTagCompound tagCompound) {
    InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
    NBTTagList itemsList = tagCompound.getList("Items", 10);
    for (int i = 0; i < itemsList.size(); i++) {
        NBTTagCompound nbtTagCompound = itemsList.getCompound(i);
        inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(ItemStack.a(nbtTagCompound)));
    }
    return inventory;
}
Also used : NBTTagList(net.minecraft.server.v1_16_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_16_R3.NBTTagCompound) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 4 with InventoryHolder

use of com.bgsoftware.wildchests.objects.inventory.InventoryHolder in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method deserialze.

@Override
public InventoryHolder[] deserialze(String serialized) {
    byte[] buff;
    if (serialized.toCharArray()[0] == '*') {
        buff = Base64.getDecoder().decode(serialized.substring(1));
    } else {
        buff = new BigInteger(serialized, 32).toByteArray();
    }
    ByteArrayInputStream inputStream = new ByteArrayInputStream(buff);
    InventoryHolder[] inventories = new InventoryHolder[0];
    try {
        NBTTagCompound tagCompound = NBTCompressedStreamTools.a(new DataInputStream(inputStream), NBTReadLimiter.a);
        int length = tagCompound.getInt("Length");
        inventories = new InventoryHolder[length];
        for (int i = 0; i < length; i++) {
            if (tagCompound.hasKey(i + "")) {
                NBTTagCompound nbtTagCompound = tagCompound.getCompound(i + "");
                inventories[i] = deserialize(nbtTagCompound);
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return inventories;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BigInteger(java.math.BigInteger) DataInputStream(java.io.DataInputStream) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 5 with InventoryHolder

use of com.bgsoftware.wildchests.objects.inventory.InventoryHolder in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_17_R1 method deserialize.

private static InventoryHolder deserialize(NBTTagCompound tagCompound) {
    InventoryHolder inventory = new InventoryHolder(tagCompound.getInt("Size"), "Chest");
    NBTTagList itemsList = tagCompound.getList("Items", 10);
    for (int i = 0; i < itemsList.size(); i++) {
        NBTTagCompound nbtTagCompound = itemsList.getCompound(i);
        inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(ItemStack.a(nbtTagCompound)));
    }
    return inventory;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Aggregations

InventoryHolder (com.bgsoftware.wildchests.objects.inventory.InventoryHolder)12 ByteArrayInputStream (java.io.ByteArrayInputStream)6 DataInputStream (java.io.DataInputStream)6 BigInteger (java.math.BigInteger)6 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)6 NBTTagList (net.minecraft.nbt.NBTTagList)3 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)2 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)2 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)2 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)1 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)1 NBTTagList (net.minecraft.server.v1_16_R3.NBTTagList)1 NBTTagList (net.minecraft.server.v1_8_R3.NBTTagList)1 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)1