Search in sources :

Example 76 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project MechanicsMain by WeaponMechanics.

the class NonNullList_1_12_R1 method set.

@Override
public ItemStack set(int index, ItemStack newItem) {
    ItemStack oldItem = get(index);
    Item item = (Item) ReflectionUtil.invokeField(itemField, newItem);
    if (newItem.getCount() == 0 && item != null) {
        newItem.setCount(1);
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
        newItem.setCount(0);
    } else if (!ItemStack.matches(oldItem, newItem)) {
        consumer.accept(CraftItemStack.asBukkitCopy(oldItem), CraftItemStack.asBukkitCopy(newItem), index);
    }
    return super.set(index, newItem);
}
Also used : Item(net.minecraft.server.v1_12_R1.Item) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 77 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_11_R1.EnumItemSlot) Packet(net.minecraft.server.v1_11_R1.Packet) ItemStack(net.minecraft.server.v1_11_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_11_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 78 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Citizens2 by CitizensDev.

the class CitizensBlockBreaker method strengthMod.

private float strengthMod(IBlockData block) {
    ItemStack itemstack = getCurrentItem();
    float f = itemstack.a(block);
    if (getHandle() instanceof EntityLiving) {
        EntityLiving handle = (EntityLiving) getHandle();
        if (f > 1.0F) {
            int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
            if (i > 0) {
                f += i * i + 1;
            }
        }
        if (handle.hasEffect(MobEffects.FASTER_DIG)) {
            f *= (1.0F + (handle.getEffect(MobEffects.FASTER_DIG).getAmplifier() + 1) * 0.2F);
        }
        if (handle.hasEffect(MobEffects.SLOWER_DIG)) {
            float f1 = 1.0F;
            switch(handle.getEffect(MobEffects.SLOWER_DIG).getAmplifier()) {
                case 0:
                    f1 = 0.3F;
                    break;
                case 1:
                    f1 = 0.09F;
                    break;
                case 2:
                    f1 = 0.0027F;
                    break;
                case 3:
                default:
                    f1 = 8.1E-4F;
            }
            f *= f1;
        }
        if (handle.a(Material.WATER) && !EnchantmentManager.i(handle)) {
            f /= 5.0F;
        }
    }
    if (!getHandle().onGround) {
        f /= 5.0F;
    }
    return f;
}
Also used : EntityLiving(net.minecraft.server.v1_10_R1.EntityLiving) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_10_R1.ItemStack)

Example 79 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Citizens2 by CitizensDev.

the class CitizensBlockBreaker method strengthMod.

private float strengthMod(IBlockData block) {
    ItemStack itemstack = getCurrentItem();
    float f = itemstack.a(block);
    if (getHandle() instanceof EntityLiving) {
        EntityLiving handle = (EntityLiving) getHandle();
        if (f > 1.0F) {
            int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
            if (i > 0) {
                f += i * i + 1;
            }
        }
        if (handle.hasEffect(MobEffects.FASTER_DIG)) {
            f *= (1.0F + (handle.getEffect(MobEffects.FASTER_DIG).getAmplifier() + 1) * 0.2F);
        }
        if (handle.hasEffect(MobEffects.SLOWER_DIG)) {
            float f1 = 1.0F;
            switch(handle.getEffect(MobEffects.SLOWER_DIG).getAmplifier()) {
                case 0:
                    f1 = 0.3F;
                    break;
                case 1:
                    f1 = 0.09F;
                    break;
                case 2:
                    f1 = 0.0027F;
                    break;
                case 3:
                default:
                    f1 = 8.1E-4F;
            }
            f *= f1;
        }
        if (handle.a(TagsFluid.WATER) && !EnchantmentManager.h(handle)) {
            f /= 5.0F;
        }
    }
    if (!getHandle().onGround) {
        f /= 5.0F;
    }
    return f;
}
Also used : EntityLiving(net.minecraft.server.v1_13_R2.EntityLiving) ItemStack(net.minecraft.server.v1_13_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack)

Example 80 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_13_R2.EnumItemSlot) Packet(net.minecraft.server.v1_13_R2.Packet) ItemStack(net.minecraft.server.v1_13_R2.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_13_R2.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

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 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)14 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)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 (org.bukkit.inventory.ItemStack)11 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)10 NBTTagCompound (net.minecraft.server.v1_16_R3.NBTTagCompound)10 Location (org.bukkit.Location)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