Java Code Examples for cn.nukkit.block.Block#TALL_GRASS
The following examples show how to use
cn.nukkit.block.Block#TALL_GRASS .
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: ObjectTallGrass.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) { int[][] arr = { {Block.DANDELION, 0}, {Block.POPPY, 0}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1} }; int arrC = arr.length - 1; for (int c = 0; c < count; c++) { int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius)); int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius)); if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) { int[] t = arr[random.nextRange(0, arrC)]; level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]); level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]); } } }
Example 2
Source File: ObjectTallGrass.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public static void growGrass(ChunkManager level, Vector3 pos, NukkitRandom random, int count, int radius) { int[][] arr = { {Block.DANDELION, 0}, {Block.POPPY, 0}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1}, {Block.TALL_GRASS, 1} }; int arrC = arr.length - 1; for (int c = 0; c < count; c++) { int x = random.nextRange((int) (pos.x - radius), (int) (pos.x + radius)); int z = random.nextRange((int) (pos.z) - radius, (int) (pos.z + radius)); if (level.getBlockIdAt(x, (int) (pos.y + 1), z) == Block.AIR && level.getBlockIdAt(x, (int) (pos.y), z) == Block.GRASS) { int[] t = arr[random.nextRange(0, arrC)]; level.setBlockIdAt(x, (int) (pos.y + 1), z, t[0]); level.setBlockDataAt(x, (int) (pos.y + 1), z, t[1]); } } }
Example 3
Source File: EntityLightning.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override protected void initEntity() { super.initEntity(); this.setHealth(4); this.setMaxHealth(4); this.state = 2; this.liveTime = this.level.rand.nextInt(3) + 1; if (isEffect && this.level.gameRules.getBoolean("dofiretick") && (this.server.getDifficulty() >= 2)) { Block block = this.getLevelBlock(); if (block.getId() == 0 || block.getId() == Block.TALL_GRASS) { BlockFire fire = new BlockFire(); fire.x = block.x; fire.y = block.y; fire.z = block.z; fire.level = level; this.getLevel().setBlock(fire, fire, true); if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { level.setBlock(fire, fire, true); level.scheduleUpdate(fire, fire.tickRate() + level.rand.nextInt(10)); } } } } }
Example 4
Source File: EntityLightning.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override protected void initEntity() { super.initEntity(); this.setHealth(4); this.setMaxHealth(4); this.state = 2; this.liveTime = ThreadLocalRandom.current().nextInt(3) + 1; if (isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK) && (this.server.getDifficulty() >= 2)) { Block block = this.getLevelBlock(); if (block.getId() == 0 || block.getId() == Block.TALL_GRASS) { BlockFire fire = (BlockFire) Block.get(BlockID.FIRE); fire.x = block.x; fire.y = block.y; fire.z = block.z; fire.level = level; this.getLevel().setBlock(fire, fire, true); if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { level.setBlock(fire, fire, true); level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10)); } } } } }
Example 5
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void performThunder(long index, FullChunk chunk) { if (areNeighboringChunksLoaded(index)) return; if (ThreadLocalRandom.current().nextInt(10000) == 0) { int LCG = this.getUpdateLCG() >> 2; int chunkX = chunk.getX() * 16; int chunkZ = chunk.getZ() * 16; Vector3 vector = this.adjustPosToNearbyEntity(new Vector3(chunkX + (LCG & 0xf), 0, chunkZ + (LCG >> 8 & 0xf))); Biome biome = Biome.getBiome(this.getBiomeId(vector.getFloorX(), vector.getFloorZ())); if (!biome.canRain()) { return; } int bId = this.getBlockIdAt(vector.getFloorX(), vector.getFloorY(), vector.getFloorZ()); if (bId != Block.TALL_GRASS && bId != Block.WATER) vector.y += 1; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", vector.x)) .add(new DoubleTag("", vector.y)).add(new DoubleTag("", vector.z))) .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)).add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)) .add(new FloatTag("", 0))); EntityLightning bolt = (EntityLightning) Entity.createEntity("Lightning", chunk, nbt); if(bolt == null) return; LightningStrikeEvent ev = new LightningStrikeEvent(this, bolt); getServer().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { bolt.spawnToAll(); } else { bolt.setEffect(false); } this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_THUNDER, -1, EntityLightning.NETWORK_ID); this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_EXPLODE, -1, EntityLightning.NETWORK_ID); } }
Example 6
Source File: EntityLightning.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override protected void initEntity() { super.initEntity(); this.setHealth(4); this.setMaxHealth(4); this.state = 2; this.liveTime = ThreadLocalRandom.current().nextInt(3) + 1; if (isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK) && (this.server.getDifficulty() >= 2)) { Block block = this.getLevelBlock(); if (block.getId() == 0 || block.getId() == Block.TALL_GRASS) { BlockFire fire = new BlockFire(); fire.x = block.x; fire.y = block.y; fire.z = block.z; fire.level = level; this.getLevel().setBlock(fire, fire, true); if (fire.isBlockTopFacingSurfaceSolid(fire.down()) || fire.canNeighborBurn()) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { level.setBlock(fire, fire, true); level.scheduleUpdate(fire, fire.tickRate() + ThreadLocalRandom.current().nextInt(10)); } } } } }
Example 7
Source File: Level.java From Nukkit with GNU General Public License v3.0 | 5 votes |
private void performThunder(long index, FullChunk chunk) { if (areNeighboringChunksLoaded(index)) return; if (ThreadLocalRandom.current().nextInt(10000) == 0) { this.updateLCG = this.updateLCG * 3 + 1013904223; int LCG = this.updateLCG >> 2; int chunkX = chunk.getX() * 16; int chunkZ = chunk.getZ() * 16; Vector3 vector = this.adjustPosToNearbyEntity(new Vector3(chunkX + (LCG & 15), 0, chunkZ + (LCG >> 8 & 15))); int bId = this.getBlockIdAt(vector.getFloorX(), vector.getFloorY(), vector.getFloorZ()); if (bId != Block.TALL_GRASS && bId != Block.WATER) vector.y += 1; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", vector.x)) .add(new DoubleTag("", vector.y)).add(new DoubleTag("", vector.z))) .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)).add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0)) .add(new FloatTag("", 0))); EntityLightning bolt = new EntityLightning(chunk, nbt); LightningStrikeEvent ev = new LightningStrikeEvent(this, bolt); getServer().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { bolt.spawnToAll(); } else { bolt.setEffect(false); } this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_THUNDER, 93, -1, false); this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1, false); } }
Example 8
Source File: EntityLightning.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; this.entityBaseTick(tickDiff); if (this.state == 2) { this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_THUNDER, 93, -1, this); this.level.addLevelSoundEvent(LevelSoundEventPacket.SOUND_EXPLODE, 93, -1, this); } this.state--; if (this.state < 0) { if (this.liveTime == 0) { this.close(); return false; } else if (this.state < -this.level.rand.nextInt(10)) { this.liveTime--; this.state = 1; if (this.isEffect && this.level.gameRules.getBoolean("dofiretick")) { Block block = this.getLevelBlock(); if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { Block fire = new BlockFire(); this.level.setBlock(block, fire); this.getLevel().scheduleUpdate(fire, fire.tickRate()); } } } } } if (this.state >= 0) { if (this.isEffect) { AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3); bb.maxX += 6; for (Entity entity : this.level.getCollidingEntities(bb, this)) { entity.onStruckByLightning(this); } } } return true; }
Example 9
Source File: EntityLightning.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; this.entityBaseTick(tickDiff); if (this.state == 2) { this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER); this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE); } this.state--; if (this.state < 0) { if (this.liveTime == 0) { this.close(); return false; } else if (this.state < -ThreadLocalRandom.current().nextInt(10)) { this.liveTime--; this.state = 1; if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) { Block block = this.getLevelBlock(); if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { Block fire = Block.get(BlockID.FIRE); this.level.setBlock(block, fire); this.getLevel().scheduleUpdate(fire, fire.tickRate()); } } } } } if (this.state >= 0) { if (this.isEffect) { AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3); bb.setMaxX(bb.getMaxX() + 6); for (Entity entity : this.level.getCollidingEntities(bb, this)) { entity.onStruckByLightning(this); } } } return true; }
Example 10
Source File: EntityLightning.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onUpdate(int currentTick) { if (this.closed) { return false; } int tickDiff = currentTick - this.lastUpdate; if (tickDiff <= 0 && !this.justCreated) { return true; } this.lastUpdate = currentTick; this.entityBaseTick(tickDiff); if (this.state == 2) { this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER, 93, -1); this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1); } this.state--; if (this.state < 0) { if (this.liveTime == 0) { this.close(); return false; } else if (this.state < -ThreadLocalRandom.current().nextInt(10)) { this.liveTime--; this.state = 1; if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) { Block block = this.getLevelBlock(); if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) { BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING); getServer().getPluginManager().callEvent(e); if (!e.isCancelled()) { Block fire = new BlockFire(); this.level.setBlock(block, fire); this.getLevel().scheduleUpdate(fire, fire.tickRate()); } } } } } if (this.state >= 0) { if (this.isEffect) { AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3); bb.setMaxX(bb.getMaxX() + 6); for (Entity entity : this.level.getCollidingEntities(bb, this)) { entity.onStruckByLightning(this); } } } return true; }