[Feature] Slot-based complex Material for Stone

This commit is contained in:
Frank 2023-06-11 14:33:46 +02:00
parent c9e384304e
commit 8fddd5bb79
15 changed files with 486 additions and 43 deletions

View file

@ -0,0 +1,50 @@
package org.betterx.bclib.complexmaterials;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.behaviours.BehaviourBuilders;
import org.betterx.bclib.complexmaterials.entry.SlotMap;
import org.betterx.bclib.complexmaterials.set.stone.StoneSlots;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.material.MapColor;
public class StoneComplexMaterial extends ComplexMaterialSet<StoneComplexMaterial> {
public static final ResourceLocation MATERIAL_ID = BCLib.makeID("stone_material");
public final MapColor color;
public final Block sourceBlock;
protected StoneComplexMaterial(
String modID,
String baseName,
String receipGroupPrefix,
Block sourceBlock,
MapColor color
) {
super(modID, baseName, receipGroupPrefix);
this.color = color;
this.sourceBlock = sourceBlock;
}
@Override
protected BlockBehaviour.Properties getBlockSettings() {
return BehaviourBuilders.createStone(color);
}
@Override
public ResourceLocation getMaterialID() {
return MATERIAL_ID;
}
@Override
protected SlotMap<StoneComplexMaterial> createMaterialSlots() {
return SlotMap.of(
StoneSlots.SOURCE,
StoneSlots.SLAB,
StoneSlots.STAIRS,
StoneSlots.WALL
);
}
}

View file

@ -15,22 +15,33 @@ import java.util.function.BiFunction;
public class BlockEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, BlockBehaviour.Properties, Block> initFunction;
final boolean hasItem;
final boolean isPseudoEntry;
TagKey<Block>[] blockTags;
TagKey<Item>[] itemTags;
public BlockEntry(String suffix, BiFunction<ComplexMaterial, BlockBehaviour.Properties, Block> initFunction) {
this(suffix, true, initFunction);
this(suffix, true, false, initFunction);
}
public BlockEntry(
String suffix,
boolean hasItem,
BiFunction<ComplexMaterial, BlockBehaviour.Properties, Block> initFunction
) {
this(suffix, hasItem, false, initFunction);
}
public BlockEntry(
String suffix,
boolean hasItem,
boolean isPseudoEntry,
BiFunction<ComplexMaterial, BlockBehaviour.Properties, Block> initFunction
) {
super(suffix);
this.initFunction = initFunction;
this.hasItem = hasItem;
this.isPseudoEntry = isPseudoEntry;
}
@SafeVarargs
@ -49,17 +60,22 @@ public class BlockEntry extends ComplexMaterialEntry {
ResourceLocation location = getLocation(material.getModID(), material.getBaseName());
Block block = initFunction.apply(material, blockSettings);
if (block == null) return null;
if (!isPseudoEntry) {
if (hasItem) {
registry.register(location, block);
if (itemTags != null) {
TagManager.ITEMS.add(block.asItem(), itemTags);
}
} else {
registry.registerBlockOnly(location, block);
}
}
if (hasItem && itemTags != null) {
TagManager.ITEMS.add(block.asItem(), itemTags);
}
if (blockTags != null) {
TagManager.BLOCKS.add(block, blockTags);
}
return block;
}
}

View file

@ -0,0 +1,37 @@
package org.betterx.bclib.complexmaterials.set.common;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractSlab<M extends ComplexMaterial> extends SimpleMaterialSlot<M> {
public AbstractSlab() {
super("slab");
}
protected AbstractSlab(String prefix) {
super(prefix + "_slab");
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder
.crafting(id, parentMaterial.getBlock(suffix))
.setOutputCount(6)
.setShape("###")
.addMaterial('#', parentMaterial.getBlock(getSourceBlockSlot()))
.setGroup("slab")
.setCategory(RecipeCategory.BUILDING_BLOCKS)
.build();
}
@Nullable
protected abstract MaterialSlot<M> getSourceBlockSlot();
}

