use of net.minecraft.world.level.chunk.ChunkAccess in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
try {
BlockPos pos = packet.getPos();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
LevelChunk chunk = world.getChunkAt(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof LevelChunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.ChunkAccess in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getBlockYMask();
List<byte[]> blockData = packet.getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.ChunkAccess in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
if (doNotCheck) {
return;
}
try {
int cX = packet.getX();
int cZ = packet.getZ();
BitSet bitMask = packet.getLightData().getBlockYMask();
List<byte[]> blockData = packet.getLightData().getBlockUpdates();
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
if (!(chk instanceof LevelChunk)) {
return;
}
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
if (lights == null) {
return;
}
boolean any = false;
for (BlockLight light : lights) {
if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
any = true;
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.ChunkAccess in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method checkIfLightsBrokenByPacket.
public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
try {
BlockPos pos = packet.getPos();
int chunkX = pos.getX() >> 4;
int chunkZ = pos.getZ() >> 4;
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
LevelChunk chunk = world.getChunk(chunkX, chunkZ);
boolean any = false;
for (Vector vec : RELATIVE_CHUNKS) {
ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
if (other instanceof LevelChunk) {
List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
if (lights != null) {
any = true;
for (BlockLight light : lights) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
}
}
}
}
if (any) {
Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
}
}, 1);
} catch (Exception ex) {
Debug.echoError(ex);
}
}
use of net.minecraft.world.level.chunk.ChunkAccess in project MinecraftForge by MinecraftForge.
the class ChunkGenWorker method doWork.
@Override
public boolean doWork() {
/* TODO: Check how many things are pending save, and slow down world gen if to many
AnvilChunkLoader loader = dim.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
if (loader != null && loader.getPendingSaveCount() > 100)
{
if (lastNotifcationTime < System.currentTimeMillis() - 10*1000)
{
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
lastNotifcationTime = System.currentTimeMillis();
}
return false;
}
*/
BlockPos next = queue.poll();
if (next != null) {
if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60 * 1000) {
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.progress", total - queue.size(), total), true);
lastNotification = 0;
lastNotifcationTime = System.currentTimeMillis();
}
int x = next.getX();
int z = next.getZ();
if (!dim.hasChunk(x, z)) {
// Chunk is unloaded
ChunkAccess chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
if (!chunk.getStatus().isOrAfter(ChunkStatus.FULL)) {
chunk = dim.getChunk(x, z, ChunkStatus.FULL);
// There isn't a way to check if the chunk is actually created just if it was loaded
genned++;
}
}
}
if (queue.size() == 0) {
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
/* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
if (keepingLoaded != null && !keepingLoaded)
DimensionManager.keepLoaded(dim, false);
*/
return false;
}
return true;
}
Aggregations