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;
}
}
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;
}
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;
}
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);
}
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);
}
Aggregations