View file

@ -0,0 +1,37 @@
package org.betterx.bclib.complexmaterials.set.common;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractStairs<M extends ComplexMaterial> extends SimpleMaterialSlot<M> {
public AbstractStairs() {
super("stairs");
}
protected AbstractStairs(String prefix) {
super(prefix + "_stairs");
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder
.crafting(id, parentMaterial.getBlock(suffix))
.setOutputCount(4)
.setShape("# ", "## ", "###")
.addMaterial('#', parentMaterial.getBlock(getSourceBlockSlot()))
.setGroup("stairs")
.setCategory(RecipeCategory.BUILDING_BLOCKS)
.build();
}
@Nullable
protected abstract MaterialSlot<M> getSourceBlockSlot();
}

View file

@ -0,0 +1,35 @@
package org.betterx.bclib.complexmaterials.set.common;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.complexmaterials.set.stone.StoneSlots;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public abstract class AbstractWall<M extends ComplexMaterial> extends SimpleMaterialSlot<M> {
public AbstractWall() {
super("wall");
}
protected AbstractWall(@NotNull String postfix) {
super(postfix + "_wall");
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder.crafting(id, parentMaterial.getBlock(suffix))
.setOutputCount(6)
.setShape("###", "###")
.addMaterial('#', parentMaterial.getBlock(StoneSlots.SOURCE))
.setGroup("wall")
.build();
}
@Nullable
protected abstract MaterialSlot<M> getSourceBlockSlot();
}

View file

@ -0,0 +1,32 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.blocks.BaseBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class CrackedBlock extends SimpleMaterialSlot<StoneComplexMaterial> {
public CrackedBlock() {
super("cracked");
}
@Override
protected @NotNull Block createBlock(StoneComplexMaterial parentMaterial, BlockBehaviour.Properties settings) {
return new BaseBlock.Stone(settings);
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder.smelting(id, parentMaterial.getBlock(suffix))
.setPrimaryInputAndUnlock(parentMaterial.getBlock(StoneSlots.SOURCE))
.build(false, false, false);
}
}

View file

@ -0,0 +1,57 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.blocks.BaseSlabBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.set.common.AbstractSlab;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Slab extends AbstractSlab<StoneComplexMaterial> {
private final MaterialSlot<StoneComplexMaterial> base;
public Slab() {
super();
this.base = StoneSlots.SOURCE;
}
public Slab(MaterialSlot<StoneComplexMaterial> base) {
super(base.suffix);
this.base = base;
}
@Override
protected @NotNull Block createBlock(
StoneComplexMaterial parentMaterial, BlockBehaviour.Properties settings
) {
return new BaseSlabBlock.Stone(parentMaterial.getBlock(getSourceBlockSlot()));
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
super.makeRecipe(parentMaterial, id);
BCLRecipeBuilder
.stonecutting(
new ResourceLocation(id.getNamespace(), "stonecutter_" + id.getPath()),
parentMaterial.getBlock(suffix)
)
.setPrimaryInputAndUnlock(parentMaterial.getBlock(getSourceBlockSlot()))
.setOutputCount(2)
.setGroup("slab")
.build();
}
@Nullable
@Override
protected MaterialSlot<StoneComplexMaterial> getSourceBlockSlot() {
return base;
}
}

View file

@ -0,0 +1,25 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.BlockEntry;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.entry.RecipeEntry;
import java.util.function.Consumer;
public class Source extends MaterialSlot<StoneComplexMaterial> {
public Source() {
super("source");
}
@Override
public void addBlockEntry(StoneComplexMaterial parentMaterial, Consumer<BlockEntry> adder) {
adder.accept(new BlockEntry(suffix, true, true, (c, p) -> parentMaterial.sourceBlock));
}
@Override
public void addRecipeEntry(StoneComplexMaterial parentMaterial, Consumer<RecipeEntry> adder) {
}
}

View file

