Java Code Examples for cn.nukkit.item.Item#getDamage()

The following examples show how to use cn.nukkit.item.Item#getDamage() . 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: BlockDoublePlant.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) { //Bone meal
        switch (this.getDamage() & 0x07) {
            case SUNFLOWER:
            case LILAC:
            case ROSE_BUSH:
            case PEONY:
                if (player != null && (player.gamemode & 0x01) == 0) {
                    item.count--;
                }
                this.level.addParticle(new BoneMealParticle(this));
                this.level.dropItem(this, this.toItem());
        }

        return true;
    }

    return false;
}
 
Example 2
Source File: BlockCocoa.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@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 3
Source File: BlockGrass.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) {
        item.count--;
        ObjectTallGrass.growGrass(this.getLevel(), this, new NukkitRandom(), 15, 10);
        return true;
    } else if (item.isHoe()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockFarmland());
        return true;
    } else if (item.isShovel()) {
        item.useOn(this);
        this.getLevel().setBlock(this, new BlockGrassPath());
        return true;
    }

    return false;
}
 
Example 4
Source File: BlockCocoa.java    From Jupiter with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        Block block = this.clone();
        if (this.meta / 4 < 2) {
            block.meta += 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 5
Source File: BaseInventory.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean contains(Item item) {
    int count = Math.max(1, item.getCount());
    boolean checkDamage = item.hasMeta() && item.getDamage() >= 0;
    boolean checkTag = item.getCompoundTag() != null;
    for (Item i : this.getContents().values()) {
        if (item.equals(i, checkDamage, checkTag)) {
            count -= i.getCount();
            if (count <= 0) {
                return true;
            }
        }
    }

    return false;
}
 
Example 6
Source File: BlockTallGrass.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) {
        Block up = this.up();

        if (up.getId() == AIR) {
            int meta;

            switch (this.getDamage()) {
                case 0:
                case 1:
                    meta = BlockDoublePlant.TALL_GRASS;
                    break;
                case 2:
                case 3:
                    meta = BlockDoublePlant.LARGE_FERN;
                    break;
                default:
                    meta = -1;
            }

            if (meta != -1) {
                if (player != null && (player.gamemode & 0x01) == 0) {
                    item.count--;
                }

                this.level.addParticle(new BoneMealParticle(this));
                this.level.setBlock(this, get(DOUBLE_PLANT, meta), true, false);
                this.level.setBlock(up, get(DOUBLE_PLANT, meta ^ BlockDoublePlant.TOP_HALF_BITMASK), true);
            }
        }

        return true;
    }

    return false;
}
 
Example 7
Source File: BinaryStream.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void putSlot(Item item) {
    if (item == null || item.getId() == 0) {
        this.putVarInt(0);
        return;
    }

    this.putVarInt(item.getId());
    int auxValue = (((item.hasMeta() ? item.getDamage() : -1) & 0x7fff) << 8) | item.getCount();
    this.putVarInt(auxValue);
    byte[] nbt = item.getCompoundTag();
    this.putLShort(nbt.length);
    this.put(nbt);
    this.putVarInt(0); //TODO CanPlaceOn entry count
    this.putVarInt(0); //TODO CanDestroy entry count
}
 
Example 8
Source File: BlockCrops.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: NukkitPlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getBlockInHand() throws WorldEditException {
    PlayerInventory inv = player.getInventory();
    Item itemStack = inv.getItemInHand();
    if (itemStack == null) {
        return EditSession.nullBlock;
    }
    return new BaseBlock(itemStack.getId(), itemStack.getMaxDurability() != 0 ? 0 : itemStack.getDamage());
}
 
Example 10
Source File: BinaryStream.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void putSlot(Item item) {
    if (item == null || item.getId() == 0) {
        this.putVarInt(0);
        return;
    }

    this.putVarInt(item.getId());
    int auxValue = (((item.hasMeta() ? item.getDamage() : -1) & 0x7fff) << 8) | item.getCount();
    this.putVarInt(auxValue);
    byte[] nbt = item.getCompoundTag();
    this.putLShort(nbt.length);
    this.put(nbt);
    this.putVarInt(0); //TODO CanPlaceOn entry count
    this.putVarInt(0); //TODO CanDestroy entry count
}
 
