Skip to content

Commit

Permalink
Fixed bale models
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Dec 23, 2024
1 parent e3f82ab commit e8fcd4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
37 changes: 29 additions & 8 deletions src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import net.minecraft.util.Util;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
Expand All @@ -53,15 +54,13 @@ public class EdibleBlock extends HayBlock {

// [up/down][north/south][west/east]
public static final BooleanProperty[] SEGMENTS = {
BOTTOM_NORTH_WEST,
BOTTOM_NORTH_EAST,
BOTTOM_SOUTH_WEST,
BOTTOM_SOUTH_EAST,
TOP_NORTH_WEST,
TOP_NORTH_EAST,
TOP_SOUTH_WEST,
TOP_SOUTH_EAST
BOTTOM_NORTH_WEST, BOTTOM_NORTH_EAST,
BOTTOM_SOUTH_WEST, BOTTOM_SOUTH_EAST,

TOP_NORTH_WEST, TOP_NORTH_EAST,
TOP_SOUTH_WEST, TOP_SOUTH_EAST
};

private static final VoxelShape[] SHAPES = {
Block.createCuboidShape(0, 0, 0, 8, 8, 8),
Block.createCuboidShape(8, 0, 0, 16, 8, 8),
Expand All @@ -83,6 +82,28 @@ public class EdibleBlock extends HayBlock {
return shape == null ? VoxelShapes.fullCube() : shape.simplify();
});

public static int rotate(Direction.Axis axis, int index) {
Direction x = ((index & 1) == 0 ? Direction.EAST : Direction.WEST).rotateClockwise(axis);
Direction y = ((index & 4) == 0 ? Direction.DOWN : Direction.UP).rotateClockwise(axis);
Direction z = ((index & 2) == 0 ? Direction.NORTH : Direction.SOUTH).rotateClockwise(axis);
return toIndex(x) | toIndex(y) | toIndex(z);
}

private static int toIndex(Direction direction) {
if (direction.getAxis() == Direction.Axis.X) {
direction = direction.getOpposite();
}
return direction.getDirection() == Direction.AxisDirection.POSITIVE ? getOffset(direction.getAxis()) : 0;
}

private static int getOffset(Direction.Axis axis) {
return switch (axis) {
case X -> 1;
case Z -> 2;
case Y -> 4;
};
}

static void bootstrap() {
UseBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) -> {
if (!Pony.of(player).getSpecies().isEquine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static net.minecraft.data.client.VariantSettings.Y;
import static net.minecraft.data.client.VariantSettings.Rotation.R0;
import static net.minecraft.data.client.VariantSettings.Rotation.R90;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
Expand Down Expand Up @@ -53,14 +52,25 @@ public void registerBale(Identifier blockId, Identifier baseBlockId, String endS

for (Direction.Axis axis : Direction.Axis.VALUES) {
for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) {
BooleanProperty segment = EdibleBlock.SEGMENTS[i];
segment.getName();
int index = i;
if (axis == Direction.Axis.X) {
index = EdibleBlock.rotate(Direction.Axis.Z, index);
index = EdibleBlock.rotate(Direction.Axis.Z, index);
index = EdibleBlock.rotate(Direction.Axis.Z, index);
index = EdibleBlock.rotate(Direction.Axis.X, index);
}
if (axis == Direction.Axis.Z) {
index = EdibleBlock.rotate(Direction.Axis.X, index);
}

BooleanProperty segment = EdibleBlock.SEGMENTS[index];

supplier.with(When.create().set(EdibleBlock.AXIS, axis).set(segment, true), BlockStateVariant.create()
.put(MODEL, uploadedModels.computeIfAbsent(i, ii -> {
return BlockModels.BALE_MODELS[ii].getLeft().upload(blockId.withPath(p -> "block/" + p + BlockModels.BALE_MODELS[ii].getRight()), textures, modelCollector);
}))
.put(X, axis == Direction.Axis.Y ? R0 : R90)
.put(Y, axis == Direction.Axis.X ? R90 : R0)
.put(X, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R90)
.put(Y, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R0)
);
}
}
Expand Down

0 comments on commit e8fcd4d

Please sign in to comment.