+ flag
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package ovh.glitchlabs.ornamentum.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
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.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)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext context) {
|
||||
return this.defaultBlockState()
|
||||
.setValue(FACING, context.getHorizontalDirection().getOpposite());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState state, Rotation rotation) {
|
||||
return state.setValue(
|
||||
FACING,
|
||||
rotation.rotate(state.getValue(FACING))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected com.mojang.serialization.MapCodec<? extends HorizontalDirectionalBlock> codec() {
|
||||
return simpleCodec(FlagBlock::new);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@ public class ModBlocks {
|
||||
public static final DeferredRegister.Blocks BLOCKS =
|
||||
DeferredRegister.createBlocks(Ornamentum.MODID);
|
||||
|
||||
public static final DeferredBlock<Block> TEST_FLAG = registerBlock("test_flag",
|
||||
() -> new FlagBlock(BlockBehaviour.Properties.of().strength(1.0f)));
|
||||
|
||||
// Pattern Blocks
|
||||
|
||||
public static final DeferredBlock<Block> WHITE_PATTERN_BLOCK = registerBlock("white_pattern_block",
|
||||
|
||||
@@ -17,6 +17,9 @@ public class ModBlockLootTableProvider extends BlockLootSubProvider {
|
||||
@Override
|
||||
protected void generate() {
|
||||
|
||||
dropSelf(ModBlocks.TEST_FLAG.get());
|
||||
|
||||
|
||||
dropSelf(ModBlocks.RED_PATTERN_BLOCK.get());
|
||||
dropSelf(ModBlocks.RED_PATTERN_BLOCK_STAIRS.get());
|
||||
dropSelf(ModBlocks.RED_PATTERN_BLOCK_SLAB.get());
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package ovh.glitchlabs.ornamentum.datagen;
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.neoforged.neoforge.client.model.generators.BlockStateProvider;
|
||||
import net.neoforged.neoforge.client.model.generators.ConfiguredModel;
|
||||
import net.neoforged.neoforge.client.model.generators.ModelFile;
|
||||
import net.neoforged.neoforge.common.data.ExistingFileHelper;
|
||||
import net.neoforged.neoforge.registries.DeferredBlock;
|
||||
@@ -16,6 +19,9 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
||||
@Override
|
||||
protected void registerStatesAndModels() {
|
||||
|
||||
// FLAGS
|
||||
createFlag(ModBlocks.TEST_FLAG, "test_flag");
|
||||
|
||||
blockWithItem(ModBlocks.WHITE_PATTERN_BLOCK);
|
||||
createStairsAndSlab(ModBlocks.WHITE_PATTERN_BLOCK_STAIRS, ModBlocks.WHITE_PATTERN_BLOCK_SLAB, "white_pattern_block");
|
||||
|
||||
@@ -318,8 +324,41 @@ public class ModBlockStateProvider extends BlockStateProvider {
|
||||
simpleBlockWithItem(deferredBlock.get(), model);
|
||||
}
|
||||
|
||||
private void paneModelWithItem(DeferredBlock<?> deferredBlock, String textureName) {
|
||||
simpleBlockWithItem(deferredBlock.get(), models().withExistingParent(deferredBlock.getId().getPath(), mcLoc("block/thin_block"))
|
||||
.texture("texture", modLoc("block/" + textureName)));
|
||||
private void createFlag(DeferredBlock<?> block, String textureName) {
|
||||
|
||||
String name = block.getId().getPath();
|
||||
|
||||
ModelFile model = models()
|
||||
.withExistingParent(
|
||||
name,
|
||||
modLoc("block/template_flag")
|
||||
)
|
||||
.texture(
|
||||
"2",
|
||||
modLoc("block/flags/" + textureName)
|
||||
);
|
||||
|
||||
|
||||
getVariantBuilder(block.get())
|
||||
.forAllStates(state -> {
|
||||
Direction direction = state.getValue(HorizontalDirectionalBlock.FACING);
|
||||
|
||||
return ConfiguredModel.builder()
|
||||
.modelFile(model)
|
||||
.rotationY(switch (direction) {
|
||||
case NORTH -> 0;
|
||||
case EAST -> 90;
|
||||
case SOUTH -> 180;
|
||||
case WEST -> 270;
|
||||
default -> 0;
|
||||
})
|
||||
.build();
|
||||
});
|
||||
|
||||
|
||||
simpleBlockItem(
|
||||
block.get(),
|
||||
model
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user