From e577acd53ce89f92b7e07f6bbbf078876246f011 Mon Sep 17 00:00:00 2001 From: Angeline Date: Tue, 31 Mar 2020 21:48:11 -0500 Subject: [PATCH] fix: Correct broken comparison logic in LightUtil#unionCoversFullCube --- .../mods/phosphor/common/util/LightUtil.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/jellysquid/mods/phosphor/common/util/LightUtil.java b/src/main/java/me/jellysquid/mods/phosphor/common/util/LightUtil.java index b1297d16..1c203ae5 100644 --- a/src/main/java/me/jellysquid/mods/phosphor/common/util/LightUtil.java +++ b/src/main/java/me/jellysquid/mods/phosphor/common/util/LightUtil.java @@ -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; @@ -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); } }