@ -0,0 +1,56 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.blocks.BaseStairsBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.set.common.AbstractStairs;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Stairs extends AbstractStairs<StoneComplexMaterial> {
private final MaterialSlot<StoneComplexMaterial> base;
public Stairs() {
super();
this.base = StoneSlots.SOURCE;
}
public Stairs(MaterialSlot<StoneComplexMaterial> base) {
super(base.suffix);
this.base = base;
}
@Override
protected @NotNull Block createBlock(
StoneComplexMaterial parentMaterial, BlockBehaviour.Properties settings
) {
return new BaseStairsBlock.Stone(parentMaterial.getBlock(getSourceBlockSlot()));
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
super.makeRecipe(parentMaterial, id);
BCLRecipeBuilder
.stonecutting(
new ResourceLocation(id.getNamespace(), "stonecutter_" + id.getPath()),
parentMaterial.getBlock(suffix)
)
.setPrimaryInputAndUnlock(parentMaterial.getBlock(getSourceBlockSlot()))
.setOutputCount(1)
.setGroup("stairs")
.build();
}
@Override
protected @Nullable MaterialSlot<StoneComplexMaterial> getSourceBlockSlot() {
return base;
}
}

View file

@ -0,0 +1,21 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
public class StoneSlots {
public static final MaterialSlot<StoneComplexMaterial> SOURCE = new Source();
public static final MaterialSlot<StoneComplexMaterial> SLAB = new Slab();
public static final MaterialSlot<StoneComplexMaterial> STAIRS = new Stairs();
public static final MaterialSlot<StoneComplexMaterial> WALL = new Wall();
public static final MaterialSlot<StoneComplexMaterial> CRACKED = new CrackedBlock();
public static final MaterialSlot<StoneComplexMaterial> CRACKED_SLAB = new Slab(CRACKED);
public static final MaterialSlot<StoneComplexMaterial> CRACKED_STAIRS = new Stairs(CRACKED);
public static final MaterialSlot<StoneComplexMaterial> CRACKED_WALL = new Wall(CRACKED);
public static final MaterialSlot<StoneComplexMaterial> WEATHERED = new WeatheredBlock();
public static final MaterialSlot<StoneComplexMaterial> WEATHERED_SLAB = new Slab(WEATHERED);
public static final MaterialSlot<StoneComplexMaterial> WEATHERED_STAIRS = new Stairs(WEATHERED);
public static final MaterialSlot<StoneComplexMaterial> WEATHERED_WALL = new Wall(WEATHERED);
}

View file

@ -0,0 +1,54 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.blocks.BaseWallBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.set.common.AbstractWall;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Wall extends AbstractWall<StoneComplexMaterial> {
private final MaterialSlot<StoneComplexMaterial> base;
public Wall() {
super();
this.base = StoneSlots.SOURCE;
}
public Wall(MaterialSlot<StoneComplexMaterial> base) {
super(base.suffix);
this.base = base;
}
@Override
protected @NotNull Block createBlock(StoneComplexMaterial parentMaterial, BlockBehaviour.Properties settings) {
return new BaseWallBlock.Stone(parentMaterial.getBlock(getSourceBlockSlot()));
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
super.makeRecipe(parentMaterial, id);
BCLRecipeBuilder
.stonecutting(
new ResourceLocation(id.getNamespace(), "stonecutter_" + id.getPath()),
parentMaterial.getBlock(suffix)
)
.setPrimaryInputAndUnlock(parentMaterial.getBlock(getSourceBlockSlot()))
.setOutputCount(1)
.setGroup("wall")
.build();
}
@Override
protected @Nullable MaterialSlot<StoneComplexMaterial> getSourceBlockSlot() {
return base;
}
}

View file

