Skip to content

Commit

Permalink
Option to create instances using builders - good for subclasses
Browse files Browse the repository at this point in the history
  • Loading branch information
Fureniku committed Dec 2, 2023
1 parent 6690942 commit 463a2a1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public MetroBlockDecorative(Properties props, VoxelShape shape, String modelName
_modelName = modelName;
}

public MetroBlockDecorative(MetroBlockDecorativeBuilder builder) {
this(builder.getProps(), builder.getShape(), builder.getModelName(), builder.getTextures());
}

@Override
protected VoxelShape getShapeFromBlockState(BlockState pState) {
return BLOCK_SHAPE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fureniku.metropolis.datagen.TextureSet;
import com.fureniku.metropolis.enums.DecorativeBuilderType;
import com.fureniku.metropolis.enums.ToggleType;
import com.fureniku.metropolis.utils.Debug;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
Expand Down Expand Up @@ -99,6 +98,21 @@ public MetroBlockDecorativeBuilder setLit() {
return this;
}

public MetroBlockDecorativeBuilder get() { return this; }
public BlockBehaviour.Properties getProps() { return _props; }
public VoxelShape getShape() { return _blockShape; }
public VoxelShape getShapeToggled() { return _toggledBlockShape; }
public String getModelName() { return _modelName; }
public String getToggledModelName() { return _toggledModelName; }
public ToggleType getToggleType() { return _toggleType; }
public Item getToggleItem() { return _toggleItem; }
public TextureSet[] getTextures() { return _textures; }

/**
* Internal level build function. Fine to use for any blocks which can just use the metro base classes directly.
* If you are making a derived block, create the builder instance as a separate object and pass it through the super
* @return The created block instance
*/
public MetroBlockDecorative build() {
switch (_type) {
case DECORATIVE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public MetroBlockDecorativeRotatable(Properties props, VoxelShape shape, String
this.registerDefaultState(this.stateDefinition.any().setValue(DIRECTION, Direction.NORTH));
}

public MetroBlockDecorativeRotatable(MetroBlockDecorativeBuilder builder) {
this(builder.getProps(), builder.getShape(), builder.getModelName(), builder.getTextures());
}

@Override
public void generateBlockState(RegistryObject<Block> blockRegistryObject, MetroBlockStateProvider blockStateProvider) {
Block block = blockRegistryObject.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ public MetroBlockDecorativeRotatableToggle(Properties props, VoxelShape shape, V
_item = item;
}

public MetroBlockDecorativeRotatableToggle(MetroBlockDecorativeBuilder builder, Item item) {
this(builder.getProps(), builder.getShape(), builder.getShapeToggled(), builder.getModelName(), builder.getToggledModelName(), item, builder.getTextures());
}

public MetroBlockDecorativeRotatableToggle(MetroBlockDecorativeBuilder builder) {
this(builder.getProps(), builder.getShape(), builder.getShapeToggled(), builder.getModelName(), builder.getToggledModelName(), builder.getToggleType(), builder.getTextures());
}

/**
* Constructor for decorative blocks which have a specific shape. This shape is rotated automatically.
* @param props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public MetroBlockDecorativeToggle(Properties props, VoxelShape shape, VoxelShape
_item = item;
}

public MetroBlockDecorativeToggle(MetroBlockDecorativeBuilder builder, Item item) {
this(builder.getProps(), builder.getShape(), builder.getShapeToggled(), builder.getModelName(), builder.getToggledModelName(), item, builder.getTextures());
}

public MetroBlockDecorativeToggle(MetroBlockDecorativeBuilder builder) {
this(builder.getProps(), builder.getShape(), builder.getShapeToggled(), builder.getModelName(), builder.getToggledModelName(), builder.getToggleType(), builder.getTextures());
}

public MetroBlockDecorativeToggle(Properties props, VoxelShape shape, VoxelShape toggledShape, String modelName, String toggledModelName, ToggleType type, TextureSet... textures) {
super(props, shape, modelName, textures);
BLOCK_SHAPE = shape;
Expand Down

0 comments on commit 463a2a1

Please sign in to comment.