Search in sources :

Example 21 with Slot

use of net.minecraft.server.v1_12_R1.Slot in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method serialize.

@Override
public String serialize(Inventory[] inventories) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutput dataOutput = new DataOutputStream(outputStream);
    NBTTagCompound tagCompound = new NBTTagCompound();
    tagCompound.setInt("Length", inventories.length);
    for (int slot = 0; slot < inventories.length; slot++) {
        NBTTagCompound inventoryCompound = new NBTTagCompound();
        serialize(inventories[slot], inventoryCompound);
        tagCompound.set(slot + "", inventoryCompound);
    }
    try {
        NBTCompressedStreamTools.a(tagCompound, dataOutput);
    } catch (Exception ex) {
        return null;
    }
    return "*" + new String(Base64.getEncoder().encode(outputStream.toByteArray()));
}
Also used : DataOutput(java.io.DataOutput) DataOutputStream(java.io.DataOutputStream) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 22 with Slot

use of net.minecraft.server.v1_12_R1.Slot in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method deserialize.

private 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.get(i);
        inventory.setItem(nbtTagCompound.getByte("Slot"), CraftItemStack.asBukkitCopy(new ItemStack(nbtTagCompound)));
    }
    return inventory;
}
Also used : NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) InventoryHolder(com.bgsoftware.wildchests.objects.inventory.InventoryHolder)

Example 23 with Slot

use of net.minecraft.server.v1_12_R1.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.12.2
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) theseSlots.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return ItemStack.a;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return ItemStack.a;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.f();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_13_R2.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_13_R2.Slot) ItemStack(net.minecraft.server.v1_13_R2.ItemStack)

Example 24 with Slot

use of net.minecraft.server.v1_12_R1.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method b.

/**
 * The shift clicking method
 */
@Override
public ItemStack b(EntityHuman entityhuman, int i) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.c.get(i);
    if ((slot != null) && (slot.hasItem())) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            itemstack1.getItem().b(itemstack1, world, entityhuman);
            if (!a(itemstack1, 10, 46, true)) {
                return null;
            }
            slot.a(itemstack1, itemstack);
        } else if ((i >= 10) && (i < 37)) {
            if (!a(itemstack1, 37, 46, false)) {
                return null;
            }
        } else if ((i >= 37) && (i < 46)) {
            if (!a(itemstack1, 10, 37, false)) {
                return null;
            }
        } else if (!a(itemstack1, 10, 46, false)) {
            return null;
        }
        slot.f();
        if (itemstack1.count == itemstack.count) {
            return null;
        }
        slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack1, false);
        }
    }
    return itemstack;
}
Also used : PacketPlayOutSetSlot(net.minecraft.server.v1_8_R3.PacketPlayOutSetSlot) Slot(net.minecraft.server.v1_8_R3.Slot) ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Example 25 with Slot

use of net.minecraft.server.v1_12_R1.Slot in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method shiftClick.

// Overrides 1.15.1
@Override
public ItemStack shiftClick(EntityHuman entityhuman, int i) {
    ItemStack itemstack = ItemStack.a;
    Slot slot = (Slot) this.slots.get(i);
    if (slot != null && slot.hasItem()) {
        ItemStack itemstack1 = slot.getItem();
        itemstack = itemstack1.cloneItemStack();
        if (i == 0) {
            this.containerAccess.a((world, blockposition) -> {
                itemstack1.getItem().b(itemstack1, world, entityhuman);
            });
            if (!this.a(itemstack1, 10, 46, true)) {
                return ItemStack.a;
            }
            slot.a(itemstack1, itemstack);
        } else if (i >= 10 && i < 46 ? !this.a(itemstack1, 1, 10, false) && (i < 37 ? !this.a(itemstack1, 37, 46, false) : !this.a(itemstack1, 10, 37, false)) : !this.a(itemstack1, 10, 46, false)) {
            return ItemStack.a;
        }
        if (itemstack1.isEmpty()) {
            slot.set(ItemStack.a);
        } else {
            slot.d();
        }
        if (itemstack1.getCount() == itemstack.getCount()) {
            return ItemStack.a;
        }
        ItemStack itemstack2 = slot.a(entityhuman, itemstack1);
        if (i == 0) {
            entityhuman.drop(itemstack2, false);
        }
    }
    return itemstack;
}
Also used : Slot(net.minecraft.server.v1_15_R1.Slot) ItemStack(net.minecraft.server.v1_15_R1.ItemStack)

Aggregations

NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)9 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)7 NBTTagList (net.minecraft.server.v1_12_R1.NBTTagList)6 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)6 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)3 Slot (net.minecraft.server.v1_12_R1.Slot)3 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2 HardwareTokenType (ee.ria.xroad.signer.tokenmanager.token.HardwareTokenType)2 Slot (iaik.pkcs.pkcs11.Slot)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)2 Slot (net.minecraft.server.v1_11_R1.Slot)2 NBTTagInt (net.minecraft.server.v1_12_R1.NBTTagInt)2 ScoreboardObjective (net.minecraft.server.v1_12_R1.ScoreboardObjective)2 InventoryHolder (com.bgsoftware.wildchests.objects.inventory.InventoryHolder)1 FailedNbt (com.ruinscraft.panilla.api.exception.FailedNbt)1 INbtTagCompound (com.ruinscraft.panilla.api.nbt.INbtTagCompound)1 NbtTagCompound (com.ruinscraft.panilla.craftbukkit.v1_12_R1.nbt.NbtTagCompound)1 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)1 CustomInventory (de.Keyle.MyPet.compat.v1_12_R1.util.inventory.CustomInventory)1