Skip to content

Commit

Permalink
Cache blockOcclusionShape instead of empty
Browse files Browse the repository at this point in the history
  • Loading branch information
1foxy2 committed Dec 6, 2024
1 parent 25d117b commit 14b490e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package ca.fxco.moreculling.mixin.models.cullshape;

import ca.fxco.moreculling.api.model.BakedOpacity;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

import static ca.fxco.moreculling.MoreCulling.blockRenderManager;

@Mixin(BlockBehaviour.BlockStateBase.class)
public class BlockStateBase_cullShapeMixin {
public abstract class BlockStateBase_cullShapeMixin {

@Shadow public abstract Block getBlock();

@Shadow protected abstract BlockState asState();

@Redirect(
method = "initCache",
Expand Down Expand Up @@ -54,4 +61,15 @@ public class BlockStateBase_cullShapeMixin {
}
return instance.getOcclusionShape(state);
}

@WrapOperation(
method = "initCache",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/phys/shapes/Shapes;empty()Lnet/minecraft/world/phys/shapes/VoxelShape;"
)
)
private VoxelShape moreculling$cacheOcclusionShape(Operation<VoxelShape> original) {
return this.getBlock().getOcclusionShape(this.asState());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ private static boolean shouldDrawFace(BlockGetter world, BlockState thisState, B
}
Direction opposite = side.getOpposite();
VoxelShape thisShape = thisState.getFaceOcclusionShape(side);
if (thisShape.isEmpty()) //vanilla 1.21.2 will just return empty if block cant occlude instead of its shape
thisShape = thisState.getBlock().getOcclusionShape(thisState).getFaceShape(side);
VoxelShape sideShape = sideState.getFaceOcclusionShape(opposite);
if (sideShape.isEmpty())
sideShape = sideState.getBlock().getOcclusionShape(sideState).getFaceShape(opposite);

Block.ShapePairKey shapePairKey = new Block.ShapePairKey(
thisShape,
Expand Down

0 comments on commit 14b490e

Please sign in to comment.