cn.nukkit.item.ItemBlock Java Examples

The following examples show how to use cn.nukkit.item.ItemBlock. 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: EntitySheep.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Item[] getDrops() {
    if (!(this.sheared)) {
        if (this.isOnFire()) {
            return new Item[]{new ItemBlock(new BlockWool()), new ItemMuttonCooked(0, random.nextRange(1, 3))};
        } else {
            return new Item[]{new ItemBlock(new BlockWool()), new ItemMuttonRaw(0, random.nextRange(1, 3))};
        }
    } else {
        if (this.isOnFire()) {
            return new Item[]{new ItemMuttonCooked(0, random.nextRange(1, 3))};
        } else {
            return new Item[]{new ItemMuttonRaw(0, random.nextRange(1, 3))};
        }
    }
}
 
Example #2
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void setArmorContents(Item[] items) {
    if (items.length < 4) {
        Item[] newItems = new Item[4];
        System.arraycopy(items, 0, newItems, 0, items.length);
        items = newItems;
    }

    for (int i = 0; i < 4; ++i) {
        if (items[i] == null) {
            items[i] = new ItemBlock(Block.get(BlockID.AIR), null, 0);
        }

        if (items[i].getId() == Item.AIR) {
            this.clear(this.getSize() + i);
        } else {
            this.setItem(this.getSize() + i, items[i]);
        }
    }
}
 
Example #3
Source File: BlockEntityBeacon.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean updateCompoundTag(CompoundTag nbt, Player player) {
    if (!nbt.getString("id").equals(BlockEntity.BEACON)) {
        return false;
    }

    this.setPrimaryPower(nbt.getInt("primary"));
    this.setSecondaryPower(nbt.getInt("secondary"));

    this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BEACON_POWER);

    BeaconInventory inv = (BeaconInventory)player.getWindowById(Player.BEACON_WINDOW_ID);

    inv.setItem(0, new ItemBlock(Block.get(BlockID.AIR), 0, 0));
    return true;
}
 
Example #4
Source File: BlockLeaves2.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    if (item.isShears()) {
        return new Item[]{
                toItem()
        };
    } else {
        if ((int) ((Math.random()) * 200) == 0 && this.meta == DARK_OAK) {
            return new Item[]{
                    new ItemApple()
            };
        }
        if ((int) ((Math.random()) * 20) == 0) {
            return new Item[]{
                    new ItemBlock(new BlockSapling(), this.meta & 0x03, 1)
            };
        }
    }
    return new Item[0];
}
 
Example #5
Source File: BlockLeaves.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    if (item.isShears()) {
        return new Item[]{
                toItem()
        };
    } else {
        if ((int) ((Math.random()) * 200) == 0 && (this.meta & 0x03) == OAK) {
            return new Item[]{
                    new ItemApple()
            };
        }
        if ((int) ((Math.random()) * 20) == 0) {
            return new Item[]{
                    new ItemBlock(new BlockSapling(), this.meta & 0x03, 1)
            };
        }
    }
    return new Item[0];
}
 
Example #6
Source File: BlockEntityItemFrame.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CompoundTag getSpawnCompound() {
    if (!this.namedTag.contains("Item")) {
        this.setItem(new ItemBlock(Block.get(BlockID.AIR)), false);
    }
    CompoundTag item = namedTag.getCompound("Item").copy();
    item.setName("Item");
    CompoundTag tag = new CompoundTag()
            .putString("id", BlockEntity.ITEM_FRAME)
            .putInt("x", (int) this.x)
            .putInt("y", (int) this.y)
            .putInt("z", (int) this.z);

    if (item.getShort("id") != Item.AIR) {
        tag.putCompound("Item", item)
                .putByte("ItemRotation", this.getItemRotation());
    }
    return tag;
}
 
Example #7
Source File: PlayerInventory.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
public void setArmorContents(Item[] items) {
    if (items.length < 4) {
        Item[] newItems = new Item[4];
        System.arraycopy(items, 0, newItems, 0, items.length);
        items = newItems;
    }

    for (int i = 0; i < 4; ++i) {
        if (items[i] == null) {
            items[i] = new ItemBlock(new BlockAir(), null, 0);
        }

        if (items[i].getId() == Item.AIR) {
            this.clear(this.getSize() + i);
        } else {
            this.setItem(this.getSize() + i, items[i]);
        }
    }
}
 
Example #8
Source File: BlockEntityItemFrame.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void initBlockEntity() {
    if (!namedTag.contains("Item")) {
        namedTag.putCompound("Item", NBTIO.putItemHelper(new ItemBlock(Block.get(BlockID.AIR))));
    }
    if (!namedTag.contains("ItemRotation")) {
        namedTag.putByte("ItemRotation", 0);
    }
    if (!namedTag.contains("ItemDropChance")) {
        namedTag.putFloat("ItemDropChance", 1.0f);
    }

    this.level.updateComparatorOutputLevel(this);

    super.initBlockEntity();
}
 
