/** * Gets the current display name of an Item. * If no name is set, the default Material name is returned instead. * * @param stack to get the display name of * @return display name */ public static String getDisplayName(org.bukkit.inventory.ItemStack stack) { return CommonNMS.getNative(stack).getName(); }
/** * Checks whether an item has a custom display name set * * @param stack to check * @return True if a custom name is set, False if not */ public static boolean hasDisplayName(org.bukkit.inventory.ItemStack stack) { return CommonNMS.getNative(stack).hasName(); }
public ItemStack splitStack(int slot, int subtract) { if (slot < size && items.get(slot) != null) { if (items.get(slot).count <= subtract) { ItemStack itemStack = items.get(slot); items.set(slot, null); return itemStack; } else { ItemStack itemStack = items.get(slot); ItemStack splittedStack = new ItemStack(itemStack.getItem(), subtract, itemStack.getData()); if (itemStack.getTag() != null) { splittedStack.setTag(((NBTTagCompound) itemStack.getTag().clone())); } itemStack.count -= subtract; if (items.get(slot).count == 0) { items.set(slot, null); } return splittedStack; } } return null; }
public static TagCompound itemStackToCompund(ItemStack itemStack) { TagCompound compound = new TagCompound(); compound.getCompoundData().put("id", new TagShort((short) Item.getId(itemStack.getItem()))); compound.getCompoundData().put("Count", new TagByte((byte) itemStack.count)); compound.getCompoundData().put("Damage", new TagShort((short) itemStack.getData())); if (itemStack.getTag() != null) { compound.getCompoundData().put("tag", vanillaCompoundToCompound(itemStack.getTag())); } return compound; }
public void load(MaterialHolder material, String data) { Item item = (Item) Item.REGISTRY.get(material.getLegacyName().getName()); if (item == null) { return; } net.minecraft.server.v1_7_R4.ItemStack is = new net.minecraft.server.v1_7_R4.ItemStack(item, 1, material.getLegacyName().getData()); if (data != null) { NBTBase tag = null; String nbtString = data.trim(); if (nbtString.startsWith("{") && nbtString.endsWith("}")) { String tagString = data.substring(data.indexOf("{"), data.lastIndexOf("}")); data = data.substring(0, data.indexOf("{")); try { tag = MojangsonParser.parse(tagString); } catch (Exception e) { MyPetApi.getLogger().warning("Error" + ChatColor.RESET + " in config: " + ChatColor.YELLOW + e.getLocalizedMessage() + ChatColor.RESET + " caused by:"); MyPetApi.getLogger().warning(data + tagString); } if (tag != null) { is.setTag((NBTTagCompound) tag); } } } this.item = CraftItemStack.asCraftMirror(is); } }
public boolean handlePlayerInteraction(EntityHuman entityhuman) { if (super.handlePlayerInteraction(entityhuman)) { return true; } ItemStack itemStack = entityhuman.inventory.getItemInHand(); if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (getMyPet().isOnFire() && itemStack.getItem() == Items.GLASS_BOTTLE && itemStack.getData() == 0 && getOwner().getPlayer().isSneaking()) { getMyPet().setOnFire(false); makeSound("random.fizz", 1.0F, 1.0F); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) { entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.GLASS_BOTTLE)); } else { if (!entityhuman.inventory.pickup(new ItemStack(Items.GLASS_BOTTLE))) { entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true); } } } return true; } else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.FLINT_AND_STEEL && getOwner().getPlayer().isSneaking()) { getMyPet().setOnFire(true); makeSound("fire.ignite", 1.0F, 1.0F); if (!entityhuman.abilities.canInstantlyBuild) { itemStack.damage(1, entityhuman); } return true; } } return false; }
Player owner = this.getOwner().getPlayer(); if (itemStack != null && itemStack.getItem() == Items.LEASH) { ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutAttachEntity(1, this, null)); if (!entityhuman.abilities.canInstantlyBuild) { if (itemStack.getItem() == Items.NAME_TAG && itemStack.hasName()) { if (Permissions.has(getOwner(), "MyPet.command.name") && Permissions.hasExtended(getOwner(), "MyPet.extended.nametag")) { final String name = itemStack.getName(); getMyPet().setPetName(name); EntityMyPet.super.setCustomName("-"); if (itemStack.getItem() == Items.NAME_TAG) { if (itemStack.hasName()) { EntityMyPet.super.setCustomName("-"); new BukkitRunnable() {
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); if (itemInSlot != null) { EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); itemStack.damage(1, entityhuman); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) { EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
public boolean handlePlayerInteraction(EntityHuman entityhuman) { if (super.handlePlayerInteraction(entityhuman)) { return true; } ItemStack itemStack = entityhuman.inventory.getItemInHand(); if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (itemStack.getItem() == Item.getItemOf(Blocks.RED_ROSE) && !getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { getMyPet().setFlower(CraftItemStack.asBukkitCopy(itemStack)); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) { entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null); } } return true; } else if (itemStack.getItem() == Items.SHEARS && getMyPet().hasFlower() && getOwner().getPlayer().isSneaking()) { EntityItem entityitem = this.a(CraftItemStack.asNMSCopy(getMyPet().getFlower()), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); makeSound("mob.sheep.shear", 1.0F, 1.0F); getMyPet().setFlower(null); if (!entityhuman.abilities.canInstantlyBuild) { itemStack.damage(1, entityhuman); } return true; } } return false; }
if (itemStack.getItem().equals(Items.BOWL)) { if (!getOwner().equals(entityhuman) || !canUseItem() || !Configuration.MyPet.Mooshroom.CAN_GIVE_SOUP) { final int itemInHandIndex = entityhuman.inventory.itemInHandIndex; ItemStack is = new ItemStack(Items.MUSHROOM_SOUP); final ItemStack oldIs = entityhuman.inventory.getItem(itemInHandIndex); entityhuman.inventory.setItem(itemInHandIndex, is); entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_SOUP)); } else { if (!entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_SOUP))) { entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
if (itemStack.getItem() == Items.INK_SACK && itemStack.getData() != getMyPet().getCollarColor().getWoolData()) { if (itemStack.getData() <= 15) { if (getOwner().getPlayer().isSneaking()) { getMyPet().setCollarColor(DyeColor.getByWoolData((byte) itemStack.getData())); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) {
int slot = EntityInsentient.b(itemstack); if (slot == 0) { if (itemstack.getItem() instanceof ItemSword) { return true; } else if (itemstack.getItem() instanceof ItemAxe) { return true; } else if (itemstack.getItem() instanceof ItemSpade) { return true; } else if (itemstack.getItem() instanceof ItemHoe) { return true; } else if (itemstack.getItem() instanceof ItemPickaxe) { return true; } else if (itemstack.getItem() instanceof ItemBow) { return true; } else if (itemstack.getItem() instanceof ItemFishingRod) { return true; } else if (itemstack.getItem() == Items.COMPASS) { return true; } else if (itemstack.getItem() == Items.WATCH) { return true; } else if (itemstack.getItem() instanceof ItemCarrotStick) { return true; } else if (itemstack.getItem() instanceof ItemSign) { return true;
@Override public ItemStack splitStack(int index, int size) { ItemStack item = this.getItem(index); if (item != null) { ItemStack itemstack; if (item.count <= size) { itemstack = item; this.setItem(index, null); return itemstack; } else { itemstack = item.a(size); if (item.count == 0) { this.setItem(index, null); } return itemstack; } } else { return null; } }
/** * Sets the current display name of an Item * * @param stack to set the display name of * @param displayName to set to, null to reset to the default */ public static void setDisplayName(org.bukkit.inventory.ItemStack stack, String displayName) { if (displayName != null) { CommonNMS.getNative(stack).c(displayName); } else if (hasDisplayName(stack)) { CommonNMS.getNative(stack).tag.remove("display"); } } }
public void dropContentAt(Location loc) { World world = ((CraftWorld) loc.getWorld()).getHandle(); for (int i = 0; i < this.getSize(); i++) { ItemStack is = this.splitWithoutUpdate(i); if (is != null) { is = is.cloneItemStack(); EntityItem itemEntity = new EntityItem(world, loc.getX(), loc.getY(), loc.getZ(), is); itemEntity.pickupDelay = 20; world.addEntity(itemEntity); } } }
/** * Creates an inventory from a tag list * * @param tags Tag list * @return Inventory */ public static Inventory createInventory(CommonTagList tags) { Inventory inv = new CraftInventoryCustom(null, tags.size()); for(int i = 0; i < tags.size(); i++) { CommonTagCompound tag = (CommonTagCompound) tags.get(i); if(!tag.isEmpty()) { inv.setItem(i, CraftItemStack.asCraftMirror(ItemStack.createStack( (NBTTagCompound) tag.getHandle()))); } } return inv; }
if (itemStack.getItem() == Items.INK_SACK && itemStack.getData() <= 15 && itemStack.getData() != getMyPet().getColor().getDyeData() && !getMyPet().isSheared()) { getMyPet().setColor(DyeColor.getByDyeData((byte) itemStack.getData())); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) { } else if (itemStack.getItem() == Items.SHEARS && Configuration.MyPet.Sheep.CAN_BE_SHEARED && !getMyPet().isSheared()) { getMyPet().setSheared(true); int woolDropCount = 1 + this.random.nextInt(3); EntityItem entityitem = this.a(new ItemStack(Blocks.WOOL, 1, getMyPet().getColor().ordinal()), 1.0F); itemStack.damage(1, entityhuman);
if (itemStack.getItem() == Items.SHEARS && getOwner().getPlayer().isSneaking() && canEquip()) { boolean hadEquipment = false; for (EquipmentSlot slot : EquipmentSlot.values()) { ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); if (itemInSlot != null) { EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); itemStack.damage(1, entityhuman); ItemStack itemInSlot = CraftItemStack.asNMSCopy(getMyPet().getEquipment(slot)); if (itemInSlot != null && !entityhuman.abilities.canInstantlyBuild) { EntityItem entityitem = this.a(itemInSlot.cloneItemStack(), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F);
public boolean compare(Object o) { net.minecraft.server.v1_7_R4.ItemStack compareItem = (net.minecraft.server.v1_7_R4.ItemStack) o; if (item == null || item.getTypeId() == 0) { if (compareItem == null || Item.getId(compareItem.getItem()) == 0) { return true; } else { return false; if (item.getTypeId() != Item.getId(compareItem.getItem())) { return false; if (compareItem.getData() <= item.getDurability()) { return false; if (compareItem.getData() >= item.getDurability()) { return false; if (compareItem.getData() != item.getDurability()) { return false; return CraftItemStack.asNMSCopy(item).getTag().equals(compareItem.getTag());
public boolean handlePlayerInteraction(EntityHuman entityhuman) { if (super.handlePlayerInteraction(entityhuman)) { return true; } ItemStack itemStack = entityhuman.inventory.getItemInHand(); if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) { if (itemStack.getItem() == Items.SHEARS && getMyPet().hasBlock() && getOwner().getPlayer().isSneaking()) { EntityItem entityitem = this.a(CraftItemStack.asNMSCopy(getMyPet().getBlock()), 1.0F); entityitem.motY += (double) (this.random.nextFloat() * 0.05F); entityitem.motX += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); entityitem.motZ += (double) ((this.random.nextFloat() - this.random.nextFloat()) * 0.1F); makeSound("mob.sheep.shear", 1.0F, 1.0F); getMyPet().setBlock(null); if (!entityhuman.abilities.canInstantlyBuild) { itemStack.damage(1, entityhuman); } return true; } else if (getMyPet().getBlock() == null && Util.isBetween(1, 255, Item.getId(itemStack.getItem())) && getOwner().getPlayer().isSneaking()) { getMyPet().setBlock(CraftItemStack.asBukkitCopy(itemStack)); if (!entityhuman.abilities.canInstantlyBuild) { if (--itemStack.count <= 0) { entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null); } } return true; } } return false; }