Search in sources :

Example 6 with NukkitRandom

use of cn.nukkit.math.NukkitRandom in project Nukkit by Nukkit.

the class BlockMushroomRed method grow.

public boolean grow() {
    this.level.setBlock(this, new BlockAir(), true, false);
    BigMushroom generator = new BigMushroom(1);
    if (generator.generate(this.level, new NukkitRandom(), this)) {
        return true;
    } else {
        this.level.setBlock(this, this, true, false);
        return false;
    }
}
Also used : BigMushroom(cn.nukkit.level.generator.object.mushroom.BigMushroom) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 7 with NukkitRandom

use of cn.nukkit.math.NukkitRandom in project Nukkit by Nukkit.

the class BlockGrass method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        Block block = this.getLevel().getBlock(new Vector3(this.x, this.y, this.z));
        if (block.up().getLightLevel() < 4) {
            BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockDirt());
            Server.getInstance().getPluginManager().callEvent(ev);
        } else if (block.up().getLightLevel() >= 9) {
            for (int l = 0; l < 4; ++l) {
                NukkitRandom random = new NukkitRandom();
                int x = random.nextRange((int) this.x - 1, (int) this.x + 1);
                int y = random.nextRange((int) this.y - 2, (int) this.y + 2);
                int z = random.nextRange((int) this.z - 1, (int) this.z + 1);
                Block blocks = this.getLevel().getBlock(new Vector3(x, y, z));
                if (blocks.getId() == Block.DIRT && blocks.getDamage() == 0x0F && blocks.up().getLightLevel() >= 4 && blocks.z <= 2) {
                    BlockSpreadEvent ev = new BlockSpreadEvent(blocks, this, new BlockGrass());
                    Server.getInstance().getPluginManager().callEvent(ev);
                    if (!ev.isCancelled()) {
                        this.getLevel().setBlock(blocks, ev.getNewState());
                    }
                }
            }
        }
    }
    return 0;
}
Also used : BlockSpreadEvent(cn.nukkit.event.block.BlockSpreadEvent) Vector3(cn.nukkit.math.Vector3) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 8 with NukkitRandom

use of cn.nukkit.math.NukkitRandom in project Nukkit by Nukkit.

the class BlockGrass method onActivate.

@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;
}
Also used : NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 9 with NukkitRandom

use of cn.nukkit.math.NukkitRandom in project Nukkit by Nukkit.

the class EntityExpBottle method onUpdate.

@Override
public boolean onUpdate(int currentTick) {
    if (this.closed) {
        return false;
    }
    this.timing.startTiming();
    int tickDiff = currentTick - this.lastUpdate;
    boolean hasUpdate = super.onUpdate(currentTick);
    if (this.age > 1200) {
        this.kill();
        hasUpdate = true;
    }
    if (this.isCollided) {
        this.kill();
        Particle particle1 = new EnchantParticle(this);
        this.getLevel().addParticle(particle1);
        Particle particle2 = new SpellParticle(this, 0x00385dc6);
        this.getLevel().addParticle(particle2);
        hasUpdate = true;
        NukkitRandom random = new NukkitRandom();
        int add = 1;
        for (int ii = 1; ii <= random.nextRange(3, 11); ii += add) {
            getLevel().dropExpOrb(this, add);
            add = random.nextRange(1, 3);
        }
    }
    this.timing.stopTiming();
    return hasUpdate;
}
Also used : EnchantParticle(cn.nukkit.level.particle.EnchantParticle) SpellParticle(cn.nukkit.level.particle.SpellParticle) Particle(cn.nukkit.level.particle.Particle) SpellParticle(cn.nukkit.level.particle.SpellParticle) EnchantParticle(cn.nukkit.level.particle.EnchantParticle) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 10 with NukkitRandom

use of cn.nukkit.math.NukkitRandom in project Nukkit by Nukkit.

the class GeneratorRegisterTask method onRun.

@Override
public void onRun() {
    Block.init();
    Biome.init();
    SimpleChunkManager manager = new SimpleChunkManager(this.seed);
    try {
        Generator generator = this.generator.getConstructor(Map.class).newInstance(this.settings);
        generator.init(manager, new NukkitRandom(manager.getSeed()));
        GeneratorPool.put(this.levelId, generator);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : SimpleChunkManager(cn.nukkit.level.SimpleChunkManager) Map(java.util.Map) NukkitRandom(cn.nukkit.math.NukkitRandom) Generator(cn.nukkit.level.generator.Generator)

Aggregations

NukkitRandom (cn.nukkit.math.NukkitRandom)13 BlockSpreadEvent (cn.nukkit.event.block.BlockSpreadEvent)2 Simplex (cn.nukkit.level.generator.noise.Simplex)2 BigMushroom (cn.nukkit.level.generator.object.mushroom.BigMushroom)2 OreType (cn.nukkit.level.generator.object.ore.OreType)2 Vector3 (cn.nukkit.math.Vector3)2 Random (java.util.Random)2 Entity (cn.nukkit.entity.Entity)1 EntityPrimedTNT (cn.nukkit.entity.item.EntityPrimedTNT)1 ItemBlock (cn.nukkit.item.ItemBlock)1 SimpleChunkManager (cn.nukkit.level.SimpleChunkManager)1 Generator (cn.nukkit.level.generator.Generator)1 BiomeSelector (cn.nukkit.level.generator.biome.BiomeSelector)1 BasicGenerator (cn.nukkit.level.generator.object.BasicGenerator)1 BoneMealParticle (cn.nukkit.level.particle.BoneMealParticle)1 EnchantParticle (cn.nukkit.level.particle.EnchantParticle)1 Particle (cn.nukkit.level.particle.Particle)1 SpellParticle (cn.nukkit.level.particle.SpellParticle)1 CompoundTag (cn.nukkit.nbt.tag.CompoundTag)1 DoubleTag (cn.nukkit.nbt.tag.DoubleTag)1