Cache computed shapes (should improve bed performance)

This commit is contained in:
Sollace 2024-03-25 00:41:10 +00:00
parent ac5aedb488
commit 9ef3a946f6
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 3 additions and 3 deletions

View file

@ -31,7 +31,6 @@ import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.event.GameEvent;
public class FancyBedBlock extends BedBlock {

View file

@ -1,5 +1,6 @@
package com.minelittlepony.unicopia.util;
import net.minecraft.util.Util;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
@ -14,7 +15,7 @@ public interface VoxelShapeUtil {
Vec3d CENTER = new Vec3d(0.5, 0, 0.5);
static Function<Direction, VoxelShape> rotator(VoxelShape base) {
return d -> rotate(base, d);
return Util.memoize(d -> rotate(base, d));
}
static VoxelShape rotate(VoxelShape shape, Direction direction) {
@ -27,7 +28,7 @@ public interface VoxelShapeUtil {
float angle = direction.asRotation() * MathHelper.RADIANS_PER_DEGREE;
return VoxelShapes.union(VoxelShapes.empty(), shape.getBoundingBoxes().stream()
.map(box -> {
//These first two are enough for orthogonal rotations
//These first two are enough for orthogonal rotations
Vec3d a = rotate(box.minX, box.minZ, angle);
Vec3d b = rotate(box.maxX, box.maxZ, angle);
//These cover odd angles