Clean up door model generation

This commit is contained in:
Sollace 2024-03-17 12:58:56 +00:00
parent 620e5622f1
commit 16b68d43ba
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
2 changed files with 52 additions and 57 deletions

View file

@ -0,0 +1,28 @@
package com.minelittlepony.unicopia.datagen.providers;
import net.minecraft.data.client.VariantSettings;
import net.minecraft.data.client.VariantSettings.Rotation;
import net.minecraft.util.math.Direction;
import static net.minecraft.util.math.Direction.*;
public class BlockRotation {
private static final Rotation[] ROTATIONS = Rotation.values();
public static final Direction[] DIRECTIONS = { EAST, SOUTH, WEST, NORTH };
public static VariantSettings.Rotation cycle(Rotation rotation, int steps) {
int index = rotation.ordinal() + steps;
while (index < 0) {
index += ROTATIONS.length;
}
return ROTATIONS[index % ROTATIONS.length];
}
public static Rotation next(Rotation rotation) {
return cycle(rotation, 1);
}
public static Rotation previous(Rotation rotation) {
return cycle(rotation, -1);
}
}

View file

@ -21,7 +21,6 @@ import net.minecraft.block.Blocks;
import net.minecraft.block.enums.DoorHinge; import net.minecraft.block.enums.DoorHinge;
import net.minecraft.block.enums.DoubleBlockHalf; import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.data.client.BlockStateModelGenerator; import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.BlockStateSupplier;
import net.minecraft.data.client.BlockStateVariant; import net.minecraft.data.client.BlockStateVariant;
import net.minecraft.data.client.BlockStateVariantMap; import net.minecraft.data.client.BlockStateVariantMap;
import net.minecraft.data.client.Model; import net.minecraft.data.client.Model;
@ -318,72 +317,40 @@ public class UBlockStateModelGenerator extends BlockStateModelGenerator {
TextureMap topTextures = TextureMap.topBottom(door); TextureMap topTextures = TextureMap.topBottom(door);
TextureMap bottomTextures = topTextures.copyAndAdd(TextureKey.TOP, topTextures.getTexture(TextureKey.BOTTOM)); TextureMap bottomTextures = topTextures.copyAndAdd(TextureKey.TOP, topTextures.getTexture(TextureKey.BOTTOM));
registerItemModel(door.asItem()); registerItemModel(door.asItem());
blockStateCollector.accept(createStableDoorBlockState(door, var variants = BlockStateVariantMap.create(Properties.HORIZONTAL_FACING, Properties.DOUBLE_BLOCK_HALF, Properties.DOOR_HINGE, Properties.OPEN);
fillStableDoorVariantMap(variants, DoubleBlockHalf.LOWER,
BlockModels.DOOR_LEFT.upload(door, "_bottom_left", bottomTextures, modelCollector), BlockModels.DOOR_LEFT.upload(door, "_bottom_left", bottomTextures, modelCollector),
BlockModels.DOOR_RIGHT.upload(door, "_bottom_right", bottomTextures, modelCollector), BlockModels.DOOR_RIGHT.upload(door, "_bottom_right", bottomTextures, modelCollector)
);
fillStableDoorVariantMap(variants, DoubleBlockHalf.UPPER,
BlockModels.DOOR_LEFT.upload(door, "_top_left", topTextures, modelCollector), BlockModels.DOOR_LEFT.upload(door, "_top_left", topTextures, modelCollector),
BlockModels.DOOR_RIGHT.upload(door, "_top_right", topTextures, modelCollector) BlockModels.DOOR_RIGHT.upload(door, "_top_right", topTextures, modelCollector)
)); );
blockStateCollector.accept(VariantsBlockStateSupplier.create(door).coordinate(variants));
} }
public static BlockStateSupplier createStableDoorBlockState(Block doorBlock, Identifier bottomLeftHingeClosedModelId, Identifier bottomRightHingeClosedModelId, Identifier topLeftHingeClosedModelId, Identifier topRightHingeClosedModelId) { public static void fillStableDoorVariantMap(
var variants = BlockStateVariantMap.create(Properties.HORIZONTAL_FACING, Properties.DOUBLE_BLOCK_HALF, Properties.DOOR_HINGE, Properties.OPEN);
fillStableDoorVariantMap(variants, DoubleBlockHalf.LOWER, bottomLeftHingeClosedModelId, bottomRightHingeClosedModelId);
fillStableDoorVariantMap(variants, DoubleBlockHalf.UPPER, topLeftHingeClosedModelId, topRightHingeClosedModelId);
return VariantsBlockStateSupplier.create(doorBlock).coordinate(variants);
}
public static BlockStateVariantMap.QuadrupleProperty<Direction, DoubleBlockHalf, DoorHinge, Boolean> fillStableDoorVariantMap(
BlockStateVariantMap.QuadrupleProperty<Direction, DoubleBlockHalf, DoorHinge, Boolean> variantMap, BlockStateVariantMap.QuadrupleProperty<Direction, DoubleBlockHalf, DoorHinge, Boolean> variantMap,
DoubleBlockHalf targetHalf, Identifier leftModelId, Identifier rightModelId) { DoubleBlockHalf targetHalf, Identifier leftModelId, Identifier rightModelId) {
return variantMap fillStableDoorVariantMap(variantMap, targetHalf, DoorHinge.LEFT, false, VariantSettings.Rotation.R0, leftModelId);
.register(Direction.EAST, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create() fillStableDoorVariantMap(variantMap, targetHalf, DoorHinge.RIGHT, false, VariantSettings.Rotation.R0, rightModelId);
.put(VariantSettings.MODEL, leftModelId))
.register(Direction.SOUTH, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create()
.put(VariantSettings.MODEL, leftModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R90))
.register(Direction.WEST, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create()
.put(VariantSettings.MODEL, leftModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R180))
.register(Direction.NORTH, targetHalf, DoorHinge.LEFT, false, BlockStateVariant.create()
.put(VariantSettings.MODEL, leftModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R270))
.register(Direction.EAST, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() fillStableDoorVariantMap(variantMap, targetHalf, DoorHinge.LEFT, true, VariantSettings.Rotation.R90, rightModelId);
.put(VariantSettings.MODEL, rightModelId)) fillStableDoorVariantMap(variantMap, targetHalf, DoorHinge.RIGHT, true, VariantSettings.Rotation.R270, leftModelId);
.register(Direction.SOUTH, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create() }
.put(VariantSettings.MODEL, rightModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R90))
.register(Direction.WEST, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create()
.put(VariantSettings.MODEL, rightModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R180))
.register(Direction.NORTH, targetHalf, DoorHinge.RIGHT, false, BlockStateVariant.create()
.put(VariantSettings.MODEL, rightModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R270))
.register(Direction.EAST, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() public static void fillStableDoorVariantMap(
.put(VariantSettings.MODEL, rightModelId) BlockStateVariantMap.QuadrupleProperty<Direction, DoubleBlockHalf, DoorHinge, Boolean> variantMap,
.put(VariantSettings.Y, VariantSettings.Rotation.R90)) DoubleBlockHalf targetHalf,
.register(Direction.SOUTH, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create() DoorHinge hinge, boolean open, VariantSettings.Rotation rotation,
.put(VariantSettings.MODEL, rightModelId) Identifier modelId) {
.put(VariantSettings.Y, VariantSettings.Rotation.R180))
.register(Direction.WEST, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create()
.put(VariantSettings.MODEL, rightModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R270))
.register(Direction.NORTH, targetHalf, DoorHinge.LEFT, true, BlockStateVariant.create()
.put(VariantSettings.MODEL, rightModelId))
.register(Direction.EAST, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() for (int i = 0; i < BlockRotation.DIRECTIONS.length; i++) {
.put(VariantSettings.MODEL, leftModelId) variantMap.register(BlockRotation.DIRECTIONS[i], targetHalf, hinge, open, BlockStateVariant.create()
.put(VariantSettings.Y, VariantSettings.Rotation.R270)) .put(VariantSettings.MODEL, modelId)
.register(Direction.SOUTH, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() .put(VariantSettings.Y, BlockRotation.cycle(rotation, i))
.put(VariantSettings.MODEL, leftModelId)) );
.register(Direction.WEST, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create() }
.put(VariantSettings.MODEL, leftModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R90))
.register(Direction.NORTH, targetHalf, DoorHinge.RIGHT, true, BlockStateVariant.create()
.put(VariantSettings.MODEL, leftModelId)
.put(VariantSettings.Y, VariantSettings.Rotation.R180));
} }
public void registerHiveBlock(Block hive) { public void registerHiveBlock(Block hive) {