+ wall/ceiling Flags
hit box fix
This commit is contained in:
@@ -2,61 +2,100 @@ package ovh.glitchlabs.ornamentum.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.properties.AttachFace;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
|
||||
public class FlagBlock extends HorizontalDirectionalBlock {
|
||||
|
||||
private static final VoxelShape SHAPE = Shapes.or(
|
||||
Block.box(7, 0, 7, 9, 16, 9)
|
||||
);
|
||||
|
||||
public FlagBlock(Properties properties) {
|
||||
super(properties);
|
||||
|
||||
this.registerDefaultState(
|
||||
this.stateDefinition.any()
|
||||
.setValue(FACING, Direction.NORTH)
|
||||
);
|
||||
this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(BlockStateProperties.ATTACH_FACE, AttachFace.FLOOR));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
protected void createBlockStateDefinition(
|
||||
StateDefinition.Builder<Block, BlockState> builder
|
||||
) {
|
||||
builder.add(
|
||||
FACING,
|
||||
BlockStateProperties.ATTACH_FACE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
|
||||
Direction clickedFace = context.getClickedFace();
|
||||
|
||||
AttachFace face;
|
||||
|
||||
if (clickedFace == Direction.UP) {
|
||||
face = AttachFace.FLOOR;
|
||||
}
|
||||
else if (clickedFace == Direction.DOWN) {
|
||||
face = AttachFace.CEILING;
|
||||
}
|
||||
else {
|
||||
face = AttachFace.WALL;
|
||||
}
|
||||
return this.defaultBlockState()
|
||||
.setValue(BlockStateProperties.ATTACH_FACE, face)
|
||||
.setValue(FACING, context.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
AttachFace face =
|
||||
state.getValue(BlockStateProperties.ATTACH_FACE);
|
||||
|
||||
Direction facing =
|
||||
state.getValue(FACING);
|
||||
|
||||
|
||||
return switch (face) {
|
||||
|
||||
case FLOOR -> switch (facing) {
|
||||
case NORTH, SOUTH -> Block.box(7, 0, 7, 9, 16, 9);
|
||||
case EAST, WEST -> Block.box(7, 0, 7, 9, 16, 9);
|
||||
default -> Block.box(7, 0, 7, 9, 16, 9);
|
||||
};
|
||||
|
||||
case WALL -> switch (facing) {
|
||||
case NORTH -> Block.box(7, 5, 9, 9, 16, 16);
|
||||
case SOUTH -> Block.box(7, 5, 0, 9, 16, 7);
|
||||
case WEST -> Block.box(9, 5, 7, 16, 16, 9);
|
||||
case EAST -> Block.box(0, 5, 7, 7, 16, 9);
|
||||
default -> Block.box(7, 5, 9, 9, 16, 16);
|
||||
};
|
||||
|
||||
case CEILING -> switch (facing) {
|
||||
case NORTH, SOUTH -> Block.box(0, 10, 7, 16, 16, 9);
|
||||
case EAST, WEST -> Block.box(7, 10, 0, 9, 16, 16);
|
||||
default -> Block.box(7, 10, 7, 9, 16, 9);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return state.setValue(
|
||||
FACING,
|
||||
rotation.rotate(state.getValue(FACING))
|
||||
return state.setValue(FACING, rotation.rotate(state.getValue(FACING))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected com.mojang.serialization.MapCodec<? extends HorizontalDirectionalBlock> codec() {
|
||||
return simpleCodec(FlagBlock::new);
|
||||
|
||||
@@ -2,7 +2,10 @@ package ovh.glitchlabs.ornamentum.datagen;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.world.level.block.FaceAttachedHorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.state.properties.AttachFace;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
|
||||
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
|
||||
import net.neoforged.neoforge.client.model.generators.ModelFile;
|
||||
@@ -386,37 +389,74 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
||||
|
||||
String name = block.getId().getPath();
|
||||
|
||||
ModelFile model = models()
|
||||
.withExistingParent(
|
||||
name,
|
||||
modLoc("block/template_flag")
|
||||
)
|
||||
.texture(
|
||||
"2",
|
||||
modLoc("block/flags/" + textureName)
|
||||
);
|
||||
|
||||
ModelFile floor =
|
||||
models()
|
||||
.withExistingParent(
|
||||
name,
|
||||
modLoc("block/template_flag")
|
||||
)
|
||||
.texture(
|
||||
"2",
|
||||
modLoc("block/flags/" + textureName)
|
||||
);
|
||||
|
||||
|
||||
ModelFile wall =
|
||||
models()
|
||||
.withExistingParent(
|
||||
name + "_wall",
|
||||
modLoc("block/template_flag_wall")
|
||||
)
|
||||
.texture(
|
||||
"2",
|
||||
modLoc("block/flags/" + textureName)
|
||||
);
|
||||
|
||||
|
||||
ModelFile ceiling =
|
||||
models()
|
||||
.withExistingParent(
|
||||
name + "_ceiling",
|
||||
modLoc("block/template_flag_ceiling")
|
||||
)
|
||||
.texture(
|
||||
"2",
|
||||
modLoc("block/flags/" + textureName)
|
||||
);
|
||||
|
||||
getVariantBuilder(block.get())
|
||||
.forAllStates(state -> {
|
||||
Direction direction = state.getValue(HorizontalDirectionalBlock.FACING);
|
||||
Direction direction =
|
||||
state.getValue(HorizontalDirectionalBlock.FACING);
|
||||
|
||||
AttachFace face =
|
||||
state.getValue(
|
||||
BlockStateProperties.ATTACH_FACE
|
||||
);
|
||||
|
||||
ModelFile model = switch (face) {
|
||||
case WALL -> wall;
|
||||
case CEILING -> ceiling;
|
||||
default -> floor;
|
||||
};
|
||||
|
||||
|
||||
return ConfiguredModel.builder()
|
||||
.modelFile(model)
|
||||
.rotationY(switch (direction) {
|
||||
case NORTH -> 0;
|
||||
case EAST -> 90;
|
||||
case SOUTH -> 180;
|
||||
case WEST -> 270;
|
||||
default -> 0;
|
||||
})
|
||||
.build();
|
||||
.rotationY(
|
||||
switch(direction) {
|
||||
case NORTH -> 0;
|
||||
case EAST -> 90;
|
||||
case SOUTH -> 180;
|
||||
case WEST -> 270;
|
||||
default -> 0;
|
||||
}
|
||||
).build();
|
||||
});
|
||||
|
||||
|
||||
simpleBlockItem(
|
||||
block.get(),
|
||||
model
|
||||
floor
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user