diff --git a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockBase.java b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockBase.java index 302da44..10b6a53 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockBase.java +++ b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockBase.java @@ -42,7 +42,7 @@ protected BlockState getPlacementState(BlockPlaceContext context) { * Create the blockstate. Override whenever we have a custom blockstate available on a block. * @param builder */ - protected void createBlockState(StateDefinition.Builder builder) {} + protected void createBlockState(StateDefinition.Builder builder) {} /** * Get which shape should be used for the block. Override when blocks don't have a standard full cube. @@ -127,7 +127,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player } @Override - public void createBlockStateDefinition(StateDefinition.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { createBlockState(builder); } } diff --git a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorative.java b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorative.java index 887eab6..70c6092 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorative.java +++ b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorative.java @@ -12,8 +12,8 @@ public class MetroBlockDecorative extends MetroBlockBase { private final VoxelShape BLOCK_SHAPE; - private TextureSet[] _resources; - private String _modelName; + protected TextureSet[] _resources; + protected String _modelName; public MetroBlockDecorative(Properties props, String modelName, ResourceLocation resource) { this(props, 16, 16, modelName, new TextureSet("texture", resource)); diff --git a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatable.java b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatable.java index 33c52f9..d43dacd 100644 --- a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatable.java +++ b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatable.java @@ -1,51 +1,55 @@ package com.fureniku.metropolis.blocks; import com.fureniku.metropolis.datagen.MetroBlockStateProvider; +import com.fureniku.metropolis.datagen.TextureSet; +import com.fureniku.metropolis.utils.Debug; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; +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.state.properties.BooleanProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.phys.shapes.VoxelShape; +import net.neoforged.neoforge.client.model.generators.BlockModelBuilder; import net.neoforged.neoforge.registries.RegistryObject; -public class MetroBlockDecorativeRotatable extends MetroBlockBase { +/** + * Decorative non-full block which can be rotated + */ +public class MetroBlockDecorativeRotatable extends MetroBlockDecorative { - protected static final DirectionProperty DIRECTION = DirectionProperty.create("rotation", Direction.Plane.HORIZONTAL); + protected static final DirectionProperty DIRECTION = HorizontalDirectionalBlock.FACING; private final VoxelShape BLOCK_SHAPE; - public MetroBlockDecorativeRotatable(Properties props) { - this(props, 16, 16); - } - - public MetroBlockDecorativeRotatable(Properties props, float height) { - this(props, height, 16); - } - - public MetroBlockDecorativeRotatable(Properties props, float height, float width) { - this(props, width, height, width); - } - - public MetroBlockDecorativeRotatable(Properties props, VoxelShape shape) { - super(props); + /** + * Constructor for decorative blocks which have a specific shape. This shape is rotated automatically. + * @param props + * @param shape + */ + public MetroBlockDecorativeRotatable(Properties props, VoxelShape shape, String modelName, TextureSet... textures) { + super(props, modelName, textures); BLOCK_SHAPE = shape; - this.registerDefaultState(this.defaultBlockState().setValue(DIRECTION, Direction.NORTH)); - } - - public MetroBlockDecorativeRotatable(Properties props, float sizeX, float sizeY, float sizeZ) { - super(props); - float insetX = (16-sizeX)/2; - float insetZ = (16-sizeZ)/2; - BLOCK_SHAPE = Block.box(insetX, 0, insetZ, 16-insetX, 16-sizeY, 16-insetZ); - this.registerDefaultState(this.defaultBlockState().setValue(DIRECTION, Direction.NORTH)); + this.registerDefaultState(this.stateDefinition.any().setValue(DIRECTION, Direction.NORTH)); } @Override public void generateBlockState(RegistryObject blockRegistryObject, MetroBlockStateProvider blockStateProvider) { - blockStateProvider.simpleBlockWithItem(blockRegistryObject.get()); + Block block = blockRegistryObject.get(); + BlockModelBuilder bmb; + if (_modelName == null || _resources == null) { + bmb = blockStateProvider.getModelFilesWithTexture(block, "", "blocks/decorative/" + block.getName(), blockStateProvider.modLoc("blocks/decorative/" + block.getName())); + } else { + bmb = blockStateProvider.getModelFilesWithTexture(block, "", "blocks/decorative/" + _modelName, _resources[0].getTexture()); + if (_resources.length > 1) { + for (int i = 1; i < _resources.length; i++) { + bmb = bmb.texture(_resources[i].getKey(), _resources[i].getTexture()); + } + } + } + blockStateProvider.horizontalBlock(block, bmb); } @Override @@ -55,7 +59,12 @@ protected BlockState getPlacementState(BlockPlaceContext context) { } @Override - protected void createBlockState(StateDefinition.Builder builder) { + protected void createBlockState(StateDefinition.Builder builder) { builder.add(DIRECTION); } + + @Override + protected VoxelShape getShapeFromBlockState(BlockState pState) { + return BLOCK_SHAPE; + } } diff --git a/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatableBuilder.java b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatableBuilder.java new file mode 100644 index 0000000..9b52b38 --- /dev/null +++ b/src/main/java/com/fureniku/metropolis/blocks/MetroBlockDecorativeRotatableBuilder.java @@ -0,0 +1,61 @@ +package com.fureniku.metropolis.blocks; + +import com.fureniku.metropolis.datagen.TextureSet; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockBehaviour; +import net.minecraft.world.phys.shapes.VoxelShape; + +public class MetroBlockDecorativeRotatableBuilder { + + private BlockBehaviour.Properties props; + private VoxelShape blockShape = Block.box(0, 0, 0, 16, 16, 16); + private String modelName = null; + private TextureSet[] textures = null; + + public MetroBlockDecorativeRotatableBuilder setProps(BlockBehaviour.Properties props) { + this.props = props; + return this; + } + + public MetroBlockDecorativeRotatableBuilder setHeight(float height) { + return setShape(16, height, 16); + } + + public MetroBlockDecorativeRotatableBuilder setWidth(float width) { + return setShape(width, 16, width); + } + + public MetroBlockDecorativeRotatableBuilder setShape(float width, float height) { + return setShape(width, height, width); + } + + public MetroBlockDecorativeRotatableBuilder setShape(float width, float height, float depth) { + float insetX = (16-width)/2; + float insetZ = (16-depth)/2; + return setShape(Block.box(insetX, 0, insetZ, 16-insetX, 16-height, 16-insetZ)); + } + + public MetroBlockDecorativeRotatableBuilder setShape(VoxelShape shape) { + this.blockShape = shape; + return this; + } + + public MetroBlockDecorativeRotatableBuilder setModelName(String modelName) { + this.modelName = modelName; + return this; + } + + public MetroBlockDecorativeRotatableBuilder setTextures(TextureSet... textures) { + this.textures = textures; + return this; + } + + public MetroBlockDecorativeRotatableBuilder setTextures(ResourceLocation resource) { + return setTextures(new TextureSet("texture", resource)); + } + + public MetroBlockDecorativeRotatable build() { + return new MetroBlockDecorativeRotatable(props, blockShape, modelName, textures); + } +} \ No newline at end of file diff --git a/src/main/java/com/fureniku/metropolis/datagen/MetroBlockStateProvider.java b/src/main/java/com/fureniku/metropolis/datagen/MetroBlockStateProvider.java index d897a7c..0ea2dd3 100644 --- a/src/main/java/com/fureniku/metropolis/datagen/MetroBlockStateProvider.java +++ b/src/main/java/com/fureniku/metropolis/datagen/MetroBlockStateProvider.java @@ -5,14 +5,15 @@ import net.minecraft.data.PackOutput; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; -import net.neoforged.neoforge.client.model.generators.BlockModelBuilder; -import net.neoforged.neoforge.client.model.generators.BlockStateProvider; -import net.neoforged.neoforge.client.model.generators.ItemModelBuilder; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; +import net.neoforged.neoforge.client.model.generators.*; import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.neoforged.neoforge.registries.ForgeRegistries; import net.neoforged.neoforge.registries.RegistryObject; import java.util.Collection; +import java.util.function.Function; /** * Metropolis Block State Provider @@ -39,6 +40,10 @@ public void simpleBlockWithItem(Block block) { simpleBlockWithItem(block, cubeAll(block)); } + public void horizontalBlock(Block block, ModelFile model) { + horizontalBlock(block, model, 180); + } + /** * Get a modelled block, with a matching itemblock. Uses your blocks name to get the matching texture. * @param block Your block