Looks like automagical relighting (#838)

Fixes #686
This commit is contained in:
dordsor21
2021-01-11 19:29:16 +00:00
committed by GitHub
parent 74a2f02003
commit b4d7562b87
46 changed files with 932 additions and 142 deletions

View File

@ -1,11 +1,13 @@
package com.boydti.fawe.bukkit;
import com.boydti.fawe.FAWEPlatformAdapterImpl;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.IFawe;
import com.boydti.fawe.beta.implementation.cache.preloader.AsyncPreloader;
import com.boydti.fawe.beta.implementation.cache.preloader.Preloader;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.adapter.BukkitQueueHandler;
import com.boydti.fawe.bukkit.adapter.NMSAdapter;
import com.boydti.fawe.bukkit.listener.BrushListener;
import com.boydti.fawe.bukkit.listener.BukkitImageListener;
import com.boydti.fawe.bukkit.listener.CFIPacketListener;
@ -58,6 +60,7 @@ public class FaweBukkit implements IFawe, Listener {
private BukkitImageListener imageListener;
private CFIPacketListener packetListener;
private final boolean chunksStretched;
private final FAWEPlatformAdapterImpl platformAdapter;
public FaweBukkit(Plugin plugin) {
this.plugin = plugin;
@ -81,6 +84,8 @@ public class FaweBukkit implements IFawe, Listener {
chunksStretched =
Integer.parseInt(Bukkit.getBukkitVersion().split("-")[0].split("\\.")[1]) >= 16;
platformAdapter = new NMSAdapter();
//PlotSquared support is limited to Spigot/Paper as of 02/20/2020
TaskManager.IMP.later(this::setupPlotSquared, 0);
@ -294,6 +299,11 @@ public class FaweBukkit implements IFawe, Listener {
return chunksStretched;
}
@Override
public FAWEPlatformAdapterImpl getPlatformAdapter() {
return platformAdapter;
}
private void setupPlotSquared() {
Plugin plotSquared = this.plugin.getServer().getPluginManager().getPlugin("PlotSquared");
if (plotSquared == null) {

View File

@ -0,0 +1,7 @@
package com.boydti.fawe.bukkit.adapter;
public interface BukkitGetBlocks {
void send(int mask, boolean lighting);
}

View File

@ -1,5 +1,8 @@
package com.boydti.fawe.bukkit.adapter;
import com.boydti.fawe.FAWEPlatformAdapterImpl;
import com.boydti.fawe.beta.IChunkGet;
import com.boydti.fawe.beta.implementation.chunk.ChunkHolder;
import com.boydti.fawe.config.Settings;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.math.BlockVector3;
@ -10,7 +13,7 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
import java.util.Map;
import java.util.function.Function;
public class NMSAdapter {
public class NMSAdapter implements FAWEPlatformAdapterImpl {
public static int createPalette(int[] blockToPalette, int[] paletteToBlock, int[] blocksCopy,
int[] num_palette_buffer, char[] set, Map<BlockVector3, Integer> ticking_blocks, boolean fastmode) {
int air = 0;
@ -182,4 +185,12 @@ public class NMSAdapter {
num_palette_buffer[0] = num_palette;
return air;
}
@Override
public void sendChunk(IChunkGet chunk, int mask, boolean lighting) {
if (!(chunk instanceof BukkitGetBlocks)) {
throw new IllegalArgumentException("(IChunkGet) chunk not of type BukkitGetBlocks");
}
((BukkitGetBlocks) chunk).send(mask, lighting);
}
}

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.adapter.BukkitGetBlocks;
import com.boydti.fawe.bukkit.adapter.DelegateLock;
import com.boydti.fawe.bukkit.adapter.mc1_15_2.nbt.LazyCompoundTag_1_15_2;
import com.boydti.fawe.config.Settings;
@ -74,7 +75,7 @@ import javax.annotation.Nullable;
import static org.slf4j.LoggerFactory.getLogger;
public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
public class BukkitGetBlocks_1_15_2 extends CharGetBlocks implements BukkitGetBlocks {
private static final Logger log = LoggerFactory.getLogger(BukkitGetBlocks_1_15_2.class);
@ -90,6 +91,7 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
private boolean createCopy = false;
private BukkitGetBlocks_1_15_2_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
public BukkitGetBlocks_1_15_2(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
@ -120,6 +122,37 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
return copy;
}
@Override
public void setLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setSkyLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {
BitArray bitArray = new BitArray(9, 256);
bitArray.fromRaw(data);
nmsChunk.heightMap.get(HeightMap.Type.valueOf(type.name())).a(bitArray.getData());
}
public int getChunkZ() {
return chunkZ;
}
@ -141,6 +174,34 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {
SectionPosition sectionPosition = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibble = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.BLOCK).a(sectionPosition);
if (nibble != null) {
lightUpdate = true;
synchronized (nibble) {
byte[] bytes = nibble.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
if (sky) {
SectionPosition sectionPositionSky = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibbleSky = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.SKY).a(sectionPositionSky);
if (nibble != null) {
lightUpdate = true;
synchronized (nibbleSky) {
byte[] bytes = nibbleSky.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
}
}
@Override
public CompoundTag getTile(int x, int y, int z) {
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (
@ -436,33 +497,10 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
Map<HeightMapType, int[]> heightMaps = set.getHeightMaps();
for (Map.Entry<HeightMapType, int[]> entry : heightMaps.entrySet()) {
BitArray bitArray = new BitArray(9, 256);
bitArray.fromRaw(entry.getValue());
nmsChunk.heightMap.get(HeightMap.Type.valueOf(entry.getKey().name())).a(bitArray.getData());
}
boolean lightUpdate = false;
// Lighting
char[][] light = set.getLight();
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
char[][] skyLight = set.getSkyLight();
if (skyLight != null) {
lightUpdate = true;
try {
fillLightNibble(skyLight, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
BukkitGetBlocks_1_15_2.this.setHeightmapToGet(entry.getKey(), entry.getValue());
}
BukkitGetBlocks_1_15_2.this.setLightingToGet(set.getLight());
BukkitGetBlocks_1_15_2.this.setSkyLightingToGet(set.getSkyLight());
Runnable[] syncTasks = null;
@ -584,7 +622,9 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
nmsChunk.mustNotSave = false;
nmsChunk.markDirty();
// send to player
BukkitAdapter_1_15_2.sendChunk(nmsWorld, chunkX, chunkZ, finalMask, finalLightUpdate);
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
finalizer.run();
}
@ -636,6 +676,11 @@ public class BukkitGetBlocks_1_15_2 extends CharGetBlocks {
}
}
@Override
public synchronized void send(int mask, boolean lighting) {
BukkitAdapter_1_15_2.sendChunk(world, chunkX, chunkZ, mask, lighting);
}
@Override
public synchronized char[] update(int layer, char[] data) {
ChunkSection section = getSections(true)[layer];

View File

@ -104,6 +104,15 @@ public class BukkitGetBlocks_1_15_2_Copy implements IChunkGet {
return false;
}
@Override
public void setLightingToGet(char[][] lighting) {}
@Override
public void setSkyLightingToGet(char[][] lighting) {}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {}
protected void storeBiomes(BiomeStorage biomeStorage) {
this.biomeStorage = new BiomeStorage(BukkitAdapter_1_15_2.getBiomeArray(biomeStorage).clone());
}
@ -122,6 +131,9 @@ public class BukkitGetBlocks_1_15_2_Copy implements IChunkGet {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {}
@Override
public boolean trim(boolean aggressive, int layer) {
return false;

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.adapter.BukkitGetBlocks;
import com.boydti.fawe.bukkit.adapter.DelegateLock;
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1;
import com.boydti.fawe.config.Settings;
@ -74,7 +75,7 @@ import javax.annotation.Nullable;
import static org.slf4j.LoggerFactory.getLogger;
public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
public class BukkitGetBlocks_1_16_1 extends CharGetBlocks implements BukkitGetBlocks {
private static final Logger log = LoggerFactory.getLogger(BukkitGetBlocks_1_16_1.class);
@ -90,6 +91,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
private boolean createCopy = false;
private BukkitGetBlocks_1_16_1_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
public BukkitGetBlocks_1_16_1(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
@ -121,6 +123,37 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
return copy;
}
@Override
public void setLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setSkyLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(data);
nmsChunk.heightMap.get(HeightMap.Type.valueOf(type.name())).a(bitArray.getData());
}
public int getChunkZ() {
return chunkZ;
}
@ -142,6 +175,34 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {
SectionPosition sectionPosition = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibble = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.BLOCK).a(sectionPosition);
if (nibble != null) {
lightUpdate = true;
synchronized (nibble) {
byte[] bytes = nibble.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
if (sky) {
SectionPosition sectionPositionSky = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibbleSky = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.SKY).a(sectionPositionSky);
if (nibble != null) {
lightUpdate = true;
synchronized (nibbleSky) {
byte[] bytes = nibbleSky.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
}
}
@Override
public CompoundTag getTile(int x, int y, int z) {
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (
@ -438,33 +499,10 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
Map<HeightMapType, int[]> heightMaps = set.getHeightMaps();
for (Map.Entry<HeightMapType, int[]> entry : heightMaps.entrySet()) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(entry.getValue());
nmsChunk.heightMap.get(HeightMap.Type.valueOf(entry.getKey().name())).a(bitArray.getData());
}
boolean lightUpdate = false;
// Lighting
char[][] light = set.getLight();
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
char[][] skyLight = set.getSkyLight();
if (skyLight != null) {
lightUpdate = true;
try {
fillLightNibble(skyLight, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
BukkitGetBlocks_1_16_1.this.setHeightmapToGet(entry.getKey(), entry.getValue());
}
BukkitGetBlocks_1_16_1.this.setLightingToGet(set.getLight());
BukkitGetBlocks_1_16_1.this.setSkyLightingToGet(set.getSkyLight());
Runnable[] syncTasks = null;
@ -586,7 +624,9 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
nmsChunk.mustNotSave = false;
nmsChunk.markDirty();
// send to player
BukkitAdapter_1_16_1.sendChunk(nmsWorld, chunkX, chunkZ, finalMask, finalLightUpdate);
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
finalizer.run();
}
@ -638,6 +678,11 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
}
}
@Override
public synchronized void send(int mask, boolean lighting) {
BukkitAdapter_1_16_1.sendChunk(world, chunkX, chunkZ, mask, lighting);
}
@Override
public synchronized char[] update(int layer, char[] data) {
ChunkSection section = getSections(true)[layer];

View File

@ -104,6 +104,15 @@ public class BukkitGetBlocks_1_16_1_Copy implements IChunkGet {
return false;
}
@Override
public void setLightingToGet(char[][] lighting) {}
@Override
public void setSkyLightingToGet(char[][] lighting) {}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {}
protected void storeBiomes(BiomeStorage biomeStorage) {
this.biomeStorage = new BiomeStorage(BukkitAdapter_1_16_1.getBiomeArray(biomeStorage).clone());
}
@ -122,6 +131,9 @@ public class BukkitGetBlocks_1_16_1_Copy implements IChunkGet {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {}
@Override
public boolean trim(boolean aggressive, int layer) {
return false;

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.adapter.BukkitGetBlocks;
import com.boydti.fawe.bukkit.adapter.DelegateLock;
import com.boydti.fawe.bukkit.adapter.mc1_16_2.nbt.LazyCompoundTag_1_16_2;
import com.boydti.fawe.config.Settings;
@ -75,7 +76,7 @@ import java.util.function.Function;
import static org.slf4j.LoggerFactory.getLogger;
public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
public class BukkitGetBlocks_1_16_2 extends CharGetBlocks implements BukkitGetBlocks {
private static final Logger log = LoggerFactory.getLogger(BukkitGetBlocks_1_16_2.class);
@ -91,6 +92,7 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
private boolean createCopy = false;
private BukkitGetBlocks_1_16_2_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
public BukkitGetBlocks_1_16_2(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
@ -121,6 +123,37 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
return copy;
}
@Override
public void setLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setSkyLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(data);
nmsChunk.heightMap.get(HeightMap.Type.valueOf(type.name())).a(bitArray.getData());
}
public int getChunkZ() {
return chunkZ;
}
@ -142,6 +175,34 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {
SectionPosition sectionPosition = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibble = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.BLOCK).a(sectionPosition);
if (nibble != null) {
lightUpdate = true;
synchronized (nibble) {
byte[] bytes = nibble.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
if (sky) {
SectionPosition sectionPositionSky = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibbleSky = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.SKY).a(sectionPositionSky);
if (nibble != null) {
lightUpdate = true;
synchronized (nibbleSky) {
byte[] bytes = nibbleSky.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
}
}
@Override
public CompoundTag getTile(int x, int y, int z) {
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (
@ -441,33 +502,10 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
Map<HeightMapType, int[]> heightMaps = set.getHeightMaps();
for (Map.Entry<HeightMapType, int[]> entry : heightMaps.entrySet()) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(entry.getValue());
nmsChunk.heightMap.get(HeightMap.Type.valueOf(entry.getKey().name())).a(bitArray.getData());
}
boolean lightUpdate = false;
// Lighting
char[][] light = set.getLight();
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
char[][] skyLight = set.getSkyLight();
if (skyLight != null) {
lightUpdate = true;
try {
fillLightNibble(skyLight, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
BukkitGetBlocks_1_16_2.this.setHeightmapToGet(entry.getKey(), entry.getValue());
}
BukkitGetBlocks_1_16_2.this.setLightingToGet(set.getLight());
BukkitGetBlocks_1_16_2.this.setSkyLightingToGet(set.getSkyLight());
Runnable[] syncTasks = null;
@ -589,7 +627,9 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
nmsChunk.mustNotSave = false;
nmsChunk.markDirty();
// send to player
BukkitAdapter_1_16_2.sendChunk(nmsWorld, chunkX, chunkZ, finalMask, finalLightUpdate);
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
finalizer.run();
}
@ -641,6 +681,11 @@ public class BukkitGetBlocks_1_16_2 extends CharGetBlocks {
}
}
@Override
public synchronized void send(int mask, boolean lighting) {
BukkitAdapter_1_16_2.sendChunk(world, chunkX, chunkZ, mask, lighting);
}
@Override
public synchronized char[] update(int layer, char[] data) {
ChunkSection section = getSections(true)[layer];

View File

@ -105,6 +105,15 @@ public class BukkitGetBlocks_1_16_2_Copy implements IChunkGet {
return false;
}
@Override
public void setLightingToGet(char[][] lighting) {}
@Override
public void setSkyLightingToGet(char[][] lighting) {}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {}
protected void storeBiomes(BiomeStorage biomeStorage) {
this.biomeStorage = new BiomeStorage(biomeStorage.g, BukkitAdapter_1_16_2.getBiomeArray(biomeStorage).clone());
}
@ -123,6 +132,9 @@ public class BukkitGetBlocks_1_16_2_Copy implements IChunkGet {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {}
@Override
public boolean trim(boolean aggressive, int layer) {
return false;

View File

@ -7,6 +7,7 @@ import com.boydti.fawe.beta.IChunkSet;
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
import com.boydti.fawe.beta.implementation.lighting.HeightMapType;
import com.boydti.fawe.beta.implementation.queue.QueueHandler;
import com.boydti.fawe.bukkit.adapter.BukkitGetBlocks;
import com.boydti.fawe.bukkit.adapter.DelegateLock;
import com.boydti.fawe.bukkit.adapter.mc1_16_4.nbt.LazyCompoundTag_1_16_4;
import com.boydti.fawe.config.Settings;
@ -75,7 +76,7 @@ import java.util.function.Function;
import static org.slf4j.LoggerFactory.getLogger;
public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
public class BukkitGetBlocks_1_16_4 extends CharGetBlocks implements BukkitGetBlocks {
private static final Logger log = LoggerFactory.getLogger(BukkitGetBlocks_1_16_4.class);
@ -91,6 +92,7 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
private boolean createCopy = false;
private BukkitGetBlocks_1_16_4_Copy copy = null;
private boolean forceLoadSections = true;
private boolean lightUpdate = false;
public BukkitGetBlocks_1_16_4(World world, int chunkX, int chunkZ) {
this(((CraftWorld) world).getHandle(), chunkX, chunkZ);
@ -121,6 +123,37 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
return copy;
}
@Override
public void setLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setSkyLightingToGet(char[][] light) {
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
}
}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(data);
nmsChunk.heightMap.get(HeightMap.Type.valueOf(type.name())).a(bitArray.getData());
}
public int getChunkZ() {
return chunkZ;
}
@ -142,6 +175,34 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {
SectionPosition sectionPosition = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibble = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.BLOCK).a(sectionPosition);
if (nibble != null) {
lightUpdate = true;
synchronized (nibble) {
byte[] bytes = nibble.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
if (sky) {
SectionPosition sectionPositionSky = SectionPosition.a(nmsChunk.getPos(), layer);
NibbleArray nibbleSky = world.getChunkProvider().getLightEngine().a(EnumSkyBlock.SKY).a(sectionPositionSky);
if (nibble != null) {
lightUpdate = true;
synchronized (nibbleSky) {
byte[] bytes = nibbleSky.getCloneIfSet();
if (bytes != NibbleArray.EMPTY_NIBBLE) {
Arrays.fill(bytes, (byte) 0);
}
}
}
}
}
@Override
public CompoundTag getTile(int x, int y, int z) {
TileEntity tileEntity = getChunk().getTileEntity(new BlockPosition((x & 15) + (
@ -441,33 +502,10 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
Map<HeightMapType, int[]> heightMaps = set.getHeightMaps();
for (Map.Entry<HeightMapType, int[]> entry : heightMaps.entrySet()) {
BitArrayUnstretched bitArray = new BitArrayUnstretched(9, 256);
bitArray.fromRaw(entry.getValue());
nmsChunk.heightMap.get(HeightMap.Type.valueOf(entry.getKey().name())).a(bitArray.getData());
}
boolean lightUpdate = false;
// Lighting
char[][] light = set.getLight();
if (light != null) {
lightUpdate = true;
try {
fillLightNibble(light, EnumSkyBlock.BLOCK);
} catch (Throwable e) {
e.printStackTrace();
}
}
char[][] skyLight = set.getSkyLight();
if (skyLight != null) {
lightUpdate = true;
try {
fillLightNibble(skyLight, EnumSkyBlock.SKY);
} catch (Throwable e) {
e.printStackTrace();
}
BukkitGetBlocks_1_16_4.this.setHeightmapToGet(entry.getKey(), entry.getValue());
}
BukkitGetBlocks_1_16_4.this.setLightingToGet(set.getLight());
BukkitGetBlocks_1_16_4.this.setSkyLightingToGet(set.getSkyLight());
Runnable[] syncTasks = null;
@ -589,7 +627,9 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
nmsChunk.mustNotSave = false;
nmsChunk.markDirty();
// send to player
BukkitAdapter_1_16_4.sendChunk(nmsWorld, chunkX, chunkZ, finalMask, finalLightUpdate);
if (Settings.IMP.LIGHTING.MODE == 0 || !Settings.IMP.LIGHTING.DELAY_PACKET_SENDING) {
this.send(finalMask, finalLightUpdate);
}
if (finalizer != null) {
finalizer.run();
}
@ -641,6 +681,11 @@ public class BukkitGetBlocks_1_16_4 extends CharGetBlocks {
}
}
@Override
public synchronized void send(int mask, boolean lighting) {
BukkitAdapter_1_16_4.sendChunk(world, chunkX, chunkZ, mask, lighting);
}
@Override
public synchronized char[] update(int layer, char[] data) {
ChunkSection section = getSections(true)[layer];

View File

@ -105,6 +105,15 @@ public class BukkitGetBlocks_1_16_4_Copy implements IChunkGet {
return false;
}
@Override
public void setLightingToGet(char[][] lighting) {}
@Override
public void setSkyLightingToGet(char[][] lighting) {}
@Override
public void setHeightmapToGet(HeightMapType type, int[] data) {}
protected void storeBiomes(BiomeStorage biomeStorage) {
this.biomeStorage = new BiomeStorage(biomeStorage.g, BukkitAdapter_1_16_4.getBiomeArray(biomeStorage).clone());
}
@ -123,6 +132,9 @@ public class BukkitGetBlocks_1_16_4_Copy implements IChunkGet {
return base != null ? BukkitAdapter.adapt(CraftBlock.biomeBaseToBiome(world.r().b(IRegistry.ay), base)) : null;
}
@Override
public void removeSectionLighting(int layer, boolean sky) {}
@Override
public boolean trim(boolean aggressive, int layer) {
return false;