@ -0,0 +1,47 @@
package org.betterx.bclib.complexmaterials.set.stone;
import org.betterx.bclib.blocks.BaseBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.StoneComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class WeatheredBlock extends SimpleMaterialSlot<StoneComplexMaterial> {
public WeatheredBlock() {
super("weathered");
}
@Override
protected @NotNull Block createBlock(StoneComplexMaterial parentMaterial, BlockBehaviour.Properties settings) {
return new BaseBlock.Stone(settings);
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder.crafting(
new ResourceLocation(id.getNamespace(), id.getPath() + "_from_moss"),
parentMaterial.getBlock(suffix)
)
.shapeless()
.addMaterial('#', parentMaterial.getBlock(StoneSlots.SOURCE))
.addMaterial('+', Blocks.MOSS_BLOCK)
.build();
BCLRecipeBuilder.crafting(
new ResourceLocation(id.getNamespace(), id.getPath() + "_from_vine"),
parentMaterial.getBlock(suffix)
)
.shapeless()
.addMaterial('#', parentMaterial.getBlock(StoneSlots.SOURCE))
.addMaterial('+', Blocks.VINE)
.build();
}
}

View file

@ -1,23 +1,17 @@
package org.betterx.bclib.complexmaterials.set.wood;
import org.betterx.bclib.blocks.BaseSlabBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.WoodenComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.set.common.AbstractSlab;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Slab extends SimpleMaterialSlot<WoodenComplexMaterial> {
public Slab() {
super("slab");
}
public class Slab extends AbstractSlab<WoodenComplexMaterial> {
@Override
protected @NotNull Block createBlock(
@ -26,15 +20,9 @@ public class Slab extends SimpleMaterialSlot<WoodenComplexMaterial> {
return new BaseSlabBlock.Wood(parentMaterial.getBlock(WoodSlots.PLANKS), !parentMaterial.woodType.flammable);
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder
.crafting(id, parentMaterial.getBlock(suffix))
.setOutputCount(6)
.setShape("###")
.addMaterial('#', parentMaterial.getBlock(WoodSlots.PLANKS))
.setGroup("slab")
.setCategory(RecipeCategory.BUILDING_BLOCKS)
.build();
protected @Nullable MaterialSlot<WoodenComplexMaterial> getSourceBlockSlot() {
return WoodSlots.PLANKS;
}
}

View file

@ -1,23 +1,17 @@
package org.betterx.bclib.complexmaterials.set.wood;
import org.betterx.bclib.blocks.BaseStairsBlock;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.complexmaterials.WoodenComplexMaterial;
import org.betterx.bclib.complexmaterials.entry.SimpleMaterialSlot;
import org.betterx.bclib.recipes.BCLRecipeBuilder;
import org.betterx.bclib.complexmaterials.entry.MaterialSlot;
import org.betterx.bclib.complexmaterials.set.common.AbstractStairs;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockBehaviour;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Stairs extends SimpleMaterialSlot<WoodenComplexMaterial> {
public Stairs() {
super("stairs");
}
public class Stairs extends AbstractStairs<WoodenComplexMaterial> {
@Override
protected @NotNull Block createBlock(
@ -27,14 +21,7 @@ public class Stairs extends SimpleMaterialSlot<WoodenComplexMaterial> {
}
@Override
protected @Nullable void makeRecipe(ComplexMaterial parentMaterial, ResourceLocation id) {
BCLRecipeBuilder
.crafting(id, parentMaterial.getBlock(suffix))
.setOutputCount(4)
.setShape("# ", "## ", "###")
.addMaterial('#', parentMaterial.getBlock(WoodSlots.PLANKS))
.setGroup("stairs")
.setCategory(RecipeCategory.BUILDING_BLOCKS)
.build();
protected @Nullable MaterialSlot<WoodenComplexMaterial> getSourceBlockSlot() {
return WoodSlots.PLANKS;
}
}

View file

@ -34,6 +34,7 @@ public class WoodSlots {
public static final MaterialSlot<WoodenComplexMaterial> TABURET = new Taburet();
public static final MaterialSlot<WoodenComplexMaterial> CHAIR = new Chair();
public static final MaterialSlot<WoodenComplexMaterial> BAR_STOOL = new BarStool();
public static final MaterialSlot<WoodenComplexMaterial> WALL = new Wall();
}