Example #9
Source File: BlockEntityShulkerBox.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(Block.get(BlockID.AIR), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #10
Source File: BlockHugeMushroomRed.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    if (new NukkitRandom().nextRange(1, 20) == 0) {
        return new Item[]{
                new ItemBlock(new BlockMushroomRed())
        };
    } else {
        return new Item[0];
    }
}
 
Example #11
Source File: BlockEntityBrewingStand.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(Block.get(BlockID.AIR), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #12
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean clear(int index, boolean send) {
    if (this.slots.containsKey(index)) {
        Item item = new ItemBlock(Block.get(BlockID.AIR), null, 0);
        Item old = this.slots.get(index);
        InventoryHolder holder = this.getHolder();
        if (holder instanceof Entity) {
            EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, old, item, index);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                this.sendSlot(index, this.getViewers());
                return false;
            }
            item = ev.getNewItem();
        }
        if (holder instanceof BlockEntity) {
            ((BlockEntity) holder).setDirty();
        }

        if (item.getId() != Item.AIR) {
            this.slots.put(index, item.clone());
        } else {
            this.slots.remove(index);
        }

        this.onSlotChange(index, old, send);
    }

    return true;
}
 
Example #13
Source File: BlockAnvil.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item toItem() {
    int damage = this.getDamage();
    if (damage >= 4 && damage <= 7) {
        return new ItemBlock(this, this.getDamage() & 0x04);
    } else if (damage >= 8 && damage <= 11) {
        return new ItemBlock(this, this.getDamage() & 0x08);
    } else {
        return new ItemBlock(this);
    }
}
 
Example #14
Source File: BlockItemFrame.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@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 #15
Source File: EntitySheep.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public boolean shear() {
    if (sheared) {
        return false;
    }

    this.sheared = true;
    this.setDataFlag(DATA_FLAGS, DATA_FLAG_SHEARED, true);

    this.level.dropItem(this, new ItemBlock(new BlockWool(this.getColor()), 0, this.level.rand.nextInt(2) + 1));
    return true;
}
 
Example #16
Source File: BlockEntityFurnace.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(Block.get(BlockID.AIR), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #17
Source File: BlockHugeMushroomBrown.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item[] getDrops(Item item) {
    if (new NukkitRandom().nextRange(1, 20) == 0) {
        return new Item[]{
                new ItemBlock(new BlockMushroomBrown())
        };
    } else {
        return new Item[0];
    }
}
 
Example #18
Source File: PlayerInventory.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public Item getItemInHand() {
    Item item = this.getItem(this.getHeldItemIndex());
    if (item != null) {
        return item;
    } else {
        return new ItemBlock(Block.get(BlockID.AIR), 0, 0);
    }
}
 
Example #19
Source File: BaseInventory.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean clear(int index, boolean send) {
    if (this.slots.containsKey(index)) {
        Item item = new ItemBlock(new BlockAir(), null, 0);
        Item old = this.slots.get(index);
        InventoryHolder holder = this.getHolder();
        if (holder instanceof Entity) {
            EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, this, old, item, index);
            Server.getInstance().getPluginManager().callEvent(ev);
            if (ev.isCancelled()) {
                this.sendSlot(index, this.getViewers());
                return false;
            }
            item = ev.getNewItem();
        }

        if (item.getId() != Item.AIR) {
            this.slots.put(index, item.clone());
        } else {
            this.slots.remove(index);
        }

        this.onSlotChange(index, old, send);
    }

    return true;
}
 
Example #20
Source File: BlockEntityDropper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #21
Source File: BlockEntityHopper.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #22
Source File: BlockEntityShulkerBox.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #23
Source File: BlockEntityFurnace.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #24
Source File: BlockEntityHopper.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(Block.get(BlockID.AIR), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #25
Source File: BlockEntityDispenser.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item getItem(int index) {
    int i = this.getSlotIndex(index);
    if (i < 0) {
        return new ItemBlock(new BlockAir(), 0, 0);
    } else {
        CompoundTag data = (CompoundTag) this.namedTag.getList("Items").get(i);
        return NBTIO.getItemHelper(data);
    }
}
 
Example #26
Source File: EntityElderGuardian.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Item[] getDrops() {
    Item drops[] = new Item[4];
    drops[0] = new ItemPrismarineCrystals(0, random.nextRange(0, 1));
    drops[1] = new ItemPrismarineShard(0, random.nextRange(0, 2));
    //TODO: 60%の確率で生魚、25%の確率で生鮭、2%の確率でクマノミ、13%の確率でフグ。また焼死時には焼き魚、焼き鮭をドロップ
    if (this.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
        drops[2] = new ItemBlock(new BlockSponge());
    }
    return drops;
}
 
Example #27
Source File: BlockFire.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    return new ItemBlock(Block.get(BlockID.AIR));
}
 
Example #28
Source File: BlockDoubleSlabWood.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    return new ItemBlock(Block.get(BlockID.WOODEN_SLAB), this.getDamage() & 0x07);
}
 
Example #29
Source File: BlockTorch.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    return new ItemBlock(this, 0);
}
 
Example #30
Source File: BlockStairsRedSandstone.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Item toItem() {
    return new ItemBlock(this, this.getDamage() & 0x07);
}