Example 11
Source File: BlockFlowerPot.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = getLevel().getBlockEntity(this);
    if (!(blockEntity instanceof BlockEntityFlowerPot)) return false;
    if (blockEntity.namedTag.getShort("item") != 0 || blockEntity.namedTag.getInt("mData") != 0) return false;
    int itemID;
    int itemMeta;
    if (!canPlaceIntoFlowerPot(item.getId())) {
        if (!canPlaceIntoFlowerPot(item.getBlock().getId())) {
            return true;
        }
        itemID = item.getBlock().getId();
        itemMeta = item.getDamage();
    } else {
        itemID = item.getId();
        itemMeta = item.getDamage();
    }
    blockEntity.namedTag.putShort("item", itemID);
    blockEntity.namedTag.putInt("data", itemMeta);

    this.setDamage(1);
    this.getLevel().setBlock(this, this, true);
    ((BlockEntityFlowerPot) blockEntity).spawnToAll();

    if (player.isSurvival()) {
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item.getCount() > 0 ? item : Item.get(Item.AIR));
    }
    return true;
}
 
Example 12
Source File: BlockFlower.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0f) { //Bone meal
        if (player != null && (player.gamemode & 0x01) == 0) {
            item.count--;
        }

        this.level.addParticle(new BoneMealParticle(this));

        for (int i = 0; i < 8; i++) {
            Vector3 vec = this.add(
                    ThreadLocalRandom.current().nextInt(-3, 4),
                    ThreadLocalRandom.current().nextInt(-1, 2),
                    ThreadLocalRandom.current().nextInt(-3, 4));

            if (level.getBlock(vec).getId() == AIR && level.getBlock(vec.down()).getId() == GRASS && vec.getY() >= 0 && vec.getY() < 256) {
                if (ThreadLocalRandom.current().nextInt(10) == 0) {
                    this.level.setBlock(vec, this.getUncommonFlower(), true);
                } else {
                    this.level.setBlock(vec, get(this.getId()), true);
                }
            }
        }

        return true;
    }

    return false;
}
 
Example 13
Source File: BlockMushroomBrown.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == DyeColor.WHITE.getDyeData()) {
        if (ThreadLocalRandom.current().nextFloat() < 0.4) {
            this.grow();
        }

        this.level.addParticle(new BoneMealParticle(this));
        return true;
    }
    return false;
}
 
Example 14
Source File: BlockEntityFurnace.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
protected void checkFuel(Item fuel) {

        FurnaceBurnEvent ev = new FurnaceBurnEvent(this, fuel, fuel.getFuelTime() == null ? 0 : fuel.getFuelTime());

        if (ev.isCancelled()) {
            return;
        }

        maxTime = ev.getBurnTime();
        burnTime = ev.getBurnTime();
        burnDuration = 0;
        if (this.getBlock().getId() == Item.FURNACE) {
            this.getLevel().setBlock(this, new BlockFurnaceBurning(this.getBlock().getDamage()), true);
        }

        if (burnTime > 0 && ev.isBurning()) {
            fuel.setCount(fuel.getCount() - 1);
            if (fuel.getCount() == 0) {
                if (fuel.getId() == Item.BUCKET && fuel.getDamage() == 10) {
                    fuel.setDamage(0);
                    fuel.setCount(1);
                } else {
                    fuel = new ItemBlock(new BlockAir(), 0, 0);
                }
            }
            this.inventory.setFuel(fuel);
        }
    }
 
Example 15
Source File: SlotEntityData.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public SlotEntityData(int id, Item item) {
    this(id, item.getId(), (byte) (item.hasMeta() ? item.getDamage() : 0), item.getCount());
}
 
Example 16
Source File: SlotEntityData.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public SlotEntityData(int id, Item item) {
    this(id, item.getId(), (byte) (item.hasMeta() ? item.getDamage() : 0), item.getCount());
}
 
Example 17
Source File: BlockSapling.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
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 (ThreadLocalRandom.current().nextFloat() >= 0.45) {
            return true;
        }

        BasicGenerator generator = null;
        boolean bigTree = false;

        int x = 0;
        int z = 0;

        switch (this.getDamage()) {
            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 + ThreadLocalRandom.current().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.getDamage() & 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;
    }
    return false;
}
 
Example 18
Source File: BlockSapling.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: ItemBreakParticle.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public ItemBreakParticle(Vector3 pos, Item item) {
    super(pos, Particle.TYPE_ITEM_BREAK, (item.getId() << 16) | item.getDamage());
}
 
Example 20
Source File: SlotEntityData.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setData(Item data) {
    this.blockId = data.getId();
    this.meta = (data.hasMeta() ? data.getDamage() : 0);
    this.count = data.getCount();
}