Add option to change lighting behaviour in queues

This commit is contained in:
dordsor21
2020-09-11 14:18:50 +01:00
parent f0e9a8c5fe
commit 1552a8e74b
6 changed files with 126 additions and 6 deletions

View File

@ -63,7 +63,8 @@ import java.util.function.Consumer;
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
private final SideEffectSet sideEffectSet;
private final SideEffectSet noSideEffectSet;
private final SideEffectSet lightingSideEffectSet;
private org.bukkit.World bukkitWorld;
@Inject private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
@Inject private ChunkCoordinatorFactory chunkCoordinatorFactory;
@ -71,7 +72,8 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
@Inject public BukkitQueueCoordinator(@Nonnull World world) {
super(world);
sideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
}
@Override public BlockState getBlock(int x, int y, int z) {
@ -177,7 +179,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
localChunk.getTiles().forEach(((blockVector3, tag) -> {
try {
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
getWorld().setBlock(blockVector3, block, sideEffectSet);
getWorld().setBlock(blockVector3, block, noSideEffectSet);
} catch (WorldEditException ignored) {
StateWrapper sw = new StateWrapper(tag);
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
@ -205,7 +207,23 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
*/
private void setWorldBlock(int x, int y, int z, @Nonnull BaseBlock block, @Nonnull BlockVector2 blockVector2) {
try {
getWorld().setBlock(BlockVector3.at(x, y, z), block, sideEffectSet);
BlockVector3 loc = BlockVector3.at(x, y, z);
boolean lighting = false;
switch (getLightingMode()) {
case NONE:
break;
case PLACEMENT:
lighting = block.getBlockType().getMaterial().getLightValue() > 0;
break;
case REPLACEMENT:
lighting = block.getBlockType().getMaterial().getLightValue() > 0
|| getWorld().getBlock(loc).getBlockType().getMaterial().getLightValue() > 0;
break;
default:
// Can only be "all"
lighting = true;
}
getWorld().setBlock(loc, block, lighting ? lightingSideEffectSet : noSideEffectSet);
} catch (WorldEditException ignored) {
// Fallback to not so nice method
BlockData blockData = BukkitAdapter.adapt(block);