cn.nukkit.blockentity.BlockEntityItemFrame Java Examples
The following examples show how to use
cn.nukkit.blockentity.BlockEntityItemFrame.
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: Server.java From Jupiter with GNU General Public License v3.0 | 6 votes |
private void registerBlockEntities() { BlockEntity.registerBlockEntity(BlockEntity.FURNACE, BlockEntityFurnace.class); BlockEntity.registerBlockEntity(BlockEntity.CHEST, BlockEntityChest.class); BlockEntity.registerBlockEntity(BlockEntity.SIGN, BlockEntitySign.class); BlockEntity.registerBlockEntity(BlockEntity.ENCHANT_TABLE, BlockEntityEnchantTable.class); BlockEntity.registerBlockEntity(BlockEntity.SKULL, BlockEntitySkull.class); BlockEntity.registerBlockEntity(BlockEntity.FLOWER_POT, BlockEntityFlowerPot.class); BlockEntity.registerBlockEntity(BlockEntity.BREWING_STAND, BlockEntityBrewingStand.class); BlockEntity.registerBlockEntity(BlockEntity.ITEM_FRAME, BlockEntityItemFrame.class); BlockEntity.registerBlockEntity(BlockEntity.CAULDRON, BlockEntityCauldron.class); BlockEntity.registerBlockEntity(BlockEntity.ENDER_CHEST, BlockEntityEnderChest.class); BlockEntity.registerBlockEntity(BlockEntity.BEACON, BlockEntityBeacon.class); BlockEntity.registerBlockEntity(BlockEntity.SHULKER_BOX, BlockEntityShulkerBox.class); BlockEntity.registerBlockEntity(BlockEntity.MOB_SPAWNER, BlockEntityMobSpawner.class); BlockEntity.registerBlockEntity(BlockEntity.DISPENSER, BlockEntityDispenser.class); BlockEntity.registerBlockEntity(BlockEntity.DROPPER, BlockEntityDropper.class); BlockEntity.registerBlockEntity(BlockEntity.COMMAND_BLOCK, BlockEntityCommandBlock.class); BlockEntity.registerBlockEntity(BlockEntity.BANNER, BlockEntityBanner.class); }
Example #2
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Item item, Player player) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; if (itemFrame.getItem().getId() == Item.AIR) { Item itemOnFrame = item.clone(); if (player != null && player.isSurvival()) { itemOnFrame.setCount(itemOnFrame.getCount() - 1); player.getInventory().setItemInHand(itemOnFrame); } itemOnFrame.setCount(1); itemFrame.setItem(itemOnFrame); this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ADD_ITEM); } else { itemFrame.setItemRotation((itemFrame.getItemRotation() + 1) % 8); this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ROTATE_ITEM); } return true; }
Example #3
Source File: BlockItemFrame.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) { if (face.getIndex() > 1 && target.isSolid() && (!block.isSolid() || block.canBeReplaced())) { this.setDamage(FACING[face.getIndex()]); this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ITEM_FRAME) .putInt("x", (int) block.x) .putInt("y", (int) block.y) .putInt("z", (int) block.z) .putByte("ItemRotation", 0) .putFloat("ItemDropChance", 1.0f); if (item.hasCustomBlockData()) { for (Tag aTag : item.getCustomBlockData().getAllTags()) { nbt.put(aTag.getName(), aTag); } } BlockEntityItemFrame frame = (BlockEntityItemFrame) BlockEntity.createBlockEntity(BlockEntity.ITEM_FRAME, this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); if (frame == null) { return false; } this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_PLACE); return true; } return false; }
Example #4
Source File: BlockItemFrame.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; if (itemFrame.getItem().getId() == Item.AIR) { // We can't use Item.get(item.getId(), item.getDamage(), 1) because // we need to keep the item's NBT tags Item itemOnFrame = item.clone(); // So we clone the item itemOnFrame.setCount(1); // Change it to only one item (if we keep +1, visual glitches will happen) itemFrame.setItem(itemOnFrame); // And then we set it on the item frame // The item will be removed from the player's hand a few lines ahead this.getLevel().addSound(new ItemFrameItemAddedSound(this)); if (player != null && player.isSurvival()) { int count = item.getCount(); if (count-- <= 0) { player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0)); return true; } item.setCount(count); player.getInventory().setItemInHand(item); } } else { int itemRot = itemFrame.getItemRotation(); if (itemRot >= 7) { itemRot = 0; } else { itemRot++; } itemFrame.setItemRotation(itemRot); this.getLevel().addSound(new ItemFrameItemRotated(this)); } return true; }
Example #5
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int getComparatorInputOverride() { BlockEntity blockEntity = this.level.getBlockEntity(this); if (blockEntity instanceof BlockEntityItemFrame) { return ((BlockEntityItemFrame) blockEntity).getAnalogOutput(); } return super.getComparatorInputOverride(); }
Example #6
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops(Item item) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; int chance = new Random().nextInt(100) + 1; if (itemFrame != null && chance <= (itemFrame.getItemDropChance() * 100)) { return new Item[]{ toItem(), Item.get(itemFrame.getItem().getId(), itemFrame.getItem().getDamage(), 1) }; } else { return new Item[]{ toItem() }; } }
Example #7
Source File: BlockItemFrame.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 (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) { switch (face) { case NORTH: this.setDamage(3); break; case SOUTH: this.setDamage(2); break; case WEST: this.setDamage(1); break; case EAST: this.setDamage(0); break; default: return false; } this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ITEM_FRAME) .putInt("x", (int) block.x) .putInt("y", (int) block.y) .putInt("z", (int) block.z) .putByte("ItemRotation", 0) .putFloat("ItemDropChance", 1.0f); if (item.hasCustomBlockData()) { for (Tag aTag : item.getCustomBlockData().getAllTags()) { nbt.put(aTag.getName(), aTag); } } new BlockEntityItemFrame(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_PLACE); return true; } return false; }
Example #8
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Item item, Player player) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; if (itemFrame.getItem().getId() == Item.AIR) { // We can't use Item.get(item.getId(), item.getDamage(), 1) because // we need to keep the item's NBT tags Item itemOnFrame = item.clone(); // So we clone the item itemOnFrame.setCount(1); // Change it to only one item (if we keep +1, visual glitches will happen) itemFrame.setItem(itemOnFrame); // And then we set it on the item frame // The item will be removed from the player's hand a few lines ahead this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ADD_ITEM); if (player != null && player.isSurvival()) { int count = item.getCount(); if (count-- <= 0) { player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0)); return true; } item.setCount(count); player.getInventory().setItemInHand(item); } } else { int itemRot = itemFrame.getItemRotation(); if (itemRot >= 7) { itemRot = 0; } else { itemRot++; } itemFrame.setItemRotation(itemRot); this.getLevel().addSound(this, Sound.BLOCK_ITEMFRAME_ROTATE_ITEM); } return true; }
Example #9
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int getComparatorInputOverride() { BlockEntity blockEntity = this.level.getBlockEntity(this); if (blockEntity instanceof BlockEntityItemFrame) { return ((BlockEntityItemFrame) blockEntity).getAnalogOutput(); } return super.getComparatorInputOverride(); }
Example #10
Source File: BlockItemFrame.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops(Item item) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; int chance = new Random().nextInt(100) + 1; if (itemFrame != null && chance <= (itemFrame.getItemDropChance() * 100)) { return new Item[]{ toItem(), itemFrame.getItem().clone() }; } else { return new Item[]{ toItem() }; } }
Example #11
Source File: BlockItemFrame.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public int getComparatorInputOverride() { BlockEntity blockEntity = this.level.getBlockEntity(this); if (blockEntity instanceof BlockEntityItemFrame) { return ((BlockEntityItemFrame) blockEntity).getAnalogOutput(); } return super.getComparatorInputOverride(); }
Example #12
Source File: BlockItemFrame.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public Item[] getDrops(Item item) { BlockEntity blockEntity = this.getLevel().getBlockEntity(this); BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity; int chance = new Random().nextInt(100) + 1; if (itemFrame != null && chance <= (itemFrame.getItemDropChance() * 100)) { return new Item[]{ toItem(), Item.get(itemFrame.getItem().getId(), itemFrame.getItem().getDamage(), 1) }; } else { return new Item[]{ toItem() }; } }
Example #13
Source File: BlockItemFrame.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 (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) { switch (face) { case NORTH: this.meta = 3; break; case SOUTH: this.meta = 2; break; case WEST: this.meta = 1; break; case EAST: this.meta = 0; break; default: return false; } this.getLevel().setBlock(block, this, true, true); CompoundTag nbt = new CompoundTag() .putString("id", BlockEntity.ITEM_FRAME) .putInt("x", (int) block.x) .putInt("y", (int) block.y) .putInt("z", (int) block.z) .putByte("ItemRotation", 0) .putFloat("ItemDropChance", 1.0f); if (item.hasCustomBlockData()) { for (Tag aTag : item.getCustomBlockData().getAllTags()) { nbt.put(aTag.getName(), aTag); } } new BlockEntityItemFrame(this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); this.getLevel().addSound(new ItemFramePlacedSound(this)); return true; } return false; }
Example #14
Source File: ItemFrameDropItemEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public BlockEntityItemFrame getItemFrame() { return itemFrame; }
Example #15
Source File: ItemFrameDropItemEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public ItemFrameDropItemEvent(Player player, Block block, BlockEntityItemFrame itemFrame, Item item) { super(block); this.player = player; this.itemFrame = itemFrame; this.item = item; }
Example #16
Source File: ItemFrameDropItemEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public BlockEntityItemFrame getItemFrame() { return itemFrame; }
Example #17
Source File: ItemFrameDropItemEvent.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public ItemFrameDropItemEvent(Player player, Block block, BlockEntityItemFrame itemFrame, Item item) { super(block); this.player = player; this.itemFrame = itemFrame; this.item = item; }
Example #18
Source File: ItemFrameDropItemEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public ItemFrameDropItemEvent(Player player, Block block, BlockEntityItemFrame itemFrame, Item item) { super(block); this.player = player; this.itemFrame = itemFrame; this.item = item; }
Example #19
Source File: ItemFrameDropItemEvent.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public BlockEntityItemFrame getItemFrame() { return itemFrame; }