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