Skip to content

Commit

Permalink
fix weird black spots in the world
Browse files Browse the repository at this point in the history
  • Loading branch information
FalsePattern committed Nov 9, 2024
1 parent fe0a69d commit 698d2f3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
9 changes: 9 additions & 0 deletions src/main/java/com/falsepattern/lumi/internal/ArrayHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@

import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import net.minecraft.world.chunk.NibbleArray;

public class ArrayHelper {
public static boolean isEmpty(@Nullable NibbleArray arr) {
if (arr == null) {
return true;
}
return isZero(arr.data);
}
@Contract(pure = true)
public static boolean isZero(byte @NotNull [] arr) {
for (int i = 0; i < arr.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

package com.falsepattern.lumi.internal.mixin.mixins.common;

import com.falsepattern.lumi.internal.ArrayHelper;
import lombok.val;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.chunk.NibbleArray;
Expand Down Expand Up @@ -189,26 +190,12 @@ public boolean isEmpty() {
return false;

if (lumi$isDirty) {
val blockLightEqual = lumi$checkLightArrayEqual(blocklightArray, EnumSkyBlock.Block);
val skyLightEqual = lumi$checkLightArrayEqual(skylightArray, EnumSkyBlock.Sky);
lumi$isTrivial = blockLightEqual && skyLightEqual;
val blockLightEmpty = ArrayHelper.isEmpty(blocklightArray);
val skyLightEmpty = ArrayHelper.isEmpty(skylightArray);
lumi$isTrivial = blockLightEmpty && skyLightEmpty;
lumi$isDirty = false;
}

return lumi$isTrivial;
}

@Unique
private boolean lumi$checkLightArrayEqual(NibbleArray storage, EnumSkyBlock baseLightType) {
if (storage == null)
return true;

val expectedValue = (byte) baseLightType.defaultLightValue;
val data = storage.data;
for (val value : data)
if (value != expectedValue)
return false;

return true;
}
}

0 comments on commit 698d2f3

Please sign in to comment.