Search in sources :

Example 41 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project WildChests by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method serialize.

@Override
public String serialize(org.bukkit.inventory.ItemStack itemStack) {
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    DataOutput dataOutput = new DataOutputStream(outputStream);
    NBTTagCompound tagCompound = new NBTTagCompound();
    ItemStack nmsItem = CraftItemStack.asNMSCopy(itemStack);
    if (nmsItem.isEmpty())
        return "";
    if (nmsItem != null) {
        nmsItem.setCount(1);
        nmsItem.save(tagCompound);
    }
    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) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 42 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project InteractionVisualizer by LOOHP.

the class V1_16_2 method createEntityEquipmentPacket.

@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
    List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R2.ItemStack>> nmsList = new ArrayList<>();
    for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
        EnumItemSlot nmsSlot;
        switch(pair.getFirst()) {
            case CHEST:
                nmsSlot = EnumItemSlot.CHEST;
                break;
            case FEET:
                nmsSlot = EnumItemSlot.FEET;
                break;
            case HEAD:
                nmsSlot = EnumItemSlot.HEAD;
                break;
            case LEGS:
                nmsSlot = EnumItemSlot.LEGS;
                break;
            case OFF_HAND:
                nmsSlot = EnumItemSlot.OFFHAND;
                break;
            case HAND:
            default:
                nmsSlot = EnumItemSlot.MAINHAND;
                break;
        }
        net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
        nmsList.add(new Pair<>(nmsSlot, nmsItem));
    }
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
    return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) ArrayList(java.util.ArrayList) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) EnumItemSlot(net.minecraft.server.v1_16_R2.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R2.PacketPlayOutEntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 43 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project PublicCrafters by BananaPuncher714.

the class CustomContainerAnvil method e.

public void e() {
    EntityHuman player = ((CraftHumanEntity) this.player).getHandle();
    ItemStack itemstack = subcontainer.getItem(0);
    this.a = 1;
    int i = 0;
    byte b0 = 0;
    byte b1 = 0;
    if (itemstack.isEmpty()) {
        CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
        this.a = 0;
    } else {
        ItemStack itemstack1 = itemstack.cloneItemStack();
        if ((itemstack1.getCount() > 1) && (!player.abilities.canInstantlyBuild) && (!(itemstack1.getItem() instanceof ItemNameTag))) {
            itemstack1.setCount(1);
        }
        ItemStack itemstack2 = subcontainer.getItem(1);
        Map map = EnchantmentManager.a(itemstack1);
        int j = b0 + itemstack.getRepairCost() + (itemstack2.isEmpty() ? 0 : itemstack2.getRepairCost());
        xpCost = 0;
        if (!itemstack2.isEmpty()) {
            boolean flag = (itemstack2.getItem() == Items.ENCHANTED_BOOK) && (!Items.ENCHANTED_BOOK.h(itemstack2).isEmpty());
            if ((itemstack1.f()) && (itemstack1.getItem().a(itemstack, itemstack2))) {
                int k = Math.min(itemstack1.i(), itemstack1.k() / 4);
                if (k <= 0) {
                    CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
                    this.a = 0;
                    return;
                }
                for (int l = 0; (k > 0) && (l < itemstack2.getCount()); l++) {
                    int i1 = itemstack1.i() - k;
                    itemstack1.setData(i1);
                    i++;
                    k = Math.min(itemstack1.i(), itemstack1.k() / 4);
                    xpCost = l;
                }
            } else {
                if ((!flag) && ((itemstack1.getItem() != itemstack2.getItem()) || (!itemstack1.f()))) {
                    CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
                    this.a = 0;
                    return;
                }
                if ((itemstack1.f()) && (!flag)) {
                    int k = itemstack.k() - itemstack.i();
                    int l = itemstack2.k() - itemstack2.i();
                    int i1 = l + itemstack1.k() * 12 / 100;
                    int j1 = k + i1;
                    int k1 = itemstack1.k() - j1;
                    if (k1 < 0) {
                        k1 = 0;
                    }
                    if (k1 < itemstack1.getData()) {
                        itemstack1.setData(k1);
                        i += 2;
                    }
                }
                Map<Enchantment, Integer> map1 = EnchantmentManager.a(itemstack2);
                boolean flag1 = false;
                boolean flag2 = false;
                Iterator iterator = map1.keySet().iterator();
                while (iterator.hasNext()) {
                    Enchantment enchantment = (Enchantment) iterator.next();
                    if (enchantment != null) {
                        int l1 = map.containsKey(enchantment) ? ((Integer) map.get(enchantment)).intValue() : 0;
                        int i2 = ((Integer) map1.get(enchantment)).intValue();
                        i2 = l1 == i2 ? i2 + 1 : Math.max(i2, l1);
                        boolean flag3 = enchantment.canEnchant(itemstack);
                        if ((player.abilities.canInstantlyBuild) || (itemstack.getItem() == Items.ENCHANTED_BOOK)) {
                            flag3 = true;
                        }
                        Iterator iterator1 = map.keySet().iterator();
                        while (iterator1.hasNext()) {
                            Enchantment enchantment1 = (Enchantment) iterator1.next();
                            if ((enchantment1 != enchantment) && (!enchantment.c(enchantment1))) {
                                flag3 = false;
                                i++;
                            }
                        }
                        if (!flag3) {
                            flag2 = true;
                        } else {
                            flag1 = true;
                            if (i2 > enchantment.getMaxLevel()) {
                                i2 = enchantment.getMaxLevel();
                            }
                            map.put(enchantment, Integer.valueOf(i2));
                            int j2 = 0;
                            switch(enchantment.e()) {
                                case COMMON:
                                    j2 = 1;
                                    break;
                                case RARE:
                                    j2 = 2;
                                    break;
                                case UNCOMMON:
                                    j2 = 4;
                                    break;
                                case VERY_RARE:
                                    j2 = 8;
                            }
                            if (flag) {
                                j2 = Math.max(1, j2 / 2);
                            }
                            i += j2 * i2;
                        }
                    }
                }
                if ((flag2) && (!flag1)) {
                    CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), ItemStack.a);
                    this.a = 0;
                    return;
                }
            }
        }
        if (StringUtils.isBlank(this.l)) {
            if (itemstack.hasName()) {
                b1 = 1;
                i += b1;
                itemstack1.s();
            }
        } else if (!this.l.equals(itemstack.getName())) {
            b1 = 1;
            i += b1;
            itemstack1.g(this.l);
        }
        this.a = (j + i);
        if (i <= 0) {
            itemstack1 = ItemStack.a;
        }
        if ((b1 == i) && (b1 > 0) && (this.a >= 40)) {
            this.a = 39;
        }
        if ((this.a >= 40) && (!player.abilities.canInstantlyBuild)) {
            itemstack1 = ItemStack.a;
        }
        if (!itemstack1.isEmpty()) {
            int k2 = itemstack1.getRepairCost();
            if ((!itemstack2.isEmpty()) && (k2 < itemstack2.getRepairCost())) {
                k2 = itemstack2.getRepairCost();
            }
            if ((b1 != i) || (b1 == 0)) {
                k2 = k2 * 2 + 1;
            }
            itemstack1.setRepairCost(k2);
            EnchantmentManager.a(map, itemstack1);
        }
        CraftEventFactory.callPrepareAnvilEvent(getBukkitView(), itemstack1);
        b();
    }
}
Also used : EntityHuman(net.minecraft.server.v1_11_R1.EntityHuman) ItemNameTag(net.minecraft.server.v1_11_R1.ItemNameTag) CraftHumanEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity) Iterator(java.util.Iterator) ItemStack(net.minecraft.server.v1_11_R1.ItemStack) Enchantment(net.minecraft.server.v1_11_R1.Enchantment) Map(java.util.Map)

