Skip to content

Commit

Permalink
fix: Correct broken comparison logic in LightUtil#unionCoversFullCube
Browse files Browse the repository at this point in the history
  • Loading branch information
jellysquid3 committed Apr 1, 2020
1 parent 308c40d commit e577acd
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.jellysquid.mods.phosphor.common.util;

import net.minecraft.util.function.BooleanBiFunction;
import net.minecraft.util.BooleanBiFunction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;

Expand All @@ -17,16 +17,29 @@ public static boolean unionCoversFullCube(VoxelShape a, VoxelShape b) {
return true;
}

// If both shapes are the same, it is pointless to merge them
if (a == b) {
return coversFullCube(a);
}

boolean ae = a == VoxelShapes.empty() || a.isEmpty();
boolean be = b == VoxelShapes.empty() || b.isEmpty();

// If both shapes are empty, they can never overlap
// If both shapes are empty, they can never overlap a full cube
if (ae && be) {
return false;
}

// Test each shape individually if they're non-empty and fail fast
return (ae || !VoxelShapes.matchesAnywhere(VoxelShapes.fullCube(), a, BooleanBiFunction.ONLY_FIRST)) &&
(be || !VoxelShapes.matchesAnywhere(VoxelShapes.fullCube(), b, BooleanBiFunction.ONLY_FIRST));
// If one of the shapes is empty, we can skip merging as any shape merged with an empty shape is the same shape
if (ae || be) {
return coversFullCube(ae ? b : a);
}

// No special optimizations can be performed, so we need to merge both shapes and test them
return coversFullCube(VoxelShapes.combine(a, b, BooleanBiFunction.OR));
}

private static boolean coversFullCube(VoxelShape shape) {
return !VoxelShapes.matchesAnywhere(VoxelShapes.fullCube(), shape, BooleanBiFunction.ONLY_FIRST);
}
}

0 comments on commit e577acd

Please sign in to comment.