org.bukkit.ChunkSnapshot Java Examples
The following examples show how to use
org.bukkit.ChunkSnapshot.
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: SnapshotMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
public BlockState getOriginalBlock(int x, int y, int z) { BlockState state = match.getWorld().getBlockAt(x, y, z).getState(); if (y < 0 || y >= 256) return state; ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z); ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector); if (chunkSnapshot != null) { BlockVector chunkPos = chunkVector.worldToChunk(x, y, z); state.setMaterialData( new MaterialData( chunkSnapshot.getBlockTypeId( chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()), (byte) chunkSnapshot.getBlockData( chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()))); } return state; }
Example #2
Source File: BukkitQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public boolean queueChunkLoad(int cx, int cz, RunnableVal<ChunkSnapshot> operation) { if (PAPER) { try { new PaperChunkCallback(getImpWorld(), cx, cz) { @Override public void onLoad(Chunk chunk) { try { ChunkSnapshot snapshot = chunk.getChunkSnapshot(); operation.run(snapshot); } catch (Throwable e) { PAPER = false; } } }; return true; } catch (Throwable ignore) { PAPER = false; } } return super.queueChunkLoad(cx, cz); }
Example #3
Source File: BlockSnapshot.java From civcraft with GNU General Public License v2.0 | 6 votes |
public void setFromSnapshotLocation(int x, int y, int z, ChunkSnapshot snapshot) { /* Modulo in Java doesn't handle negative numbers the way we want it to, compensate here. */ if (x < 0) { x += 16; } if (z < 0) { z += 16; } this.setX(x); this.setY(y); this.setZ(z); this.setSnapshot(snapshot); this.setTypeId(ItemManager.getBlockTypeId(snapshot, this.x, this.y, this.z)); this.setData(ItemManager.getBlockData(snapshot, this.x, this.y, this.z)); }
Example #4
Source File: LevelCalcByChunk.java From askyblock with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("deprecation") private void scanChunk(ChunkSnapshot chunk) { for (int x = 0; x< 16; x++) { // Check if the block coord is inside the protection zone and if not, don't count it if (chunk.getX() * 16 + x < island.getMinProtectedX() || chunk.getX() * 16 + x >= island.getMinProtectedX() + island.getProtectionSize()) { continue; } for (int z = 0; z < 16; z++) { // Check if the block coord is inside the protection zone and if not, don't count it if (chunk.getZ() * 16 + z < island.getMinProtectedZ() || chunk.getZ() * 16 + z >= island.getMinProtectedZ() + island.getProtectionSize()) { continue; } for (int y = 0; y < island.getCenter().getWorld().getMaxHeight(); y++) { Material blockType = Material.getMaterial(chunk.getBlockTypeId(x, y, z)); boolean belowSeaLevel = Settings.seaHeight > 0 && y <= Settings.seaHeight; // Air is free if (!blockType.equals(Material.AIR)) { checkBlock(blockType, chunk.getBlockData(x, y, z), belowSeaLevel); } } } } }
Example #5
Source File: BukkitQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
@Override public ChunkSnapshot getCachedChunk(World world, int cx, int cz) { long pair = MathMan.pairInt(cx, cz); ChunkSnapshot cached = chunkCache.get(pair); if (cached != null) return cached; if (world.isChunkLoaded(cx, cz)) { Long originalKeep = keepLoaded.get(pair); keepLoaded.put(pair, Long.MAX_VALUE); if (world.isChunkLoaded(cx, cz)) { Chunk chunk = world.getChunkAt(cx, cz); ChunkSnapshot snapshot = getAndCacheChunk(chunk); if (originalKeep != null) { keepLoaded.put(pair, originalKeep); } else { keepLoaded.remove(pair); } return snapshot; } else { keepLoaded.remove(pair); return null; } } else { return null; } }
Example #6
Source File: SafeSpotTeleport.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * Loops through the chunks and if a safe spot is found, fires off the teleportation * @param chunkSnapshot */ private void checkChunks(final List<ChunkSnapshot> chunkSnapshot) { // Run async task to scan chunks plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() { @Override public void run() { for (ChunkSnapshot chunk: chunkSnapshot) { if (scanChunk(chunk)) { task.cancel(); return; } } // Nothing happened, change state checking = true; } }); }
Example #7
Source File: SafeSpotTeleport.java From askyblock with GNU General Public License v2.0 | 6 votes |
/** * @param chunk * @return true if a safe spot was found */ private boolean scanChunk(ChunkSnapshot chunk) { // Max height int maxHeight = location.getWorld().getMaxHeight() - 20; // Run through the chunk for (int x = 0; x< 16; x++) { for (int z = 0; z < 16; z++) { // Work down from the entry point up for (int y = Math.min(chunk.getHighestBlockYAt(x, z), maxHeight); y >= 0; y--) { if (checkBlock(chunk, x,y,z, maxHeight)) { return true; } } // end y } //end z } // end x return false; }
Example #8
Source File: Buildable.java From civcraft with GNU General Public License v2.0 | 6 votes |
public static int getBlockIDFromSnapshotMap(HashMap<ChunkCoord, ChunkSnapshot> snapshots, int absX, int absY, int absZ, String worldName) throws CivException { int chunkX = ChunkCoord.castToChunkX(absX); int chunkZ = ChunkCoord.castToChunkZ(absZ); int blockChunkX = absX % 16; int blockChunkZ = absZ % 16; if (blockChunkX < 0) { blockChunkX += 16; } if (blockChunkZ < 0) { blockChunkZ += 16; } ChunkCoord coord = new ChunkCoord(worldName, chunkX, chunkZ); ChunkSnapshot snapshot = snapshots.get(coord); if (snapshot == null) { throw new CivException("Snapshot for chunk "+chunkX+", "+chunkZ+" in "+worldName+" not found for abs:"+absX+","+absZ); } return ItemManager.getBlockTypeId(snapshot, blockChunkX, absY, blockChunkZ); }
Example #9
Source File: SnapshotMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
public MaterialData getOriginalMaterial(int x, int y, int z) { if (y < 0 || y >= 256) return new MaterialData(Material.AIR); ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z); ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector); if (chunkSnapshot != null) { BlockVector chunkPos = chunkVector.worldToChunk(x, y, z); return new MaterialData( chunkSnapshot.getBlockTypeId( chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()), (byte) chunkSnapshot.getBlockData( chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ())); } else { return match.getWorld().getBlockAt(x, y, z).getState().getMaterialData(); } }
Example #10
Source File: SnapshotMatchModule.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockChange(BlockTransformEvent event) { Match match = PGM.get().getMatchManager().getMatch(event.getWorld()); // Dont carry over old chunks into a new match if (match == null || match.isFinished()) return; Chunk chunk = event.getOldState().getChunk(); ChunkVector chunkVector = ChunkVector.of(chunk); if (!chunkSnapshots.containsKey(chunkVector)) { match.getLogger().fine("Copying chunk at " + chunkVector); ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot(); chunkSnapshot.updateBlock( event .getOldState()); // ChunkSnapshot is very likely to have the post-event state already, // so we have to correct it chunkSnapshots.put(chunkVector, chunkSnapshot); } }
Example #11
Source File: ChunkUtil.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public Material getBlockTypeAt(int x, int y, int z) { ChunkSnapshot chunkAt = getChunkAt(x >> 4, z >> 4); if (chunkAt != null) { int cx = x & 0xF; int cz = z & 0xF; return chunkAt.getBlockType(cx, y, cz); } return null; }
Example #12
Source File: BukkitQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public CompoundTag getTileEntity(ChunkSnapshot chunk, int x, int y, int z) { if (getAdapter() == null) { return null; } Location loc = new Location(getWorld(), x, y, z); BaseBlock block = getAdapter().getBlock(loc); return block != null ? block.getNbtData() : null; }
Example #13
Source File: ChunkSnapshotLevelLogic.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
@Override public void calculateScoreAsync(final Location l, final Callback<IslandScore> callback) { // TODO: 10/05/2015 - R4zorax: Ensure no overlapping calls to this one happen... log.entering(CN, "calculateScoreAsync"); // is further threading needed here? final ProtectedRegion region = WorldGuardHandler.getIslandRegionAt(l); if (region == null) { return; } new ChunkSnapShotTask(plugin, l, region, new Callback<List<ChunkSnapshot>>() { @Override public void run() { final List<ChunkSnapshot> snapshotsOverworld = getState(); Location netherLoc = getNetherLocation(l); final ProtectedRegion netherRegion = WorldGuardHandler.getNetherRegionAt(netherLoc); new ChunkSnapShotTask(plugin, netherLoc, netherRegion, new Callback<List<ChunkSnapshot>>() { @Override public void run() { final List<ChunkSnapshot> snapshotsNether = getState(); new BukkitRunnable() { @Override public void run() { calculateScoreAndCallback(region, snapshotsOverworld, netherRegion, snapshotsNether, callback); } }.runTaskAsynchronously(plugin); } }).runTask(plugin); } }).runTask(plugin); }
Example #14
Source File: ChunkSnapShotTask.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
public ChunkSnapShotTask(uSkyBlock plugin, Location location, ProtectedRegion region, final Callback<List<ChunkSnapshot>> callback) { super(plugin, callback); this.location = location; if (region != null) { chunks = new ArrayList<>(WorldEditHandler.getChunks(new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint()))); } else { chunks = new ArrayList<>(); } callback.setState(snapshots); }
Example #15
Source File: BukkitQueue_All.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public int getCombinedId4Data(ChunkSnapshot chunk, int x, int y, int z) { if (chunk.isSectionEmpty(y >> 4)) { return 0; } int id = chunk.getBlockTypeId(x & 15, y, z & 15); if (FaweCache.hasData(id)) { int data = chunk.getBlockData(x & 15, y, z & 15); return (id << 4) + data; } else { return id << 4; } }
Example #16
Source File: ChunkSnapshotLevelLogic.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private static ChunkSnapshot getChunkSnapshot(int x, int z, List<ChunkSnapshot> snapshots) { for (ChunkSnapshot chunk : snapshots) { if (chunk.getX() == x && chunk.getZ() == z) { return chunk; } } return null; }
Example #17
Source File: WindmillStartSyncTask.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void run() { /* Find adjacent farms, get their chunk snapshots and continue processing in our thread. */ ChunkCoord cc = new ChunkCoord(windmill.getCorner()); ArrayList<ChunkSnapshot> snapshots = new ArrayList<ChunkSnapshot>(); int[][] offset = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 1 }, {-1,-1 }, {-1, 1}, {1, -1} }; for (int i = 0; i < 8; i++) { cc.setX(cc.getX() + offset[i][0]); cc.setZ(cc.getZ() + offset[i][1]); FarmChunk farmChunk = CivGlobal.getFarmChunk(cc); if (farmChunk != null) { snapshots.add(farmChunk.getChunk().getChunkSnapshot()); } cc.setFromLocation(windmill.getCorner().getLocation()); } if (snapshots.size() == 0) { return; } /* Fire off an async task to do some post processing. */ TaskMaster.asyncTask("", new WindmillPreProcessTask(windmill, snapshots), 0); }
Example #18
Source File: AsyncChunk.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public ChunkSnapshot getChunkSnapshot(boolean includeMaxblocky, boolean includeBiome, boolean includeBiomeTempRain) { if (Fawe.isMainThread()) { return world.getChunkAt(x, z).getChunkSnapshot(includeMaxblocky, includeBiome, includeBiomeTempRain); } return whenLoaded(new RunnableVal<ChunkSnapshot>() { @Override public void run(ChunkSnapshot value) { this.value = world.getBukkitWorld().getChunkAt(x, z).getChunkSnapshot(includeBiome, includeBiome, includeBiomeTempRain); } }); }
Example #19
Source File: AsyncWorld.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public ChunkSnapshot getEmptyChunkSnapshot(final int x, final int z, final boolean includeBiome, final boolean includeBiomeTempRain) { return TaskManager.IMP.sync(new RunnableVal<ChunkSnapshot>() { @Override public void run(ChunkSnapshot value) { this.value = parent.getEmptyChunkSnapshot(x, z, includeBiome, includeBiomeTempRain); } }); }
Example #20
Source File: SafeSpotTeleport.java From askyblock with GNU General Public License v2.0 | 5 votes |
private boolean safe(ChunkSnapshot chunk, int x, int y, int z, World world) { Vector newSpot = new Vector(chunk.getX() * 16 + x + 0.5D, y + 1, chunk.getZ() * 16 + z + 0.5D); if (portal) { if (bestSpot == null) { // Stash the best spot bestSpot = newSpot.toLocation(world); } return false; } else { teleportEntity(newSpot.toLocation(world)); return true; } }
Example #21
Source File: SnapshotMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public MaterialData getOriginalMaterial(int x, int y, int z) { if(y < 0 || y >= 256) return new MaterialData(Material.AIR); ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z); ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector); if(chunkSnapshot != null) { BlockVector chunkPos = chunkVector.worldToChunk(x, y, z); return new MaterialData(chunkSnapshot.getBlockTypeId(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()), (byte) chunkSnapshot.getBlockData(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ())); } else { return getMatch().getWorld().getBlockAt(x, y, z).getState().getMaterialData(); } }
Example #22
Source File: LevelCalcByChunk.java From askyblock with GNU General Public License v2.0 | 5 votes |
private void checkChunksAsync(final Set<ChunkSnapshot> chunkSnapshot) { // Run async task to scan chunks plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { for (ChunkSnapshot chunk: chunkSnapshot) { scanChunk(chunk); } // Nothing happened, change state checking = true; }); }
Example #23
Source File: SnapshotMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public BlockState getOriginalBlock(int x, int y, int z) { BlockState state = getMatch().getWorld().getBlockAt(x, y, z).getState(); if(y < 0 || y >= 256) return state; ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z); ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector); if(chunkSnapshot != null) { BlockVector chunkPos = chunkVector.worldToChunk(x, y, z); state.setMaterialData(new MaterialData(chunkSnapshot.getBlockTypeId(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()), (byte) chunkSnapshot.getBlockData(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()))); } return state; }
Example #24
Source File: SnapshotMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onBlockChange(BlockTransformEvent event) { Chunk chunk = event.getOldState().getChunk(); ChunkVector chunkVector = ChunkVector.of(chunk); if(!chunkSnapshots.containsKey(chunkVector)) { logger.fine("Copying chunk at " + chunkVector); ChunkSnapshot chunkSnapshot = chunk.getChunkSnapshot(); chunkSnapshot.updateBlock(event.getOldState()); // ChunkSnapshot is very likely to have the post-event state already, so we have to correct it chunkSnapshots.put(chunkVector, chunkSnapshot); } }
Example #25
Source File: ChunkManager.java From ThinkMap with Apache License 2.0 | 4 votes |
private void gzipChunk(ChunkSnapshot chunk, ByteBuf out) { int mask = 0; int count = 0; for (int i = 0; i < 16; i++) { if (!chunk.isSectionEmpty(i)) { mask |= 1 << i; count++; } } ByteBuf data = allocator.buffer(16 * 16 * 16 * 4 * count + 3 + 256); data.writeByte(1); // The chunk exists data.writeShort(mask); int offset = 0; int blockDataOffset = 16 * 16 * 16 * 2 * count; int skyDataOffset = blockDataOffset + 16 * 16 * 16 * count; for (int i = 0; i < 16; i++) { if (!chunk.isSectionEmpty(i)) { for (int oy = 0; oy < 16; oy++) { for (int oz = 0; oz < 16; oz++) { for (int ox = 0; ox < 16; ox++) { int y = oy + (i << 4); int id = chunk.getBlockTypeId(ox, y, oz); int dValue = chunk.getBlockData(ox, y, oz); data.setShort((offset << 1) + 3, (id << 4) | dValue); data.setByte(blockDataOffset + offset + 3, chunk.getBlockEmittedLight(ox, y, oz)); data.setByte(skyDataOffset + offset + 3, chunk.getBlockSkyLight(ox, y, oz)); offset++; } } } } } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { data.setByte(skyDataOffset + offset + 3 + x + z * 16, ThinkBiome.bukkitToId(chunk.getBiome(x, z))); } } data.writerIndex(data.capacity()); try { GZIPOutputStream gzip = new GZIPOutputStream(new ByteBufOutputStream(out)); byte[] bytes = new byte[data.readableBytes()]; data.readBytes(bytes); gzip.write(bytes); gzip.close(); } catch (IOException e) { throw new RuntimeException(); } finally { data.release(); } }
Example #26
Source File: SafeSpotTeleport.java From askyblock with GNU General Public License v2.0 | 4 votes |
/** * Returns true if the location is a safe one. * @param chunk * @param x * @param y * @param z * @param worldHeight * @return true if this is a safe spot, false if this is a portal scan */ @SuppressWarnings("deprecation") private boolean checkBlock(ChunkSnapshot chunk, int x, int y, int z, int worldHeight) { World world = location.getWorld(); Material type = Material.getMaterial(chunk.getBlockTypeId(x, y, z)); if (!type.equals(Material.AIR)) { // AIR Material space1 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 1, worldHeight), z)); Material space2 = Material.getMaterial(chunk.getBlockTypeId(x, Math.min(y + 2, worldHeight), z)); if ((space1.equals(Material.AIR) && space2.equals(Material.AIR)) || (space1.equals(Material.PORTAL) && space2.equals(Material.PORTAL)) && (!type.toString().contains("FENCE") && !type.toString().contains("DOOR") && !type.toString().contains("GATE") && !type.toString().contains("PLATE"))) { switch (type) { // Unsafe case ANVIL: case BARRIER: case BOAT: case CACTUS: case DOUBLE_PLANT: case ENDER_PORTAL: case FIRE: case FLOWER_POT: case LADDER: case LAVA: case LEVER: case LONG_GRASS: case PISTON_EXTENSION: case PISTON_MOVING_PIECE: case SIGN_POST: case SKULL: case STANDING_BANNER: case STATIONARY_LAVA: case STATIONARY_WATER: case STONE_BUTTON: case TORCH: case TRIPWIRE: case WATER: case WEB: case WOOD_BUTTON: //Block is dangerous break; case PORTAL: if (portal) { // A portal has been found, switch to non-portal mode now portal = false; } break; default: return safe(chunk, x, y, z, world); } } } return false; }
Example #27
Source File: ChunkUtil.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
private Chunks(Map<String, ChunkSnapshot> snapshots) { this.snapshots = snapshots; }
Example #28
Source File: ChunkUtil.java From uSkyBlock with GNU General Public License v3.0 | 4 votes |
public ChunkSnapshot getChunkAt(int cx, int cz) { return snapshots.get("" + cx + "," + cz); }
Example #29
Source File: ItemManager.java From civcraft with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") public static int getBlockTypeId(ChunkSnapshot snapshot, int x, int y, int z) { return snapshot.getBlockTypeId(x, y, z); }
Example #30
Source File: ItemManager.java From civcraft with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") public static int getBlockData(ChunkSnapshot snapshot, int x, int y, int z) { return snapshot.getBlockData(x, y, z); }