Search in sources :

Example 1 with NukkitRandom

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

the class BlockMushroomBrown method grow.

public boolean grow() {
    this.level.setBlock(this, new BlockAir(), true, false);
    BigMushroom generator = new BigMushroom(0);
    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 2 with NukkitRandom

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

the class BlockMycelium method onUpdate.

@Override
public int onUpdate(int type) {
    if (type == Level.BLOCK_UPDATE_RANDOM) {
        // TODO: light levels
        NukkitRandom random = new NukkitRandom();
        x = random.nextRange((int) x - 1, (int) x + 1);
        y = random.nextRange((int) y - 1, (int) y + 1);
        z = random.nextRange((int) z - 1, (int) z + 1);
        Block block = this.getLevel().getBlock(new Vector3(x, y, z));
        if (block.getId() == Block.DIRT) {
            if (block.up().isTransparent()) {
                BlockSpreadEvent ev = new BlockSpreadEvent(block, this, new BlockMycelium());
                Server.getInstance().getPluginManager().callEvent(ev);
                if (!ev.isCancelled()) {
                    this.getLevel().setBlock(block, ev.getNewState());
                }
            }
        }
    }
    return 0;
}
Also used : BlockSpreadEvent(cn.nukkit.event.block.BlockSpreadEvent) ItemBlock(cn.nukkit.item.ItemBlock) Vector3(cn.nukkit.math.Vector3) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 3 with NukkitRandom

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

the class BlockSapling method onActivate.

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;
}
Also used : BoneMealParticle(cn.nukkit.level.particle.BoneMealParticle) BasicGenerator(cn.nukkit.level.generator.object.BasicGenerator) NukkitRandom(cn.nukkit.math.NukkitRandom)

Example 4 with NukkitRandom

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

the class BlockTNT method prime.

public void prime(int fuse) {
    this.getLevel().setBlock(this, new BlockAir(), true);
    double mot = (new NukkitRandom()).nextSignedFloat() * Math.PI * 2;
    CompoundTag nbt = new CompoundTag().putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", this.x + 0.5)).add(new DoubleTag("", this.y)).add(new DoubleTag("", this.z + 0.5))).putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", -Math.sin(mot) * 0.02)).add(new DoubleTag("", 0.2)).add(new DoubleTag("", -Math.cos(mot) * 0.02))).putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)).add(new FloatTag("", 0))).putShort("Fuse", fuse);
    Entity tnt = new EntityPrimedTNT(this.getLevel().getChunk(this.getFloorX() >> 4, this.getFloorZ() >> 4), nbt);
    tnt.spawnToAll();
    this.level.addSound(this, Sound.RANDOM_FUSE);
}
Also used : Entity(cn.nukkit.entity.Entity) FloatTag(cn.nukkit.nbt.tag.FloatTag) EntityPrimedTNT(cn.nukkit.entity.item.EntityPrimedTNT) DoubleTag(cn.nukkit.nbt.tag.DoubleTag) NukkitRandom(cn.nukkit.math.NukkitRandom) ListTag(cn.nukkit.nbt.tag.ListTag) CompoundTag(cn.nukkit.nbt.tag.CompoundTag)

Example 5 with NukkitRandom

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

the class Nether method init.

@Override
public void init(ChunkManager level, NukkitRandom random) {
    this.level = level;
    this.nukkitRandom = random;
    this.random = new Random();
    this.nukkitRandom.setSeed(this.level.getSeed());
    this.noiseBase = new Simplex(this.nukkitRandom, 4, 1 / 4f, 1 / 64f);
    this.nukkitRandom.setSeed(this.level.getSeed());
    this.localSeed1 = this.random.nextLong();
    this.localSeed2 = this.random.nextLong();
    PopulatorOre ores = new PopulatorOre(Block.NETHERRACK);
    ores.setOreTypes(new OreType[] { new OreType(new BlockOreQuartz(), 20, 16, 0, 128), new OreType(new BlockSoulSand(), 5, 64, 0, 128), new OreType(new BlockGravel(), 5, 64, 0, 128), new OreType(new BlockLava(), 1, 16, 0, (int) this.waterHeight) });
    this.populators.add(ores);
    this.populators.add(new PopulatorGlowStone());
    PopulatorGroundFire groundFire = new PopulatorGroundFire();
    groundFire.setBaseAmount(1);
    groundFire.setRandomAmount(1);
    this.populators.add(groundFire);
    PopulatorLava lava = new PopulatorLava();
    lava.setBaseAmount(0);
    lava.setRandomAmount(2);
    this.populators.add(lava);
}
Also used : Simplex(cn.nukkit.level.generator.noise.Simplex) OreType(cn.nukkit.level.generator.object.ore.OreType) NukkitRandom(cn.nukkit.math.NukkitRandom)

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