Search in sources :

Example 1 with ItemNameTag

use of net.minecraft.server.v1_11_R1.ItemNameTag 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)

Aggregations

Iterator (java.util.Iterator)1 Map (java.util.Map)1 Enchantment (net.minecraft.server.v1_11_R1.Enchantment)1 EntityHuman (net.minecraft.server.v1_11_R1.EntityHuman)1 ItemNameTag (net.minecraft.server.v1_11_R1.ItemNameTag)1 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)1 CraftHumanEntity (org.bukkit.craftbukkit.v1_11_R1.entity.CraftHumanEntity)1