Search in sources :

Example 56 with ItemStack

use of net.minecraft.server.v1_9_R2.ItemStack in project askyblock by tastybento.

the class NMSHandler method isPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#isPotion(org.bukkit.inventory.ItemStack)
     */
@Override
public boolean isPotion(ItemStack item) {
    // Bukkit.getLogger().info("DEBUG:item = " + item);
    if (item.getType().equals(Material.POTION)) {
        net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(item);
        NBTTagCompound tag = stack.getTag();
        /*
            for (String list : tag.c()) {
                Bukkit.getLogger().info("DEBUG: list = " + list);
            }*/
        if (tag != null && (!tag.getString("Potion").equalsIgnoreCase("minecraft:water") || tag.getString("Potion").isEmpty())) {
            return true;
        }
    }
    return false;
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Example 57 with ItemStack

use of net.minecraft.server.v1_9_R2.ItemStack in project askyblock by tastybento.

the class NMSHandler method setPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag)
     */
@SuppressWarnings({ "unchecked" })
@Override
public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) {
    Map<String, Tag> cont = (Map<String, Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag) contents.get("Potion"));
            if (stringTag != null) {
                String tag = ((StringTag) contents.get("Potion")).getValue();
                // Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag);
                net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
                NBTTagCompound tagCompound = stack.getTag();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                tagCompound.setString("Potion", tag);
                stack.setTag(tagCompound);
                return CraftItemStack.asBukkitCopy(stack);
            }
        }
    }
    // Schematic is old, the potions do not have tags
    // Set it to zero so that the potion bottles don't look like giant purple and black blocks
    chestItem.setDurability((short) 0);
    Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water.");
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) Map(java.util.Map)

Example 58 with ItemStack

use of net.minecraft.server.v1_9_R2.ItemStack in project acidisland by tastybento.

the class NMSHandler method setPotion.

/* (non-Javadoc)
     * @see com.wasteofplastic.acidisland.nms.NMSAbstraction#setPotion(com.wasteofplastic.org.jnbt.Tag)
     */
@SuppressWarnings({ "unchecked" })
@Override
public ItemStack setPotion(Material material, Tag itemTags, ItemStack chestItem) {
    Map<String, Tag> cont = (Map<String, Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag) contents.get("Potion"));
            if (stringTag != null) {
                String tag = ((StringTag) contents.get("Potion")).getValue();
                // Bukkit.getLogger().info("DEBUG: potioninfo found: " + tag);
                net.minecraft.server.v1_9_R2.ItemStack stack = CraftItemStack.asNMSCopy(chestItem);
                NBTTagCompound tagCompound = stack.getTag();
                if (tagCompound == null) {
                    tagCompound = new NBTTagCompound();
                }
                tagCompound.setString("Potion", tag);
                stack.setTag(tagCompound);
                return CraftItemStack.asBukkitCopy(stack);
            }
        }
    }
    // Schematic is old, the potions do not have tags
    // Set it to zero so that the potion bottles don't look like giant purple and black blocks
    chestItem.setDurability((short) 0);
    Bukkit.getLogger().warning("Potion in schematic is pre-V1.9 format and will just be water.");
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ListTag(com.wasteofplastic.org.jnbt.ListTag) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) Map(java.util.Map)

Example 59 with ItemStack

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

the class CitizensBlockBreaker method strengthMod.

private float strengthMod(Block block) {
    ItemStack itemstack = getCurrentItem();
    float f = itemstack.a(block);
    if (entity instanceof EntityLiving) {
        EntityLiving handle = (EntityLiving) entity;
        if (f > 1.0F) {
            int i = EnchantmentManager.getDigSpeedEnchantmentLevel(handle);
            if (i > 0) {
                f += i * i + 1;
            }
        }
        if (handle.hasEffect(MobEffectList.FASTER_DIG)) {
            f *= (1.0F + (handle.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F);
        }
        if (handle.hasEffect(MobEffectList.SLOWER_DIG)) {
            float f1 = 1.0F;
            switch(handle.getEffect(MobEffectList.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.j(handle))) {
            f /= 5.0F;
        }
    }
    if (!entity.onGround) {
        f /= 5.0F;
    }
    return f;
}
Also used : EntityLiving(net.minecraft.server.v1_8_R3.EntityLiving) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 60 with ItemStack

use of net.minecraft.server.v1_9_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 (entity instanceof EntityLiving) {
        EntityLiving handle = (EntityLiving) entity;
        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 (!entity.onGround) {
        f /= 5.0F;
    }
    return f;
}
Also used : EntityLiving(net.minecraft.server.v1_12_R1.EntityLiving) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)12 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)8 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)7 ItemStack (net.minecraft.server.v1_8_R1.ItemStack)7 ItemStack (net.minecraft.server.v1_8_R2.ItemStack)7 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)7 NBTTagString (net.minecraft.server.v1_9_R2.NBTTagString)5 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)4 ListTag (com.wasteofplastic.org.jnbt.ListTag)4 StringTag (com.wasteofplastic.org.jnbt.StringTag)4 Tag (com.wasteofplastic.org.jnbt.Tag)4 Map (java.util.Map)4 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)4 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)4 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)3