Java Code Examples for cn.nukkit.item.Item#DYE

The following examples show how to use cn.nukkit.item.Item#DYE . 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: 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 2
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 3
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 4
Source File: BlockMushroom.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() == DyeColor.WHITE.getDyeData()) {
        if (player != null && (player.gamemode & 0x01) == 0) {
            item.count--;
        }

        if (ThreadLocalRandom.current().nextFloat() < 0.4) {
            this.grow();
        }

        this.level.addParticle(new BoneMealParticle(this));
        return true;
    }
    return false;
}
 
Example 5
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 6
Source File: BlockSapling.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) { //BoneMeal
        if (player != null && (player.gamemode & 0x01) == 0) {
            item.count--;
        }

        this.level.addParticle(new BoneMealParticle(this));
        if (ThreadLocalRandom.current().nextFloat() >= 0.45) {
            return true;
        }

        this.grow();

        return true;
    }
    return false;
}
 
Example 7
Source File: BlockGrass.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) {
        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 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: BlockSugarcane.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) { //Bonemeal
        int count = 1;

        for (int i = 1; i <= 2; i++) {
            int id = this.level.getBlockIdAt(this.getFloorX(), this.getFloorY() - i, this.getFloorZ());

            if (id == SUGARCANE_BLOCK) {
                count++;
            }
        }

        if (count < 3) {
            int toGrow = 3 - count;

            for (int i = 1; i <= toGrow; i++) {
                Block block = this.up(i);
                if (block.getId() == 0) {
                    BlockGrowEvent ev = new BlockGrowEvent(block, new BlockSugarcane());
                    Server.getInstance().getPluginManager().callEvent(ev);

                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(block, ev.getNewState(), true);
                    }
                } else if (block.getId() != SUGARCANE_BLOCK) {
                    break;
                }
            }
        }

        if ((player.gamemode & 0x01) == 0) {
            item.count--;
        }
        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        return true;
    }
    return false;
}
 
Example 10
Source File: EntitySheep.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInteract(Player player, Item item) {
    if (item.getId() == Item.DYE) {
        this.setColor(((ItemDye) item).getDyeColor().getWoolData());
        return true;
    }

    return item.getId() == Item.SHEARS && shear();
}
 
Example 11
Source File: BlockMushroomRed.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 12
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 13
Source File: EntitySheep.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onInteract(Player player, Item item) {
    if (item.getId() == Item.DYE) {
        this.setColor(((ItemDye) item).getDyeColor().getDyedData());
        return true;
    }

    return item.getId() == Item.SHEARS && shear();
}
 
Example 14
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 15
Source File: BlockMushroomBrown.java    From Jupiter 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 (this.level.rand.nextFloat() < 0.4) {
            this.grow();
        }

        this.level.addParticle(new BoneMealParticle(this));
        return true;
    }
    return false;
}
 
Example 16
Source File: BlockMushroomRed.java    From Jupiter 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 (this.level.rand.nextFloat() < 0.4) {
            this.grow();
        }

        this.level.addParticle(new BoneMealParticle(this));
        return true;
    }
    return false;
}
 
Example 17
Source File: BlockSugarcane.java    From Jupiter 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) { //Bonemeal
        int count = 1;

        for (int i = 1; i <= 2; i++) {
            int id = this.level.getBlockIdAt(this.getFloorX(), this.getFloorY() - i, this.getFloorZ());

            if (id == SUGARCANE_BLOCK) {
                count++;
            }
        }

        if (count < 3) {
            int toGrow = 3 - count;

            for (int i = 1; i <= toGrow; i++) {
                Block block = this.up(i);
                if (block.getId() == 0) {
                    BlockGrowEvent ev = new BlockGrowEvent(block, new BlockSugarcane());
                    Server.getInstance().getPluginManager().callEvent(ev);

                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(block, ev.getNewState(), true);
                    }
                } else if (block.getId() != SUGARCANE_BLOCK) {
                    break;
                }
            }
        }

        if ((player.gamemode & 0x01) == 0) {
            item.count--;
        }
        this.level.addParticle(new BoneMealParticle(this.add(0.5, 0.5, 0.5)));
        return true;
    }
    return false;
}
 
Example 18
Source File: BlockSugarcane.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onActivate(Item item, Player player) {
    if (item.getId() == Item.DYE && item.getDamage() == 0x0F) { //Bonemeal
        int count = 1;

        for (int i = 1; i <= 2; i++) {
            int id = this.level.getBlockIdAt(this.getFloorX(), this.getFloorY() - i, this.getFloorZ());

            if (id == SUGARCANE_BLOCK) {
                count++;
            }
        }

        if (count < 3) {
            boolean success = false;
            int toGrow = 3 - count;

            for (int i = 1; i <= toGrow; i++) {
                Block block = this.up(i);
                if (block.getId() == 0) {
                    BlockGrowEvent ev = new BlockGrowEvent(block, Block.get(BlockID.SUGARCANE_BLOCK));
                    Server.getInstance().getPluginManager().callEvent(ev);

                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(block, ev.getNewState(), true);
                        success = true;
                    }
                } else if (block.getId() != SUGARCANE_BLOCK) {
                    break;
                }
            }

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

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

        return true;
    }
    return false;
}
 
Example 19
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 20
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;
}