Java Code Examples for cn.nukkit.item.Item#hasCustomName()
The following examples show how to use
cn.nukkit.item.Item#hasCustomName() .
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: BlockEnderChest.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = {2, 5, 3, 4}; this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag("") .putString("id", BlockEntity.ENDER_CHEST) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityEnderChest(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 2
Source File: BlockEnchantingTable.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ENCHANT_TABLE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntity.createBlockEntity(BlockEntity.ENCHANT_TABLE, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 3
Source File: BlockEnchantingTable.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ENCHANT_TABLE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntity.createBlockEntity(BlockEntity.ENCHANT_TABLE, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 4
Source File: BlockEnderChest.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = {4, 2, 5, 3}; this.meta = faces[player != null ? player.getDirection().getHorizontalIndex() : 0]; this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag("") .putString("id", BlockEntity.ENDER_CHEST) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityEnderChest(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 5
Source File: BlockEnderChest.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = {2, 5, 3, 4}; this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag("") .putString("id", BlockEntity.ENDER_CHEST) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityEnderChest ender = (BlockEntityEnderChest) BlockEntity.createBlockEntity(BlockEntity.ENDER_CHEST, this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return ender != null; }
Example 6
Source File: BlockFurnaceBurning.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int[] faces = {2, 5, 3, 4}; this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.FURNACE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityFurnace furnace = (BlockEntityFurnace) BlockEntity.createBlockEntity(BlockEntity.FURNACE, this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt); return furnace != null; }
Example 7
Source File: BlockEnchantingTable.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ENCHANT_TABLE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityEnchantTable enchantTable = (BlockEntityEnchantTable) BlockEntity.createBlockEntity(BlockEntity.ENCHANT_TABLE, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return enchantTable != null; }
Example 8
Source File: EntityAnimal.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 9
Source File: BlockFurnaceBurning.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int faces[] = {2, 5, 3, 4}; this.setDamage(faces[player != null ? player.getDirection().getHorizontalIndex() : 0]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.FURNACE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt); return true; }
Example 10
Source File: BlockBrewingStand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (!block.down().isTransparent()) { getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.BREWING_STAND) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityBrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; } return false; }
Example 11
Source File: BlockUndyedShulkerBox.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true); CompoundTag nbt = BlockEntity.getDefaultCompound(this, BlockEntity.SHULKER_BOX) .putByte("facing", face.getIndex()); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } CompoundTag t = item.getNamedTag(); // This code gets executed when the player has broken the shulker box and placed it back (©Kevims 2020) if (t != null && t.contains("Items")) { nbt.putList(t.getList("Items")); } // This code gets executed when the player has copied the shulker box in creative mode (©Kevims 2020) if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityShulkerBox box = (BlockEntityShulkerBox) BlockEntity.createBlockEntity(BlockEntity.SHULKER_BOX, this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt); return box != null; }
Example 12
Source File: BlockBrewingStand.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (!block.down().isTransparent()) { getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.BREWING_STAND) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } BlockEntityBrewingStand brewing = (BlockEntityBrewingStand) BlockEntity.createBlockEntity(BlockEntity.BREWING_STAND, getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return brewing != null; } return false; }
Example 13
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 14
Source File: BlockShulkerBox.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag("") .putString("id", BlockEntity.SHULKER_BOX) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.getNamedTag() != null && item.getNamedTag().contains("List")){ nbt.putList(item.getNamedTag().getList("Items")); } if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityShulkerBox(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 15
Source File: BlockFurnaceBurning.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int faces[] = {4, 2, 5, 3}; this.meta = faces[player != null ? player.getDirection().getHorizontalIndex() : 0]; this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.FURNACE) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityFurnace(this.getLevel().getChunk((int) (this.x) >> 4, (int) (this.z) >> 4), nbt); return true; }
Example 16
Source File: BlockBrewingStand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { if (!block.down().isTransparent()) { getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.BREWING_STAND) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityBrewingStand(getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; } return false; }
Example 17
Source File: BlockShulkerBoxUndyed.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag("") .putString("id", BlockEntity.SHULKER_BOX) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.getNamedTag() != null && item.getNamedTag().contains("List")){ nbt.putList(item.getNamedTag().getList("Items")); } if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityShulkerBox(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 18
Source File: BlockDispenser.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int f = 0; if (player instanceof Player) { double pitch = player.getPitch(); if (Math.abs(pitch) >= 45) { if (pitch < 0) { f = 4; } else { f = 5; } } else { f = player.getDirection().getHorizontalIndex(); } } int[] faces = new int[]{4, 2, 5, 3, 0, 1}; this.meta = faces[f]; this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.DISPENSER) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityDispenser(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }
Example 19
Source File: BlockDropper.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { int f = 0; if (player instanceof Player) { double pitch = player.getPitch(); if (Math.abs(pitch) >= 45) { if (pitch < 0) { f = 4; } else { f = 5; } } else { f = player.getDirection().getHorizontalIndex(); } } int[] faces = new int[]{4, 2, 5, 3, 0, 1}; this.meta = faces[f]; this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putList(new ListTag<>("Items")) .putString("id", BlockEntity.DROPPER) .putInt("x", (int) this.x) .putInt("y", (int) this.y) .putInt("z", (int) this.z); if (item.hasCustomName()) { nbt.putString("CustomName", item.getCustomName()); } if (item.hasCustomBlockData()) { Map<String, Tag> customData = item.getCustomBlockData().getTags(); for (Map.Entry<String, Tag> tag : customData.entrySet()) { nbt.put(tag.getKey(), tag.getValue()); } } new BlockEntityDropper(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); return true; }