Example 44 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method setCraftResult.

public void setCraftResult() {
    CraftingManager.getInstance().lastCraftView = getBukkitView();
    ItemStack craftResult = CraftingManager.getInstance().craft(craftInventory, world);
    resultInventory.setItem(0, craftResult);
    if (listeners.isEmpty()) {
        return;
    }
    if ((craftResult != null) && (craftResult.getItem() == Items.FILLED_MAP)) {
        return;
    }
    for (Object listener : listeners) {
        EntityPlayer player = (EntityPlayer) listener;
        player.playerConnection.sendPacket(new PacketPlayOutSetSlot(player.activeContainer.windowId, 0, craftResult));
    }
}
Also used : EntityPlayer(net.minecraft.server.v1_11_R1.EntityPlayer) PacketPlayOutSetSlot(net.minecraft.server.v1_11_R1.PacketPlayOutSetSlot) ItemStack(net.minecraft.server.v1_11_R1.ItemStack)

Example 45 with ItemStack

use of net.minecraft.server.v1_16_R2.ItemStack in project PublicCrafters by BananaPuncher714.

the class CustomContainerWorkbench method b.

/**
 * This might be for when the inventory closes?
 */
@Override
public void b(EntityHuman entity) {
    super.b(entity);
    // Make sure the craft inventory stops watching this container
    craftInventory.removeContainer(this);
    if (PublicCrafters.getInstance().isDropItem()) {
        if (!world.isClientSide) {
            for (int i = 0; i < 9; i++) {
                ItemStack itemstack = craftInventory.splitWithoutUpdate(i);
                if (itemstack != null) {
                    entity.drop(itemstack, false);
                }
            }
            setCraftResult();
            craftInventory.update();
        }
    }
}
Also used : ItemStack(net.minecraft.server.v1_11_R1.ItemStack)

Aggregations

ItemStack (net.minecraft.server.v1_12_R1.ItemStack)28 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)21 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)20 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)17 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)16 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)13 CraftItemStack (org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack)13 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)12 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)12 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)11 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)10 NBTTagCompound (net.minecraft.server.v1_16_R2.NBTTagCompound)10 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)10 TagCompound (de.keyle.knbt.TagCompound)9 Field (java.lang.reflect.Field)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ItemStack (net.minecraft.server.v1_13_R2.ItemStack)9 ItemStack (net.minecraft.server.v1_15_R1.ItemStack)9