cn.nukkit.level.Level Java Examples
The following examples show how to use
cn.nukkit.level.Level.
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: ItemGlassBottle.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (target.getId() == WATER || target.getId() == STILL_WATER) { Item potion = new ItemPotion(); if (this.count == 1) { player.getInventory().setItemInHand(potion); } else if (this.count > 1) { this.count--; player.getInventory().setItemInHand(this); if (player.getInventory().canAddItem(potion)) { player.getInventory().addItem(potion); } else { player.getLevel().dropItem(player.add(0, 1.3, 0), potion, player.getDirectionVector().multiply(0.4)); } } } return false; }
Example #2
Source File: BlockNoteblock.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_REDSTONE) { BlockEntityMusic blockEntity = this.getBlockEntity(); if (blockEntity != null) { if (this.getLevel().isBlockPowered(this)) { if (!blockEntity.isPowered()) { this.emitSound(); } blockEntity.setPowered(true); } else { blockEntity.setPowered(false); } } } return super.onUpdate(type); }
Example #3
Source File: Entity.java From Jupiter with GNU General Public License v3.0 | 6 votes |
protected boolean switchLevel(Level targetLevel) { if (this.closed) { return false; } if (this.isValid()) { EntityLevelChangeEvent ev = new EntityLevelChangeEvent(this, this.level, targetLevel); this.server.getPluginManager().callEvent(ev); if (ev.isCancelled()) { return false; } this.level.removeEntity(this); if (this.chunk != null) { this.chunk.removeEntity(this); } this.despawnFromAll(); } this.setLevel(targetLevel); this.level.addEntity(this); this.chunk = null; return true; }
Example #4
Source File: ItemGlassBottle.java From Jupiter with GNU General Public License v3.0 | 6 votes |
@Override public boolean onActivate(Level level, Player player, Block block, Block target, BlockFace face, double fx, double fy, double fz) { if (target.getId() == WATER || target.getId() == STILL_WATER) { Item potion = new ItemPotion(); if (this.count == 1) { player.getInventory().setItemInHand(potion); } else if (this.count > 1) { this.count--; player.getInventory().setItemInHand(this); if (player.getInventory().canAddItem(potion)) { player.getInventory().addItem(potion); } else { player.getLevel().dropItem(player.add(0, 1.3, 0), potion, player.getDirectionVector().multiply(0.4)); } } } return false; }
Example #5
Source File: LevelDB.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean loadChunk(int x, int z, boolean create) { long index = Level.chunkHash(x, z); if (this.chunks.containsKey(index)) { return true; } this.level.timings.syncChunkLoadDataTimer.startTiming(); Chunk chunk = this.readChunk(x, z); if (chunk == null && create) { chunk = Chunk.getEmptyChunk(x, z, this); } this.level.timings.syncChunkLoadDataTimer.stopTiming(); if (chunk != null) { this.chunks.put(index, chunk); return true; } return false; }
Example #6
Source File: BaseLevelProvider.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public BaseLevelProvider(Level level, String path) throws IOException { this.level = level; this.path = path; File file_path = new File(this.path); if (!file_path.exists()) { file_path.mkdirs(); } CompoundTag levelData = NBTIO.readCompressed(new FileInputStream(new File(this.getPath() + "level.dat")), ByteOrder.BIG_ENDIAN); if (levelData.get("Data") instanceof CompoundTag) { this.levelData = levelData.getCompound("Data"); } else { throw new LevelException("Invalid level.dat"); } if (!this.levelData.contains("generatorName")) { this.levelData.putString("generatorName", Generator.getGenerator("DEFAULT").getSimpleName().toLowerCase()); } if (!this.levelData.contains("generatorOptions")) { this.levelData.putString("generatorOptions", ""); } }
Example #7
Source File: BlockRedstoneLampLit.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if ((type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) && !this.level.isBlockPowered(this.getLocation())) { // Redstone event RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this); getLevel().getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return 0; } this.level.scheduleUpdate(this, 4); return 1; } if (type == Level.BLOCK_UPDATE_SCHEDULED && !this.level.isBlockPowered(this.getLocation())) { this.level.setBlock(this, Block.get(BlockID.REDSTONE_LAMP), false, false); } return 0; }
Example #8
Source File: BlockConcretePowder.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { super.onUpdate(Level.BLOCK_UPDATE_NORMAL); for (int side = 1; side <= 5; side++) { Block block = this.getSide(BlockFace.fromIndex(side)); if (block.getId() == Block.WATER || block.getId() == Block.STILL_WATER || block.getId() == Block.LAVA || block.getId() == Block.STILL_LAVA) { this.level.setBlock(this, Block.get(Block.CONCRETE, this.meta), true, true); } } return Level.BLOCK_UPDATE_NORMAL; } return 0; }
Example #9
Source File: LevelDB.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public boolean loadChunk(int x, int z, boolean create) { long index = Level.chunkHash(x, z); if (this.chunks.containsKey(index)) { return true; } this.level.timings.syncChunkLoadDataTimer.startTiming(); Chunk chunk = this.readChunk(x, z); if (chunk == null && create) { chunk = Chunk.getEmptyChunk(x, z, this); } this.level.timings.syncChunkLoadDataTimer.stopTiming(); if (chunk != null) { this.chunks.put(index, chunk); return true; } return false; }
Example #10
Source File: Server.java From Jupiter with GNU General Public License v3.0 | 6 votes |
public void doAutoSave() { if (this.getAutoSave()) { Timings.levelSaveTimer.startTiming(); for (Player player : new ArrayList<>(this.players.values())) { if (player.isOnline()) { player.save(true); } else if (!player.isConnected()) { this.removePlayer(player); } } for (Level level : this.getLevels().values()) { level.save(); } Timings.levelSaveTimer.stopTiming(); } }
Example #11
Source File: BlockLeaves.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_RANDOM && !isPersistent() && !isCheckDecay()) { setCheckDecay(true); getLevel().setBlock(this, this, false, false); } else if (type == Level.BLOCK_UPDATE_RANDOM && isCheckDecay() && !isPersistent()) { setDamage(getDamage() & 0x03); int check = 0; LeavesDecayEvent ev = new LeavesDecayEvent(this); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled() || findLog(this, new LongArraySet(), 0, check)) { getLevel().setBlock(this, this, false, false); } else { getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } } return 0; }
Example #12
Source File: BlockRedstoneTorchUnlit.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (super.onUpdate(type) == 0) { if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) { this.level.scheduleUpdate(this, tickRate()); } else if (type == Level.BLOCK_UPDATE_SCHEDULED) { RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this); getLevel().getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return 0; } if (checkState()) { return 1; } } } return 0; }
Example #13
Source File: BlockRedstoneWire.java From Nukkit with GNU General Public License v3.0 | 6 votes |
@Override public int onUpdate(int type) { if (type != Level.BLOCK_UPDATE_NORMAL && type != Level.BLOCK_UPDATE_REDSTONE) { return 0; } // Redstone event RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this); getLevel().getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { return 0; } if (type == Level.BLOCK_UPDATE_NORMAL && !this.canBePlacedOn(this.getLocation().down())) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } this.updateSurroundingRedstone(false); return Level.BLOCK_UPDATE_NORMAL; }
Example #14
Source File: LevelDB.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public Chunk getChunk(int x, int z, boolean create) { long index = Level.chunkHash(x, z); if (this.chunks.containsKey(index)) { return this.chunks.get(index); } else { this.loadChunk(x, z, create); return this.chunks.containsKey(index) ? this.chunks.get(index) : null; } }
Example #15
Source File: BlockHopper.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { boolean powered = this.level.isBlockPowered(this); if (powered == this.isEnabled()) { this.setEnabled(!powered); this.level.setBlock(this, this, true, false); } return type; } return 0; }
Example #16
Source File: BlockFallable.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { Block down = this.down(); if (down.getId() == AIR || down instanceof BlockLiquid || down instanceof BlockFire) { BlockFallEvent event = new BlockFallEvent(this); this.level.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { return type; } this.level.setBlock(this, Block.get(Block.AIR), true, true); 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("", 0)) .add(new DoubleTag("", 0)) .add(new DoubleTag("", 0))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", 0)) .add(new FloatTag("", 0))) .putInt("TileID", this.getId()) .putByte("Data", this.getDamage()); EntityFallingBlock fall = (EntityFallingBlock) Entity.createEntity("FallingSand", this.getLevel().getChunk((int) this.x >> 4, (int) this.z >> 4), nbt); if (fall != null) { fall.spawnToAll(); } } } return type; }
Example #17
Source File: BlockTrapdoor.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_REDSTONE || type == Level.BLOCK_UPDATE_NORMAL) { if ((!isOpen() && this.level.isBlockPowered(this)) || (isOpen() && !this.level.isBlockPowered(this))) { this.level.getServer().getPluginManager().callEvent(new BlockRedstoneEvent(this, isOpen() ? 15 : 0, isOpen() ? 0 : 15)); this.toggle(null); return type; } } return 0; }
Example #18
Source File: Anvil.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public void setChunk(int chunkX, int chunkZ, FullChunk chunk) { if (!(chunk instanceof Chunk)) { throw new ChunkException("Invalid Chunk class"); } chunk.setProvider(this); int regionX = chunkX >> 5; int regionZ = chunkZ >> 5; this.loadRegion(regionX, regionZ); chunk.setX(chunkX); chunk.setZ(chunkZ); long index = Level.chunkHash(chunkX, chunkZ); this.chunks.put(index, (Chunk) chunk); }
Example #19
Source File: Anvil.java From Jupiter with GNU General Public License v3.0 | 5 votes |
protected void loadRegion(int x, int z) { long index = Level.chunkHash(x, z); if (!this.regions.containsKey(index)) { try { this.regions.put(index, new RegionLoader(this, x, z)); } catch (IOException e) { throw new RuntimeException(e); } } }
Example #20
Source File: BlockNetherWart.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { if (this.down().getId() != SOUL_SAND) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } } else if (type == Level.BLOCK_UPDATE_RANDOM) { if (new Random().nextInt(10) == 1) { if (this.getDamage() < 0x03) { BlockNetherWart block = (BlockNetherWart) this.clone(); block.setDamage(block.getDamage() + 1); BlockGrowEvent ev = new BlockGrowEvent(this, block); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { this.getLevel().setBlock(this, ev.getNewState(), true, true); } else { return Level.BLOCK_UPDATE_RANDOM; } } } else { return Level.BLOCK_UPDATE_RANDOM; } } return 0; }
Example #21
Source File: BlockLever.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { int face = this.isPowerOn() ? this.getDamage() ^ 0x08 : this.getDamage(); BlockFace faces = LeverOrientation.byMetadata(face).getFacing().getOpposite(); if (!this.getSide(faces).isSolid()) { this.level.useBreakOn(this); } } return 0; }
Example #22
Source File: Server.java From Jupiter with GNU General Public License v3.0 | 5 votes |
/** * ワールドオブジェクトを名前から取得します。 * @param name 取得したいワールドの名前 * @return Level 取得したワールドオブジェクト */ public Level getLevelByName(String name) { for (Level level : this.getLevels().values()) { if (level.getFolderName().equals(name)) { return level; } } return null; }
Example #23
Source File: BlockCocoa.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { int[] faces = new int[]{ 3, 4, 2, 5, 3, 4, 2, 5, 3, 4, 2, 5 }; Block side = this.getSide(BlockFace.fromIndex(faces[this.meta])); if (side.getId() != Block.WOOD && side.getDamage() != BlockWood.JUNGLE) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } } else if (type == Level.BLOCK_UPDATE_RANDOM) { if (new Random().nextInt(2) == 1) { if (this.meta / 4 < 2) { BlockCocoa block = (BlockCocoa) this.clone(); block.meta += 4; BlockGrowEvent ev = new BlockGrowEvent(this, block); Server.getInstance().getPluginManager().callEvent(ev); if (!ev.isCancelled()) { this.getLevel().setBlock(this, ev.getNewState(), true, true); } else { return Level.BLOCK_UPDATE_RANDOM; } } } else { return Level.BLOCK_UPDATE_RANDOM; } } return 0; }
Example #24
Source File: Server.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean unloadLevel(Level level, boolean forceUnload) { if (level == this.getDefaultLevel() && !forceUnload) { throw new IllegalStateException("The default level cannot be unloaded while running, please switch levels."); } return level.unload(forceUnload); }
Example #25
Source File: BlockTripWireHook.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { if (!this.getSide(this.getFacing().getOpposite()).isNormalBlock()) { this.level.useBreakOn(this); } return type; } else if (type == Level.BLOCK_UPDATE_SCHEDULED) { this.calculateState(false, true, -1, null); return type; } return 0; }
Example #26
Source File: BlockCactus.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { Block down = down(); if (down.getId() != SAND && down.getId() != CACTUS) { this.getLevel().useBreakOn(this); } else { for (int side = 2; side <= 5; ++side) { Block block = getSide(BlockFace.fromIndex(side)); if (!block.canBeFlowedInto()) { this.getLevel().useBreakOn(this); } } } } else if (type == Level.BLOCK_UPDATE_RANDOM) { if (down().getId() != CACTUS) { if (this.getDamage() == 0x0F) { for (int y = 1; y < 3; ++y) { Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z)); if (b.getId() == AIR) { BlockGrowEvent event = new BlockGrowEvent(b, Block.get(BlockID.CACTUS)); Server.getInstance().getPluginManager().callEvent(event); if (!event.isCancelled()) { this.getLevel().setBlock(b, event.getNewState(), true); } } } this.setDamage(0); this.getLevel().setBlock(this, this); } else { this.setDamage(this.getDamage() + 1); this.getLevel().setBlock(this, this); } } } return 0; }
Example #27
Source File: BlockSugarcane.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { Block down = this.down(); if (down.isTransparent() && down.getId() != SUGARCANE_BLOCK) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } } else if (type == Level.BLOCK_UPDATE_RANDOM) { if (this.down().getId() != SUGARCANE_BLOCK) { if (this.getDamage() == 0x0F) { for (int y = 1; y < 3; ++y) { Block b = this.getLevel().getBlock(new Vector3(this.x, this.y + y, this.z)); if (b.getId() == AIR) { this.getLevel().setBlock(b, new BlockSugarcane(), false); break; } } this.setDamage(0); this.getLevel().setBlock(this, this, false); } else { this.setDamage(this.getDamage() + 1); this.getLevel().setBlock(this, this, false); } return Level.BLOCK_UPDATE_RANDOM; } } return 0; }
Example #28
Source File: NukkitPlatform.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public List<? extends com.sk89q.worldedit.world.World> getWorlds() { Collection<Level> levels = mod.getServer().getLevels().values(); List<com.sk89q.worldedit.world.World> ret = new ArrayList<>(levels.size()); for (Level level : levels) { ret.add(new NukkitWorld(level)); } return ret; }
Example #29
Source File: BlockTNT.java From Nukkit with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if ((type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) && this.level.isBlockPowered(this.getLocation())) { this.prime(); } return 0; }
Example #30
Source File: BlockRedstoneWire.java From Jupiter with GNU General Public License v3.0 | 5 votes |
@Override public int onUpdate(int type) { if (type != Level.BLOCK_UPDATE_NORMAL && type != Level.BLOCK_UPDATE_REDSTONE) { return 0; } if (type == Level.BLOCK_UPDATE_NORMAL && !this.canBePlacedOn(this.getLocation().down())) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } this.updateSurroundingRedstone(false); return Level.BLOCK_UPDATE_NORMAL; }