Skip to content

Commit bf0884a

Browse files
committed
Rotate model's shape based on transformation
Fixes: #345
1 parent ba60a6b commit bf0884a

File tree

7 files changed

+107
-18
lines changed

7 files changed

+107
-18
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package ca.fxco.moreculling.mixin.blocks.cullshape;
2+
3+
import net.minecraft.Util;
4+
import net.minecraft.world.level.block.Block;
5+
import net.minecraft.world.level.block.EndRodBlock;
6+
import net.minecraft.world.level.block.state.BlockBehaviour;
7+
import net.minecraft.world.level.block.state.BlockState;
8+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
9+
import net.minecraft.world.phys.shapes.Shapes;
10+
import net.minecraft.world.phys.shapes.VoxelShape;
11+
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Unique;
13+
14+
@Mixin(EndRodBlock.class)
15+
public class EndRodBlock_voxelMixin extends Block {
16+
17+
@Unique
18+
private static final VoxelShape[] moreculling$SHAPES = Util.make(new VoxelShape[6], voxelShapes -> {
19+
voxelShapes[0] = Shapes.or(Block.box(6.0, 15.0, 6.0, 10.0, 16.0, 10.0), Block.box(7.0, 0.0, 7.0, 9.0, 16.0, 9.0));
20+
voxelShapes[1] = Shapes.or(Block.box(6.0, 0.0, 6.0, 10.0, 1.0, 10.0), Block.box(7.0, 0.0, 7.0, 9.0, 16.0, 9.0));
21+
voxelShapes[2] = Shapes.or(Block.box(6.0, 6.0, 15.0, 10.0, 10.0, 16.0), Block.box(7.0, 7.0, 0.0, 9.0, 9.0, 16.0));
22+
voxelShapes[3] = Shapes.or(Block.box(6.0, 6.0, 0.0, 10.0, 10.0, 1.0), Block.box(7.0, 7.0, 0.0, 9.0, 9.0, 16.0));
23+
voxelShapes[4] = Shapes.or(Block.box(15.0, 6.0, 6.0, 16.0, 10.0, 10.0), Block.box(0.0, 7.0, 7.0, 16.0, 9.0, 9.0));
24+
voxelShapes[5] = Shapes.or(Block.box(0.0, 6.0, 6.0, 1.0, 10.0, 10.0), Block.box(0.0, 7.0, 7.0, 16.0, 9.0, 9.0));
25+
});
26+
27+
public EndRodBlock_voxelMixin(BlockBehaviour.Properties properties) {
28+
super(properties);
29+
}
30+
31+
@Override
32+
public VoxelShape getOcclusionShape(BlockState state) {
33+
return moreculling$SHAPES[state.getValue(BlockStateProperties.FACING).ordinal()];
34+
}
35+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package ca.fxco.moreculling.mixin.blocks.cullshape;
2+
3+
import net.minecraft.Util;
4+
import net.minecraft.world.level.block.Block;
5+
import net.minecraft.world.level.block.LightningRodBlock;
6+
import net.minecraft.world.level.block.state.BlockState;
7+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
8+
import net.minecraft.world.phys.shapes.Shapes;
9+
import net.minecraft.world.phys.shapes.VoxelShape;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Unique;
12+
13+
@Mixin(LightningRodBlock.class)
14+
public class LightningRodBlock_voxelMixin extends Block {
15+
16+
@Unique
17+
private static final VoxelShape[] moreculling$SHAPES = Util.make(new VoxelShape[6], voxelShapes -> {
18+
voxelShapes[0] = Shapes.or(Block.box(6.0, 0.0, 6.0, 10.0, 4.0, 10.0), Block.box(7.0, 0.0, 7.0, 9.0, 16.0, 9.0));
19+
voxelShapes[1] = Shapes.or(Block.box(6.0, 12.0, 6.0, 10.0, 16.0, 10.0), Block.box(7.0, 0.0, 7.0, 9.0, 16.0, 9.0));
20+
voxelShapes[2] = Shapes.or(Block.box(6.0, 6.0, 0.0, 10.0, 10.0, 4.0), Block.box(7.0, 7.0, 0.0, 9.0, 9.0, 16.0));
21+
voxelShapes[3] = Shapes.or(Block.box(6.0, 6.0, 12.0, 10.0, 10.0, 16.0), Block.box(7.0, 7.0, 0.0, 9.0, 9.0, 16.0));
22+
voxelShapes[4] = Shapes.or(Block.box(0.0, 6.0, 6.0, 4.0, 10.0, 10.0), Block.box(0.0, 7.0, 7.0, 16.0, 9.0, 9.0));
23+
voxelShapes[5] = Shapes.or(Block.box(12.0, 6.0, 6.0, 16.0, 10.0, 10.0), Block.box(0.0, 7.0, 7.0, 16.0, 9.0, 9.0));
24+
});
25+
26+
public LightningRodBlock_voxelMixin(Properties properties) {
27+
super(properties);
28+
}
29+
30+
@Override
31+
public VoxelShape getOcclusionShape(BlockState state) {
32+
return moreculling$SHAPES[state.getValue(BlockStateProperties.FACING).ordinal()];
33+
}
34+
}

common/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockStateBase_cullShapeMixin.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
import ca.fxco.moreculling.api.blockstate.StateCullingShapeCache;
44
import ca.fxco.moreculling.api.model.BakedOpacity;
55
import net.minecraft.client.resources.model.BakedModel;
6-
import net.minecraft.core.BlockPos;
76
import net.minecraft.core.Direction;
8-
import net.minecraft.world.level.BlockGetter;
97
import net.minecraft.world.level.block.Block;
108
import net.minecraft.world.level.block.state.BlockBehaviour;
119
import net.minecraft.world.level.block.state.BlockState;
10+
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
1211
import net.minecraft.world.phys.shapes.Shapes;
1312
import net.minecraft.world.phys.shapes.VoxelShape;
1413
import org.spongepowered.asm.mixin.Final;
@@ -30,8 +29,6 @@ public abstract class BlockStateBase_cullShapeMixin implements StateCullingShape
3029

3130
@Shadow private VoxelShape[] occlusionShapesByFace;
3231

33-
@Shadow public abstract VoxelShape getShape(BlockGetter level, BlockPos pos);
34-
3532
@Shadow @Final private static VoxelShape[] EMPTY_OCCLUSION_SHAPES;
3633
@Shadow @Final private static VoxelShape[] FULL_BLOCK_OCCLUSION_SHAPES;
3734
@Shadow @Final private static Direction[] DIRECTIONS;
@@ -56,7 +53,7 @@ public abstract class BlockStateBase_cullShapeMixin implements StateCullingShape
5653
VoxelShape voxelShape = null;
5754
if (blockRenderManager != null) {
5855
BakedModel model = blockRenderManager.getBlockModel(this.asState());
59-
if (model != null) {
56+
if (model != null && !this.asState().hasProperty(BlockStateProperties.FACING)) {
6057
voxelShape = ((BakedOpacity) model).moreculling$getCullingShape(this.asState());
6158
}
6259
}

common/src/main/java/ca/fxco/moreculling/utils/CullingUtils.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import ca.fxco.moreculling.MoreCulling;
44
import ca.fxco.moreculling.api.blockstate.MoreStateCulling;
55
import ca.fxco.moreculling.api.blockstate.StateCullingShapeCache;
6-
import com.mojang.logging.LogUtils;
76
import it.unimi.dsi.fastutil.objects.Object2ByteLinkedOpenHashMap;
87
import net.caffeinemc.mods.sodium.client.SodiumClientMod;
98
import net.minecraft.client.GraphicsStatus;
@@ -14,7 +13,6 @@
1413
import net.minecraft.util.RandomSource;
1514
import net.minecraft.world.level.BlockGetter;
1615
import net.minecraft.world.level.block.Block;
17-
import net.minecraft.world.level.block.Blocks;
1816
import net.minecraft.world.level.block.LeavesBlock;
1917
import net.minecraft.world.level.block.RenderShape;
2018
import net.minecraft.world.level.block.state.BlockState;

common/src/main/resources/moreculling.mixins.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"blocks.cullshape.BrewingStandBlock_voxelMixin",
2424
"blocks.cullshape.CampfireBlock_voxelMixin",
2525
"blocks.cullshape.ChorusFlowerBlock_voxelMixin",
26+
"blocks.cullshape.EndRodBlock_voxelMixin",
27+
"blocks.cullshape.LightningRodBlock_voxelMixin",
2628
"blocks.DoorBlock_cullAgainstMixin",
2729
"blocks.EndGatewayBlock_cullMixin",
2830
"blocks.FletchingTableBlock_devMixin",

fabric/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_fabricCullShapeMixin.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
import ca.fxco.moreculling.api.model.CullShapeElement;
55
import ca.fxco.moreculling.api.model.ExtendedUnbakedModel;
66
import ca.fxco.moreculling.utils.ShapeUtils;
7+
import com.mojang.math.Transformation;
78
import net.minecraft.client.renderer.block.model.BlockElement;
89
import net.minecraft.client.renderer.block.model.BlockModel;
910
import net.minecraft.client.renderer.block.model.ItemTransforms;
1011
import net.minecraft.client.renderer.block.model.TextureSlots;
11-
import net.minecraft.client.resources.model.*;
12+
import net.minecraft.client.resources.model.BakedModel;
13+
import net.minecraft.client.resources.model.ModelBaker;
14+
import net.minecraft.client.resources.model.ModelState;
15+
import net.minecraft.client.resources.model.UnbakedModel;
1216
import net.minecraft.core.Direction;
1317
import net.minecraft.resources.ResourceLocation;
1418
import net.minecraft.world.level.block.Block;
1519
import net.minecraft.world.phys.shapes.Shapes;
1620
import net.minecraft.world.phys.shapes.VoxelShape;
1721
import org.jetbrains.annotations.Nullable;
18-
import org.joml.Quaternionf;
1922
import org.spongepowered.asm.mixin.Mixin;
2023
import org.spongepowered.asm.mixin.Shadow;
2124
import org.spongepowered.asm.mixin.injection.At;
@@ -64,10 +67,20 @@ public abstract class BlockModel_fabricCullShapeMixin implements ExtendedUnbaked
6467
voxelShape = ShapeUtils.orUnoptimized(voxelShape, shape);
6568
}
6669
}
67-
Quaternionf quaternion = settings.getRotation().getLeftRotation();
68-
if (quaternion.y != 0) {
69-
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundY(Direction.SOUTH,
70-
Direction.fromYRot(Math.toDegrees(2.0f * Math.acos(quaternion.w))), voxelShape);
70+
71+
if (settings.getRotation() != Transformation.identity()) {;
72+
Direction direction = Direction.rotate(settings.getRotation().getMatrix(), Direction.NORTH);
73+
if (direction.getAxis() != Direction.Axis.Y) {
74+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundY(Direction.NORTH, direction, voxelShape);
75+
} else {
76+
voxelShape = null;
77+
/*direction = Direction.rotate(settings.getRotation().getMatrix(), Direction.UP); TODO rotation for non horizontal directions
78+
if (direction.getAxis() != Direction.Axis.X) {
79+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundX(Direction.UP, direction, voxelShape);
80+
} else {
81+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundZ(Direction.UP, direction, voxelShape);
82+
}*/
83+
}
7184
}
7285
bakedOpacity.moreculling$setCullingShape(voxelShape);
7386
}

