From 3c1994430060e16d26bfe7c9ce8f1cbf22d7d0dc Mon Sep 17 00:00:00 2001 From: Hannes Greule Date: Mon, 12 Apr 2021 12:40:18 +0200 Subject: [PATCH] Remove heightmap code from NMSRelighter --- .../fawe/bukkit/NMSRelighterFactory.java | 2 +- .../implementation/lighting/NMSRelighter.java | 103 +++--------------- .../boydti/fawe/util/EditSessionBuilder.java | 5 +- 3 files changed, 15 insertions(+), 95 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/NMSRelighterFactory.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/NMSRelighterFactory.java index ceba55e8e..52d2383e4 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/NMSRelighterFactory.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/NMSRelighterFactory.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull; public class NMSRelighterFactory implements RelighterFactory { @Override public @NotNull Relighter createRelighter(RelightMode relightMode, World world, IQueueExtent queue) { - return new NMSRelighter(queue, Settings.IMP.LIGHTING.DO_HEIGHTMAPS, + return new NMSRelighter(queue, relightMode != null ? relightMode : RelightMode.valueOf(Settings.IMP.LIGHTING.MODE)); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/lighting/NMSRelighter.java b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/lighting/NMSRelighter.java index dab5face3..112c3035e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/lighting/NMSRelighter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/beta/implementation/lighting/NMSRelighter.java @@ -12,7 +12,6 @@ import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.TaskManager; import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.math.MutableBlockVector3; -import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.EnumProperty; import com.sk89q.worldedit.registry.state.Property; @@ -37,7 +36,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReentrantLock; -import java.util.stream.Collectors; public class NMSRelighter implements Relighter { @@ -47,14 +45,12 @@ public class NMSRelighter implements Relighter { private static final EnumProperty stairHalf; private static final EnumProperty stairShape; private static final EnumProperty slabHalf; - private static final BooleanProperty waterLogged; static { stairDirection = (DirectionalProperty) (Property) BlockTypes.SANDSTONE_STAIRS.getProperty("facing"); stairHalf = (EnumProperty) (Property) BlockTypes.SANDSTONE_STAIRS.getProperty("half"); stairShape = (EnumProperty) (Property) BlockTypes.SANDSTONE_STAIRS.getProperty("shape"); slabHalf = (EnumProperty) (Property) BlockTypes.SANDSTONE_SLAB.getProperty("type"); - waterLogged = (BooleanProperty) (Property) BlockTypes.SANDSTONE_SLAB.getProperty("waterlogged"); } public final MutableBlockVector3 mutableBlockPos = new MutableBlockVector3(0, 0, 0); @@ -62,31 +58,27 @@ public class NMSRelighter implements Relighter { private final Map skyToRelight; private final Object present = new Object(); private final Map chunksToSend; - private final Map> heightMaps; private final ConcurrentLinkedQueue extentdSkyToRelight = new ConcurrentLinkedQueue<>(); private final Map lightQueue; private final AtomicBoolean lightLock = new AtomicBoolean(false); private final ConcurrentHashMap concurrentLightQueue; private final RelightMode relightMode; private final int maxY; - private final boolean calculateHeightMaps; private final ReentrantLock lightingLock; private final AtomicBoolean finished = new AtomicBoolean(false); private boolean removeFirst; public NMSRelighter(IQueueExtent queue, boolean calculateHeightMaps) { - this(queue, calculateHeightMaps, null); + this(queue, null); } - public NMSRelighter(IQueueExtent queue, boolean calculateHeightMaps, RelightMode relightMode) { + public NMSRelighter(IQueueExtent queue, RelightMode relightMode) { this.queue = queue; this.skyToRelight = new Long2ObjectOpenHashMap<>(12); this.lightQueue = new Long2ObjectOpenHashMap<>(12); this.chunksToSend = new Long2ObjectOpenHashMap<>(12); this.concurrentLightQueue = new ConcurrentHashMap<>(12); - this.heightMaps = new Long2ObjectOpenHashMap<>(12); this.maxY = queue.getMaxY(); - this.calculateHeightMaps = calculateHeightMaps; this.relightMode = relightMode != null ? relightMode : RelightMode.valueOf(Settings.IMP.LIGHTING.MODE); this.lightingLock = new ReentrantLock(); } @@ -160,12 +152,11 @@ public class NMSRelighter implements Relighter { extentdSkyToRelight.clear(); skyToRelight.clear(); chunksToSend.clear(); - heightMaps.clear(); lightQueue.clear(); } public boolean addChunk(int cx, int cz, byte[] fix, int bitmask) { - RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask, calculateHeightMaps); + RelightSkyEntry toPut = new RelightSkyEntry(cx, cz, fix, bitmask); extentdSkyToRelight.add(toPut); return true; } @@ -834,14 +825,6 @@ public class NMSRelighter implements Relighter { int z = MathMan.unpairIntY(pair); ChunkHolder chunk = (ChunkHolder) queue.getOrCreateChunk(x, z); chunk.setBitMask(bitMask); - if (calculateHeightMaps && heightMaps != null) { - Map heightMapList = heightMaps.get(pair); - if (heightMapList != null) { - for (Map.Entry heightMapEntry : heightMapList.entrySet()) { - chunk.setHeightMap(heightMapEntry.getKey(), heightMapEntry.getValue()); - } - } - } iter.remove(); } if (Settings.IMP.LIGHTING.ASYNC) { @@ -870,14 +853,6 @@ public class NMSRelighter implements Relighter { int z = MathMan.unpairIntY(pair); ChunkHolder chunk = (ChunkHolder) queue.getOrCreateChunk(x, z); chunk.setBitMask(bitMask); - if (calculateHeightMaps && heightMaps != null) { - Map heightMapList = heightMaps.get(pair); - if (heightMapList != null) { - for (Map.Entry heightMapEntry : heightMapList.entrySet()) { - chunk.setHeightMap(heightMapEntry.getKey(), heightMapEntry.getValue()); - } - } - } chunk.flushLightToGet(true); Fawe.imp().getPlatformAdapter().sendChunk(chunk.getOrCreateGet(), bitMask, true); iter.remove(); @@ -944,33 +919,19 @@ public class NMSRelighter implements Relighter { private void fixSkyLighting(List sorted) { RelightSkyEntry[] chunks = sorted.toArray(new RelightSkyEntry[sorted.size()]); boolean remove = this.removeFirst; - boolean heightMaps = this.calculateHeightMaps; BlockVectorSet chunkSet = null; - if (remove || heightMaps) { + if (remove) { BlockVectorSet tmpSet = new BlockVectorSet(); - if (remove) { - chunkSet = new BlockVectorSet(); - for (RelightSkyEntry chunk : chunks) { - tmpSet.add(chunk.x, 0, chunk.z); - } + chunkSet = new BlockVectorSet(); + for (RelightSkyEntry chunk : chunks) { + tmpSet.add(chunk.x, 0, chunk.z); } for (RelightSkyEntry chunk : chunks) { - if (remove) { - int x = chunk.x; - int z = chunk.z; - if (tmpSet.contains(x + 1, 0, z) && tmpSet.contains(x - 1, 0, z) && tmpSet.contains(x, 0, z + 1) && tmpSet - .contains(x, 0, z - 1)) { - chunkSet.add(x, 0, z); - } - } - if (heightMaps) { - long pair = MathMan.pairInt(chunk.x, chunk.z); - this.heightMaps.putIfAbsent(pair, new HashMap<>()); - Map heightMapList = this.heightMaps.get(pair); - heightMapList.putIfAbsent(HeightMapType.WORLD_SURFACE, new int[256]); - heightMapList.putIfAbsent(HeightMapType.OCEAN_FLOOR, new int[256]); - heightMapList.putIfAbsent(HeightMapType.MOTION_BLOCKING, new int[256]); - heightMapList.putIfAbsent(HeightMapType.MOTION_BLOCKING_NO_LEAVES, new int[256]); + int x = chunk.x; + int z = chunk.z; + if (tmpSet.contains(x + 1, 0, z) && tmpSet.contains(x - 1, 0, z) && tmpSet.contains(x, 0, z + 1) && tmpSet + .contains(x, 0, z - 1)) { + chunkSet.add(x, 0, z); } } } @@ -996,12 +957,6 @@ public class NMSRelighter implements Relighter { iChunk.removeSectionLighting(y >> 4, true); } - Map heightMapList = null; - if (heightMaps) { - long pair = MathMan.pairInt(chunk.x, chunk.z); - heightMapList = this.heightMaps.get(pair); - } - for (int j = 0; j < 256; j++) { int x = j & 15; int z = j >> 4; @@ -1014,38 +969,6 @@ public class NMSRelighter implements Relighter { addLightUpdate(bx + x, y, bz + z); } - if (heightMaps) { - if (heightMapList.get(HeightMapType.WORLD_SURFACE)[j] == 0 && !material.isAir()) { - // MC Requires y+1 - heightMapList.get(HeightMapType.WORLD_SURFACE)[j] = y + 1; - } - if (heightMapList.get(HeightMapType.OCEAN_FLOOR)[j] == 0 && material.isSolid()) { - heightMapList.get(HeightMapType.OCEAN_FLOOR)[j] = y + 1; - } - Map, Object> states = state.getStates(); - try { - if (heightMapList.get(HeightMapType.MOTION_BLOCKING)[j] == 0 && (material.isSolid() || material.isLiquid() || ( - states.containsKey(waterLogged) && state.getState(waterLogged)))) { - heightMapList.get(HeightMapType.MOTION_BLOCKING)[j] = y + 1; - } - } catch (Exception ignored) { - LOGGER.debug("Error calculating waterlogged state for BlockState: " + state.getBlockType().getId() + ". States:"); - LOGGER.debug(states.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()) - .collect(Collectors.joining(", ", "{", "}"))); - } - try { - if (heightMapList.get(HeightMapType.MOTION_BLOCKING_NO_LEAVES)[j] == 0 && (material.isSolid() || material.isLiquid() || ( - states.containsKey(waterLogged) && state.getState(waterLogged))) && !state.getBlockType().getId() - .toLowerCase().contains("leaves")) { - heightMapList.get(HeightMapType.MOTION_BLOCKING_NO_LEAVES)[j] = y + 1; - } - } catch (Exception ignored) { - LOGGER.debug("Error calculating waterlogged state for BlockState: " + state.getBlockType().getId() + ". States:"); - LOGGER.debug(states.entrySet().stream().map(e -> e.getKey() + "=" + e.getValue()) - .collect(Collectors.joining(", ", "{", "}"))); - } - } - switch (value) { case 0: if (opacity > 1) { @@ -1223,7 +1146,7 @@ public class NMSRelighter implements Relighter { public int bitmask; public boolean smooth; - public RelightSkyEntry(int x, int z, byte[] fix, int bitmask, boolean heightmaps) { + public RelightSkyEntry(int x, int z, byte[] fix, int bitmask) { this.x = x; this.z = z; byte[] array = new byte[256]; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java index 555816522..d1d6c31ad 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/util/EditSessionBuilder.java @@ -411,10 +411,7 @@ public class EditSessionBuilder { } else { relighter = NullRelighter.INSTANCE; } - // TODO dirty workaround, NMSRelighter and HeightmapProcessor don't work well together - if (Settings.IMP.LIGHTING.MODE == 0 || relighter.getClass().getSimpleName().startsWith("Tuinity")) { - extent.addProcessor(new HeightmapProcessor(world)); - } + extent.addProcessor(new HeightmapProcessor(world)); if (limit != null && !limit.isUnlimited() && regionExtent != null) { this.extent = new LimitExtent(regionExtent, limit); } else if (limit != null && !limit.isUnlimited()) {