use of org.bukkit.Chunk in project askyblock by tastybento.
the class GridManager method removeMobs.
/**
* Removes monsters around location l
*
* @param l location
*/
public void removeMobs(final Location l) {
if (!inWorld(l)) {
return;
}
// Don't remove mobs if at spawn
if (this.isAtSpawn(l)) {
// plugin.getLogger().info("DEBUG: at spawn!");
return;
}
final int px = l.getBlockX();
final int py = l.getBlockY();
final int pz = l.getBlockZ();
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Chunk c = l.getWorld().getChunkAt(new Location(l.getWorld(), px + x * 16, py, pz + z * 16));
if (c.isLoaded()) {
for (final Entity e : c.getEntities()) {
// Don't remove if the entity is an NPC or has a name tag
if (e.getCustomName() != null || e.hasMetadata("NPC"))
continue;
if (e instanceof Monster && !Settings.mobWhiteList.contains(e.getType())) {
e.remove();
}
}
}
}
}
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class RegionHandler_Vanilla_1_14 method getRegions3.
@Override
public Set<IntVector3> getRegions3(World world) {
HashSet<IntVector3> regionIndices = new HashSet<IntVector3>();
// Add all RegionFile instances in the cache
Object regionFileCache = findRegionFileCache.invoke(null, HandleConversion.toWorldHandle(world));
regionIndices.addAll(findCacheRegionFileCoordinates.invoke(null, regionFileCache));
// Obtain the region coordinates from all files in regions folder
File regionFolder = Common.SERVER.getWorldRegionFolder(world.getName());
if (regionFolder != null) {
String[] regionFileNames = regionFolder.list();
for (String regionFileName : regionFileNames) {
File file = new File(regionFolder, regionFileName);
if (file.isFile() && file.exists() && file.length() >= 4096) {
IntVector3 coords = getRegionFileCoordinates(file).toIntVector3(0);
if (coords != null && !regionIndices.contains(coords)) {
regionIndices.add(coords);
}
}
}
}
// Look at all loaded chunks of the world and add the regions they are inside of
for (Chunk chunk : world.getLoadedChunks()) {
IntVector3 coords = new IntVector3(chunk.getX() >> 5, 0, chunk.getZ() >> 5);
regionIndices.add(coords);
}
return regionIndices;
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class LightingHandler_1_16_4_StarLightEngine method setSectionSkyLightAsync.
@Override
public CompletableFuture<Void> setSectionSkyLightAsync(World world, int cx, int cy, int cz, byte[] data) {
final CompletableFuture<Void> future = new CompletableFuture<Void>();
final Chunk chunk = WorldUtil.getChunk(world, cx, cz);
scheduleUpdate(world, () -> {
try {
handle.setSkyLightData(HandleConversion.toChunkHandle(chunk), cx, cy, cz, data);
future.complete(null);
} catch (Throwable t) {
future.completeExceptionally(t);
}
});
return future;
}
use of org.bukkit.Chunk in project BKCommonLib by bergerhealer.
the class BlockStateConversion_1_12_2 method tileEntityToBlockState.
public synchronized BlockState tileEntityToBlockState(Block block, Object nmsTileEntity) {
// Store and restore old state in case of recursive calls to this function
// This could happen if inside BlockState construction a chunk is loaded anyway
// Would be bad, but its best to assume the worst
TileState old_state = input_state;
try {
input_state = new TileState(block, nmsTileEntity);
BlockState result = proxy_block.getState();
// Internal BlockState needs to have all proxy field instances replaced with what it should be
BlockStateCache cache = BlockStateCache.get(result.getClass());
for (SafeField<World> worldField : cache.worldFields) {
worldField.set(result, input_state.block.getWorld());
}
for (SafeField<Chunk> chunkField : cache.chunkFields) {
chunkField.set(result, input_state.block.getChunk());
}
// All done!
return result;
} catch (Throwable t) {
Logging.LOGGER_CONVERSION.once(Level.SEVERE, "Failed to convert " + nmsTileEntity.getClass().getName() + " to CraftBlockState", t);
return CraftBlockStateHandle.createNew(input_state.block);
} finally {
input_state = old_state;
}
}
use of org.bukkit.Chunk in project Glowstone by GlowstoneMC.
the class AnvilChunkIoService method write.
@Override
public void write(GlowChunk chunk) throws IOException {
int x = chunk.getX();
int z = chunk.getZ();
RegionFile region = cache.getRegionFile(x, z);
int regionX = x & REGION_SIZE - 1;
int regionZ = z & REGION_SIZE - 1;
CompoundTag levelTags = new CompoundTag();
// core properties
// NON-NLS
levelTags.putInt("xPos", chunk.getX());
// NON-NLS
levelTags.putInt("zPos", chunk.getZ());
// NON-NLS
levelTags.putLong("LastUpdate", 0);
// NON-NLS
levelTags.putLong("InhabitedTime", chunk.getInhabitedTime());
// NON-NLS
levelTags.putBool("TerrainPopulated", chunk.isPopulated());
// chunk sections
List<CompoundTag> sectionTags = new ArrayList<>();
GlowChunkSnapshot snapshot = chunk.getChunkSnapshot(true, true, false);
ChunkSection[] sections = snapshot.getRawSections();
for (byte i = 0; i < sections.length; ++i) {
ChunkSection sec = sections[i];
if (sec == null) {
continue;
}
CompoundTag sectionTag = new CompoundTag();
// NON-NLS
sectionTag.putByte("Y", i);
sec.recount();
sec.writeToNbt(sectionTag);
sectionTags.add(sectionTag);
}
// NON-NLS
levelTags.putCompoundList("Sections", sectionTags);
// height map and biomes
// NON-NLS
levelTags.putIntArray("HeightMap", snapshot.getRawHeightmap());
// NON-NLS
levelTags.putByteArray("Biomes", snapshot.getRawBiomes());
// Save Slime Chunk
// NON-NLS
levelTags.putByte("isSlimeChunk", snapshot.isSlimeChunk() ? 1 : 0);
// entities
List<CompoundTag> entities = new ArrayList<>();
for (GlowEntity entity : chunk.getRawEntities()) {
if (!entity.shouldSave()) {
continue;
}
// passengers will be saved as part of the vehicle
if (entity.isInsideVehicle()) {
continue;
}
try {
CompoundTag tag = new CompoundTag();
EntityStorage.save(entity, tag);
entities.add(tag);
} catch (Exception e) {
ConsoleMessages.Warn.Entity.SAVE_FAILED.log(e, entity, chunk);
}
}
levelTags.putCompoundList("Entities", entities);
// block entities
List<CompoundTag> blockEntities = new ArrayList<>();
for (BlockEntity entity : chunk.getRawBlockEntities()) {
try {
CompoundTag tag = new CompoundTag();
entity.saveNbt(tag);
blockEntities.add(tag);
} catch (Exception ex) {
ConsoleMessages.Error.BlockEntity.SAVE_FAILED.log(ex, entity.getBlock());
}
}
levelTags.putCompoundList("TileEntities", blockEntities);
List<CompoundTag> tileTicks = new ArrayList<>();
for (Location location : chunk.getWorld().getTickMap()) {
Chunk locationChunk = location.getChunk();
if (locationChunk.getX() == chunk.getX() && locationChunk.getZ() == chunk.getZ()) {
int tileX = location.getBlockX();
int tileY = location.getBlockY();
int tileZ = location.getBlockZ();
String type = ItemIds.getName(location.getBlock().getType());
CompoundTag tag = new CompoundTag();
tag.putInt("x", tileX);
tag.putInt("y", tileY);
tag.putInt("z", tileZ);
tag.putString("i", type);
tileTicks.add(tag);
}
}
levelTags.putCompoundList("TileTicks", tileTicks);
CompoundTag levelOut = new CompoundTag();
levelOut.putCompound("Level", levelTags);
try (NbtOutputStream nbt = new NbtOutputStream(region.getChunkDataOutputStream(regionX, regionZ), false)) {
nbt.writeTag(levelOut);
}
}
Aggregations