Java Code Examples for cn.nukkit.level.Level#getChunk()
The following examples show how to use
cn.nukkit.level.Level#getChunk() .
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: PopulationTask.java From Nukkit with GNU General Public License v3.0 | 6 votes |
public PopulationTask(Level level, BaseFullChunk chunk) { this.state = true; this.level = level; this.centerChunk = chunk; this.seed = level.getSeed(); chunks[4] = chunk; int i = 0; for (int z = -1; z <= 1; z++) { for (int x = -1; x <= 1; x++, i++) { if (i == 4) continue; BaseFullChunk ck = level.getChunk(chunk.getX() + x, chunk.getZ() + z, true); this.chunks[i] = ck; } } }
Example 2
Source File: ItemEndCrystal.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (!(target instanceof BlockBedrock) && !(target instanceof BlockObsidian)) return false; FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity("EndCrystal", chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 3
Source File: ItemMinecart.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartEmpty minecart = new EntityMinecartEmpty( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 4
Source File: ItemMinecartChest.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartChest minecart = new EntityMinecartChest( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 5
Source File: ItemBoat.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (face != BlockFace.UP) return false; EntityBoat boat = new EntityBoat( level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY() - 0.0625)) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", (float) ((player.yaw + 90f) % 360))) .add(new FloatTag("", 0))) .putByte("woodID", this.getDamage()) ); if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } boat.spawnToAll(); return true; }
Example 6
Source File: ItemSpawnEgg.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 7
Source File: ItemMinecartHopper.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartHopper minecart = new EntityMinecartHopper( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 8
Source File: ItemMinecartTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartTNT minecart = new EntityMinecartTNT( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 9
Source File: ItemMinecartTNT.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartTNT minecart = new EntityMinecartTNT( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 10
Source File: PopulationTask.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public PopulationTask(Level level, BaseFullChunk chunk) { this.state = true; this.levelId = level.getId(); this.chunk = chunk; for (int i = 0; i < 9; i++) { if (i == 4) { continue; } int xx = -1 + i % 3; int zz = -1 + (i / 3); BaseFullChunk ck = level.getChunk(chunk.getX() + xx, chunk.getZ() + zz, false); this.chunks[i] = ck; } }
Example 11
Source File: ItemMinecart.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartEmpty minecart = new EntityMinecartEmpty( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 12
Source File: ItemMinecartChest.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (Rail.isRailBlock(target)) { Rail.Orientation type = ((BlockRail) target).getOrientation(); double adjacent = 0.0D; if (type.isAscending()) { adjacent = 0.5D; } EntityMinecartChest minecart = new EntityMinecartChest( level.getChunk(target.getFloorX() >> 4, target.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<>("Pos") .add(new DoubleTag("", target.getX() + 0.5)) .add(new DoubleTag("", target.getY() + 0.0625D + adjacent)) .add(new DoubleTag("", target.getZ() + 0.5))) .putList(new ListTag<>("Motion") .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) ); minecart.spawnToAll(); count -= 1; return true; } return false; }
Example 13
Source File: ItemBoat.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (face != BlockFace.UP) return false; EntityBoat boat = new EntityBoat( level.getChunk(block.getFloorX() >> 4, block.getFloorZ() >> 4), new CompoundTag("") .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY() - 0.0625)) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", (float) ((player.yaw + 90f) % 360))) .add(new FloatTag("", 0))) .putByte("woodID", this.getDamage()) ); if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } boat.spawnToAll(); return true; }
Example 14
Source File: ItemSpawnEgg.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 15
Source File: PopulationTask.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public PopulationTask(Level level, BaseFullChunk chunk) { this.state = true; this.levelId = level.getId(); this.chunk = chunk; int i = 0; for (int z = -1; z <= 1; z++) { for (int x = -1; x <= 1; x++, i++) { if (i == 4) continue; BaseFullChunk ck = level.getChunk(chunk.getX() + x, chunk.getZ() + z, false); this.chunks[i] = ck; } } }
Example 16
Source File: ItemArmorStand.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", block.getY())) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", this.getDirection(player.yaw))) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } Entity entity = Entity.createEntity("ArmorStand", chunk, nbt); if (entity != null) { if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 17
Source File: ItemSpawnEgg.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", block.getX() + 0.5)) .add(new DoubleTag("", target.getBoundingBox() == null ? block.getY() : target.getBoundingBox().getMaxY() + 0.0001f)) .add(new DoubleTag("", block.getZ() + 0.5))) .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("", new Random().nextFloat() * 360)) .add(new FloatTag("", 0))); if (this.hasCustomName()) { nbt.putString("CustomName", this.getCustomName()); } CreatureSpawnEvent ev = new CreatureSpawnEvent(this.meta, block, nbt, SpawnReason.SPAWN_EGG); level.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } Entity entity = Entity.createEntity(this.meta, chunk, nbt); if (entity != null) { if (player.isSurvival()) { player.getInventory().decreaseCount(player.getInventory().getHeldItemIndex()); } entity.spawnToAll(); return true; } return false; }
Example 18
Source File: NukkitQueue.java From FastAsyncWorldedit with GNU General Public License v3.0 | 4 votes |
@Override public BaseFullChunk loadChunk(Level level, int x, int z, boolean generate) { return level.getChunk(x, z, generate); }
Example 19
Source File: ItemPainting.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) { int[] direction = {2, 0, 1, 3}; int[] right = {4, 5, 3, 2}; List<EntityPainting.Motive> validMotives = new ArrayList<>(); for (EntityPainting.Motive motive : EntityPainting.motives) { boolean valid = true; for (int x = 0; x < motive.width && valid; x++) { for (int z = 0; z < motive.height && valid; z++) { if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() || target.up(z).isTransparent() || block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() || block.up(z).isSolid()) { valid = false; } } } if (valid) { validMotives.add(motive); } } CompoundTag nbt = new CompoundTag() .putByte("Direction", direction[face.getIndex() - 2]) .putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title) .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("0", target.x)) .add(new DoubleTag("1", target.y)) .add(new DoubleTag("2", target.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("0", 0)) .add(new DoubleTag("1", 0)) .add(new DoubleTag("2", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("0", direction[face.getIndex() - 2] * 90)) .add(new FloatTag("1", 0))); EntityPainting entity = new EntityPainting(chunk, nbt); if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }
Example 20
Source File: ItemPainting.java From Jupiter with GNU General Public License v3.0 | 4 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { FullChunk chunk = level.getChunk((int) block.getX() >> 4, (int) block.getZ() >> 4); if (chunk == null) { return false; } if (!target.isTransparent() && face.getIndex() > 1 && !block.isSolid()) { int[] direction = {2, 0, 1, 3}; int[] right = {4, 5, 3, 2}; List<EntityPainting.Motive> validMotives = new ArrayList<>(); for (EntityPainting.Motive motive : EntityPainting.motives) { boolean valid = true; for (int x = 0; x < motive.width && valid; x++) { for (int z = 0; z < motive.height && valid; z++) { if (target.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isTransparent() || target.up(z).isTransparent() || block.getSide(BlockFace.fromIndex(right[face.getIndex() - 2]), x).isSolid() || block.up(z).isSolid()) { valid = false; } } } if (valid) { validMotives.add(motive); } } CompoundTag nbt = new CompoundTag() .putByte("Direction", direction[face.getIndex() - 2]) .putString("Motive", validMotives.get(ThreadLocalRandom.current().nextInt(validMotives.size())).title) .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("0", target.x)) .add(new DoubleTag("1", target.y)) .add(new DoubleTag("2", target.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("0", 0)) .add(new DoubleTag("1", 0)) .add(new DoubleTag("2", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("0", direction[face.getIndex() - 2] * 90)) .add(new FloatTag("1", 0))); EntityPainting entity = new EntityPainting(chunk, nbt); if (player.isSurvival()) { Item item = player.getInventory().getItemInHand(); item.setCount(item.getCount() - 1); player.getInventory().setItemInHand(item); } entity.spawnToAll(); return true; } return false; }