Skip to content

Commit e03e40c

Browse files
committed
utilize the utils
1 parent 597f5c1 commit e03e40c

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

common/src/main/java/net/artienia/rubinated_nether/block/LavaLamp.java

+8-15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package net.artienia.rubinated_nether.block;
22

3+
import net.artienia.rubinated_nether.utils.ShapeUtils;
34
import net.minecraft.core.BlockPos;
5+
import net.minecraft.core.Direction;
46
import net.minecraft.world.entity.player.Player;
57
import net.minecraft.world.item.ItemStack;
68
import net.minecraft.world.level.BlockGetter;
@@ -16,27 +18,18 @@
1618
import net.minecraft.world.phys.shapes.VoxelShape;
1719
import org.jetbrains.annotations.Nullable;
1820

21+
import java.util.Map;
22+
1923
public class LavaLamp extends RotatedPillarBlock {
20-
protected static final float AABB_MIN = 2.0F;
21-
protected static final float AABB_MAX = 14.0F;
22-
protected static final VoxelShape Y_AXIS_AABB = Block.box(2.0D, 0.0D, 2.0D, 14.0D, 16.0D, 14.0D);
23-
protected static final VoxelShape Z_AXIS_AABB = Block.box(2.0D, 2.0D, 0.0D, 14.0D, 14.0D, 16.0D);
24-
protected static final VoxelShape X_AXIS_AABB = Block.box(0.0D, 2.0D, 2.0D, 16.0D, 14.0D, 14.0D);
24+
25+
protected static final Map<Direction.Axis, VoxelShape> AXIS_SHAPES = ShapeUtils.allAxis(Block.box(2.0D, 0.0D, 2.0D, 14.0D, 16.0D, 14.0D));
2526

2627
public LavaLamp(Properties properties) {
2728
super(properties);
2829
}
2930

30-
public VoxelShape getShape(BlockState p_154346_, BlockGetter p_154347_, BlockPos p_154348_, CollisionContext p_154349_) {
31-
switch (p_154346_.getValue(AXIS)) {
32-
case X:
33-
default:
34-
return X_AXIS_AABB;
35-
case Z:
36-
return Z_AXIS_AABB;
37-
case Y:
38-
return Y_AXIS_AABB;
39-
}
31+
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext context) {
32+
return AXIS_SHAPES.get(state.getValue(AXIS));
4033
}
4134

4235
public void playerDestroy(Level level, Player player, BlockPos pos, BlockState state, @Nullable BlockEntity blockEntity, ItemStack tool) {

common/src/main/java/net/artienia/rubinated_nether/utils/ShapeUtils.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
1616
*/
1717
public class ShapeUtils {
1818

19+
public static Map<Direction.Axis, VoxelShape> allAxis(VoxelShape facingY) {
20+
Map<Direction.Axis, VoxelShape> map = new EnumMap<>(Direction.Axis.class);
21+
for(Direction.Axis axis : Direction.Axis.values()) {
22+
Vec3 dir = getDirectionRotationVec(Direction.fromAxisAndDirection(axis, Direction.AxisDirection.POSITIVE));
23+
map.put(axis, rotatedCopy(facingY, dir));
24+
}
25+
return map;
26+
}
27+
1928
public static Map<Direction, VoxelShape> allDirections(VoxelShape facingUp) {
2029
Map<Direction, VoxelShape> map = new EnumMap<>(Direction.class);
2130
for(Direction direction : Direction.values()) {
22-
Vec3 dir = new Vec3(
23-
direction == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(direction) ? 180 : 90),
24-
-((Math.max(direction.get2DDataValue(), 0) & 3) * 90f), 0
25-
);
31+
Vec3 dir = getDirectionRotationVec(direction);
2632
map.put(direction, rotatedCopy(facingUp, dir));
2733
}
2834
return map;
@@ -90,4 +96,11 @@ public static Vec3 rotateVec(Vec3 vec, double deg, Direction.Axis axis) {
9096
public static double length(VoxelShape shape, Direction.Axis axis) {
9197
return shape.isEmpty() ? 0 : shape.max(axis) - shape.min(axis);
9298
}
99+
100+
private static Vec3 getDirectionRotationVec(Direction direction) {
101+
return new Vec3(
102+
direction == Direction.UP ? 0 : (Direction.Plane.VERTICAL.test(direction) ? 180 : 90),
103+
-((Math.max(direction.get2DDataValue(), 0) & 3) * 90f), 0
104+
);
105+
}
93106
}

0 commit comments

Comments
 (0)