Search in sources :

Example 66 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    // TODO allow items like FIRE (51)
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    if (icon.getTags() != null) {
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_9_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) NBTTagCompound(net.minecraft.server.v1_9_R1.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_9_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R1.NBTTagString) ItemStack(net.minecraft.server.v1_9_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)

Example 67 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project MyPet by xXKeyleXx.

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_9_R1.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_9_R1.util.inventory.CustomInventory)

Example 68 with ItemStack

use of net.minecraft.server.v1_8_R2.ItemStack in project Essentials by EssentialsX.

the class v1_8_R2SpawnerProvider method setEntityType.

@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
    net.minecraft.server.v1_8_R2.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null) {
        tag = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = itemStack.getTag().getCompound("BlockEntityTag");
    tag.setString("EntityId", type.getName());
    ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
    return setDisplayName(bukkitItemStack, type);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 69 with ItemStack

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

the class NMSHandler method setFlowerPotBlock.

/* (non-Javadoc)
     * @see com.wasteofplastic.askyblock.nms.NMSAbstraction#setBlock(org.bukkit.block.Block, org.bukkit.inventory.ItemStack)
     * Credis: Mister_Frans (THANK YOU VERY MUCH !)
     */
@Override
public void setFlowerPotBlock(Block block, ItemStack itemStack) {
    Location loc = block.getLocation();
    CraftWorld cw = (CraftWorld) block.getWorld();
    BlockPosition bp = new BlockPosition(loc.getX(), loc.getY(), loc.getZ());
    TileEntityFlowerPot te = (TileEntityFlowerPot) cw.getHandle().getTileEntity(bp);
    // Bukkit.getLogger().info("Debug: flowerpot materialdata = " + (new ItemStack(potItem, 1,(short) potItemData).toString()));
    net.minecraft.server.v1_8_R2.ItemStack cis = CraftItemStack.asNMSCopy(itemStack);
    te.a(cis.getItem(), cis.getData());
    te.update();
}
Also used : BlockPosition(net.minecraft.server.v1_8_R2.BlockPosition) TileEntityFlowerPot(net.minecraft.server.v1_8_R2.TileEntityFlowerPot) CraftWorld(org.bukkit.craftbukkit.v1_8_R2.CraftWorld) Location(org.bukkit.Location)

Example 70 with ItemStack

use of net.minecraft.server.v1_8_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 (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(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 (!getHandle().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)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)10 Location (org.bukkit.Location)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)9 NBTTagCompound (net.minecraft.server.v1_8_R2.NBTTagCompound)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 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)6 ItemStack (org.bukkit.inventory.ItemStack)6 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)5 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)5 NBTTagString (net.minecraft.server.v1_8_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 ArrayList (java.util.ArrayList)4