neoforge/src/main/java/ca/fxco/moreculling/mixin/models/cullshape/BlockModel_neoforgeCullShapeMixin.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import ca.fxco.moreculling.api.model.CullShapeElement;
55
import ca.fxco.moreculling.api.model.ExtendedUnbakedModel;
66
import ca.fxco.moreculling.utils.ShapeUtils;
7+
import com.mojang.math.Transformation;
78
import net.minecraft.client.renderer.block.model.BlockElement;
89
import net.minecraft.client.renderer.block.model.BlockModel;
910
import net.minecraft.client.renderer.block.model.ItemTransforms;
@@ -19,7 +20,6 @@
1920
import net.minecraft.world.phys.shapes.Shapes;
2021
import net.minecraft.world.phys.shapes.VoxelShape;
2122
import org.jetbrains.annotations.Nullable;
22-
import org.joml.Quaternionf;
2323
import org.spongepowered.asm.mixin.Mixin;
2424
import org.spongepowered.asm.mixin.Shadow;
2525
import org.spongepowered.asm.mixin.injection.At;
@@ -69,10 +69,20 @@ public abstract class BlockModel_neoforgeCullShapeMixin implements ExtendedUnbak
6969
voxelShape = ShapeUtils.orUnoptimized(voxelShape, shape);
7070
}
7171
}
72-
Quaternionf quaternion = settings.getRotation().getLeftRotation();
73-
if (quaternion.y != 0) {
74-
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundY(Direction.SOUTH,
75-
Direction.fromYRot(Math.toDegrees(2.0f * Math.acos(quaternion.w))), voxelShape);
72+
73+
if (settings.getRotation() != Transformation.identity()) {;
74+
Direction direction = Direction.rotate(settings.getRotation().getMatrix(), Direction.NORTH);
75+
if (direction.getAxis() != Direction.Axis.Y) {
76+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundY(Direction.NORTH, direction, voxelShape);
77+
} else {
78+
voxelShape = null;
79+
/*direction = Direction.rotate(settings.getRotation().getMatrix(), Direction.UP); TODO
80+
if (direction.getAxis() != Direction.Axis.X) {
81+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundX(Direction.UP, direction, voxelShape);
82+
} else {
83+
voxelShape = ShapeUtils.rotateShapeUnoptimizedAroundZ(Direction.UP, direction, voxelShape);
84+
}*/
85+
}
7686
}
7787
bakedOpacity.moreculling$setCullingShape(voxelShape);
7888
}

0 commit comments

Comments
 (0)