Java Code Examples for cn.nukkit.item.Item#getId()
The following examples show how to use
cn.nukkit.item.Item#getId() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockEntityFurnace.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public void setItem(int index, Item item) { int i = this.getSlotIndex(index); CompoundTag d = NBTIO.putItemHelper(item, index); if (item.getId() == Item.AIR || item.getCount() <= 0) { if (i >= 0) { this.namedTag.getList("Items").getAll().remove(i); } } else if (i < 0) { (this.namedTag.getList("Items", CompoundTag.class)).add(d); } else { (this.namedTag.getList("Items", CompoundTag.class)).add(i, d); } }
Example 2
Source File: BlockEntityDropper.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public void setItem(int index, Item item) { int i = this.getSlotIndex(index); CompoundTag d = NBTIO.putItemHelper(item, index); if (item.getId() == Item.AIR || item.getCount() <= 0) { if (i >= 0) { this.namedTag.getList("Items").getAll().remove(i); } } else if (i < 0) { (this.namedTag.getList("Items", CompoundTag.class)).add(d); } else { (this.namedTag.getList("Items", CompoundTag.class)).add(i, d); } }
Example 3
Source File: BlockCocoa.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Item item, Player player) { if (item.getId() == Item.DYE && item.getDamage() == 0x0f) { Block block = this.clone(); if (this.getDamage() / 4 < 2) { block.setDamage(block.getDamage() + 4); BlockGrowEvent ev = new BlockGrowEvent(this, block); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } this.getLevel().setBlock(this, ev.getNewState(), true, true); } this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5))); item.count--; return true; } return false; }
Example 4
Source File: BlockCrops.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { //Bone meal if (item.getId() == Item.DYE && item.getDamage() == 0x0f) { if (this.getDamage() < 7) { BlockCrops block = (BlockCrops) this.clone(); block.setDamage(block.getDamage() + ThreadLocalRandom.current().nextInt(3) + 2); if (block.getDamage() > 7) { block.setDamage(7); } BlockGrowEvent ev = new BlockGrowEvent(this, block); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } this.getLevel().setBlock(this, ev.getNewState(), false, true); this.level.addParticle(new BoneMealParticle(this)); if (player != null && (player.gamemode & 0x01) == 0) { item.count--; } } return true; } return false; }
Example 5
Source File: EnchantCommand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean execute(CommandSender sender, String commandLabel, String[] args) { if (!this.testPermission(sender)) { return true; } if (args.length < 2) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } Player player = sender.getServer().getPlayer(args[0]); if (player == null) { sender.sendMessage(new TranslationContainer(TextFormat.RED + "%commands.generic.player.notFound")); return true; } int enchantId; int enchantLevel; try { enchantId = getIdByName(args[1]); enchantLevel = args.length == 3 ? Integer.parseInt(args[2]) : 1; } catch (NumberFormatException e) { sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage)); return true; } Enchantment enchantment = Enchantment.getEnchantment(enchantId); if (enchantment == null) { sender.sendMessage(new TranslationContainer("commands.enchant.notFound", String.valueOf(enchantId))); return true; } enchantment.setLevel(enchantLevel); Item item = player.getInventory().getItemInHand(); if (item.getId() <= 0) { sender.sendMessage(new TranslationContainer("commands.enchant.noItem")); return true; } item.addEnchantment(enchantment); player.getInventory().setItemInHand(item); Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.enchant.success")); return true; }
Example 6
Source File: EntityMob.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item, Vector3 clickedPos) { if (item.getId() == Item.NAME_TAG) { if (item.hasCustomName()) { this.setNameTag(item.getCustomName()); this.setNameTagVisible(true); player.getInventory().removeItem(item); return true; } } return false; }
Example 7
Source File: EntitySheep.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onInteract(Player player, Item item, Vector3 clickedPos) { if (item.getId() == Item.DYE) { this.setColor(((ItemDye) item).getDyeColor().getWoolData()); return true; } return item.getId() == Item.SHEARS && shear(); }
Example 8
Source File: BlockTNT.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { if (item.getId() == Item.FLINT_STEEL) { item.useOn(this); this.prime(); return true; } return false; }
Example 9
Source File: EntityMinecartHopper.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public void saveNBT() { super.saveNBT(); this.namedTag.putList(new ListTag<CompoundTag>("Items")); if (this.inventory != null) { for (int slot = 0; slot < 5; ++slot) { Item item = this.inventory.getItem(slot); if (item != null && item.getId() != Item.AIR) { this.namedTag.getList("Items", CompoundTag.class) .add(NBTIO.putItemHelper(item, slot)); } } } }
Example 10
Source File: BaseInventory.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean setItem(int index, Item item, boolean send) { item = item.clone(); if (index < 0 || index >= this.size) { return false; } else if (item.getId() == 0 || item.getCount() <= 0) { return this.clear(index); } InventoryHolder holder = this.getHolder(); if (holder instanceof Entity) { EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, this.getItem(index), item, index); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { this.sendSlot(index, this.getViewers()); return false; } item = ev.getNewItem(); } Item old = this.getItem(index); this.slots.put(index, item.clone()); this.onSlotChange(index, old, send); return true; }
Example 11
Source File: BaseInventory.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean isEmpty() { if (this.getMaxStackSize() <= 0) { return false; } for (Item item : this.slots.values()) { if (item != null && item.getId() != 0 && item.getCount() > 0) { return false; } } return true; }
Example 12
Source File: BaseInventory.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean isEmpty() { if (this.getMaxStackSize() <= 0) { return false; } for (Item item : this.slots.values()) { if (item != null && item.getId() != 0 && item.getCount() > 0) { return false; } } return true; }
Example 13
Source File: SlotEntityData.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public void setData(Item data) { this.blockId = data.getId(); this.meta = (data.hasMeta() ? data.getDamage() : 0); this.count = data.getCount(); }
Example 14
Source File: ItemBreakParticle.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public ItemBreakParticle(Vector3 pos, Item item) { super(pos, Particle.TYPE_ITEM_BREAK, (item.getId() << 16) | item.getDamage()); }
Example 15
Source File: AnvilInventory.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onRename(Player player, Item resultItem) { Item local = getItem(TARGET); Item second = getItem(SACRIFICE); if (!resultItem.equals(local, true, false) || resultItem.getCount() != local.getCount()) { //Item does not match target item. Everything must match except the tags. return false; } if (local.equals(resultItem)) { //just item transaction return true; } if (local.getId() != 0 && second.getId() == 0) { //only rename local.setCustomName(resultItem.getCustomName()); setItem(RESULT, local); player.getInventory().addItem(local); clearAll(); player.getInventory().sendContents(player); sendContents(player); player.getLevel().addSound(player, Sound.RANDOM_ANVIL_USE); return true; } else if (local.getId() != 0 && second.getId() != 0) { //enchants combining if (!local.equals(second, true, false)) { return false; } if (local.getId() != 0 && second.getId() != 0) { Item result = local.clone(); int enchants = 0; ArrayList<Enchantment> enchantments = new ArrayList<>(Arrays.asList(second.getEnchantments())); ArrayList<Enchantment> baseEnchants = new ArrayList<>(); for (Enchantment ench : local.getEnchantments()) { if (ench.isMajor()) { baseEnchants.add(ench); } } for (Enchantment enchantment : enchantments) { if (enchantment.getLevel() < 0 || enchantment.getId() < 0) { continue; } if (enchantment.isMajor()) { boolean same = false; boolean another = false; for (Enchantment baseEnchant : baseEnchants) { if (baseEnchant.getId() == enchantment.getId()) same = true; else { another = true; } } if (!same && another) { continue; } } Enchantment localEnchantment = local.getEnchantment(enchantment.getId()); if (localEnchantment != null) { int level = Math.max(localEnchantment.getLevel(), enchantment.getLevel()); if (localEnchantment.getLevel() == enchantment.getLevel()) level++; enchantment.setLevel(level); result.addEnchantment(enchantment); continue; } result.addEnchantment(enchantment); enchants++; } result.setCustomName(resultItem.getCustomName()); player.getInventory().addItem(result); player.getInventory().sendContents(player); clearAll(); sendContents(player); player.getLevel().addSound(player, Sound.RANDOM_ANVIL_USE); return true; } } return false; }
Example 16
Source File: EntityOcelot.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean isBreedingItem(Item item) { return item.getId() == Item.RAW_FISH; }
Example 17
Source File: BlockSapling.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean onActivate(Item item, Player player) { if (item.getId() == Item.DYE && item.getDamage() == 0x0F) { //BoneMeal if ((player.gamemode & 0x01) == 0) { item.count--; } this.level.addParticle(new BoneMealParticle(this)); if (this.level.rand.nextFloat() >= 0.45) { return true; } BasicGenerator generator = null; boolean bigTree = false; int x = 0; int z = 0; switch (this.meta) { case JUNGLE: loop: for (x = 0; x >= -1; --x) { for (z = 0; z >= -1; --z) { if (this.findSaplings(x, z, JUNGLE)) { generator = new ObjectJungleBigTree(10, 20, new BlockWood(BlockWood.JUNGLE), new BlockLeaves(BlockLeaves.JUNGLE)); bigTree = true; break loop; } } } if (!bigTree) { generator = new NewJungleTree(4 + this.level.rand.nextInt(7)); } break; case ACACIA: generator = new ObjectSavannaTree(); break; case DARK_OAK: bigTree = false; loop: for (x = 0; x >= -1; --x) { for (z = 0; z >= -1; --z) { if (this.findSaplings(x, z, DARK_OAK)) { generator = new ObjectDarkOakTree(); bigTree = true; break loop; } } } if (!bigTree) { return false; } break; //TODO: big spruce default: ObjectTree.growTree(this.getLevel(), (int) this.x, (int) this.y, (int) this.z, new NukkitRandom(), this.meta & 0x07); return true; } BlockAir air = new BlockAir(); if (bigTree) { this.level.setBlock(this.add(x, 0, z), air, true, false); this.level.setBlock(this.add(x + 1, 0, z), air, true, false); this.level.setBlock(this.add(x, 0, z + 1), air, true, false); this.level.setBlock(this.add(x + 1, 0, z + 1), air, true, false); } else { this.level.setBlock(this, air, true, false); } if (!generator.generate(this.level, new NukkitRandom(), this.add(x, 0, z))) { if (bigTree) { this.level.setBlock(this.add(x, 0, z), this, true, false); this.level.setBlock(this.add(x + 1, 0, z), this, true, false); this.level.setBlock(this.add(x, 0, z + 1), this, true, false); this.level.setBlock(this.add(x + 1, 0, z + 1), this, true, false); } else { this.level.setBlock(this, this, true, false); } } return true; } this.getLevel().loadChunk((int) this.x >> 4, (int) this.z >> 4); return false; }
Example 18
Source File: EntityChicken.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean isBreedingItem(Item item) { int id = item.getId(); return id == Item.WHEAT_SEEDS || id == Item.MELON_SEEDS || id == Item.PUMPKIN_SEEDS || id == Item.BEETROOT_SEEDS; }
Example 19
Source File: SlotEntityData.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public void setData(Item data) { this.blockId = data.getId(); this.meta = (data.hasMeta() ? data.getDamage() : 0); this.count = data.getCount(); }
Example 20
Source File: EntityAnimal.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean isBreedingItem(Item item) { return item.getId() == Item.WHEAT; //default }