mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-21 20:33:10 +01:00
Fixed bale models
This commit is contained in:
parent
e3f82ab133
commit
e8fcd4d050
2 changed files with 44 additions and 13 deletions
|
@ -32,6 +32,7 @@ import net.minecraft.util.ItemActionResult;
|
||||||
import net.minecraft.util.Util;
|
import net.minecraft.util.Util;
|
||||||
import net.minecraft.util.hit.BlockHitResult;
|
import net.minecraft.util.hit.BlockHitResult;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.Direction;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.util.shape.VoxelShape;
|
import net.minecraft.util.shape.VoxelShape;
|
||||||
import net.minecraft.util.shape.VoxelShapes;
|
import net.minecraft.util.shape.VoxelShapes;
|
||||||
|
@ -53,15 +54,13 @@ public class EdibleBlock extends HayBlock {
|
||||||
|
|
||||||
// [up/down][north/south][west/east]
|
// [up/down][north/south][west/east]
|
||||||
public static final BooleanProperty[] SEGMENTS = {
|
public static final BooleanProperty[] SEGMENTS = {
|
||||||
BOTTOM_NORTH_WEST,
|
BOTTOM_NORTH_WEST, BOTTOM_NORTH_EAST,
|
||||||
BOTTOM_NORTH_EAST,
|
BOTTOM_SOUTH_WEST, BOTTOM_SOUTH_EAST,
|
||||||
BOTTOM_SOUTH_WEST,
|
|
||||||
BOTTOM_SOUTH_EAST,
|
TOP_NORTH_WEST, TOP_NORTH_EAST,
|
||||||
TOP_NORTH_WEST,
|
TOP_SOUTH_WEST, TOP_SOUTH_EAST
|
||||||
TOP_NORTH_EAST,
|
|
||||||
TOP_SOUTH_WEST,
|
|
||||||
TOP_SOUTH_EAST
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final VoxelShape[] SHAPES = {
|
private static final VoxelShape[] SHAPES = {
|
||||||
Block.createCuboidShape(0, 0, 0, 8, 8, 8),
|
Block.createCuboidShape(0, 0, 0, 8, 8, 8),
|
||||||
Block.createCuboidShape(8, 0, 0, 16, 8, 8),
|
Block.createCuboidShape(8, 0, 0, 16, 8, 8),
|
||||||
|
@ -83,6 +82,28 @@ public class EdibleBlock extends HayBlock {
|
||||||
return shape == null ? VoxelShapes.fullCube() : shape.simplify();
|
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() {
|
static void bootstrap() {
|
||||||
UseBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) -> {
|
UseBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockHitResult hitResult) -> {
|
||||||
if (!Pony.of(player).getSpecies().isEquine()
|
if (!Pony.of(player).getSpecies().isEquine()
|
||||||
|
|
|
@ -7,7 +7,6 @@ import static net.minecraft.data.client.VariantSettings.X;
|
||||||
import static net.minecraft.data.client.VariantSettings.Y;
|
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.R0;
|
||||||
import static net.minecraft.data.client.VariantSettings.Rotation.R90;
|
import static net.minecraft.data.client.VariantSettings.Rotation.R90;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
@ -53,14 +52,25 @@ public class UExternalBlockStateModelGenerator extends UBlockStateModelGenerator
|
||||||
|
|
||||||
for (Direction.Axis axis : Direction.Axis.VALUES) {
|
for (Direction.Axis axis : Direction.Axis.VALUES) {
|
||||||
for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) {
|
for (int i = 0; i < EdibleBlock.SEGMENTS.length; i++) {
|
||||||
BooleanProperty segment = EdibleBlock.SEGMENTS[i];
|
int index = i;
|
||||||
segment.getName();
|
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()
|
supplier.with(When.create().set(EdibleBlock.AXIS, axis).set(segment, true), BlockStateVariant.create()
|
||||||
.put(MODEL, uploadedModels.computeIfAbsent(i, ii -> {
|
.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);
|
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(X, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R90)
|
||||||
.put(Y, axis == Direction.Axis.X ? R90 : R0)
|
.put(Y, axis == Direction.Axis.Y ? R0 : axis == Direction.Axis.X ? R90 : R0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue