Reorganized Imports/Packages

This commit is contained in:
Frank 2022-05-18 23:56:23 +02:00
parent cb9459f176
commit 3ee10482ab
721 changed files with 34873 additions and 33558 deletions

View file

@ -0,0 +1,370 @@
package org.betterx.bclib.complexmaterials;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.betterx.bclib.api.tag.TagAPI;
import org.betterx.bclib.complexmaterials.entry.BlockEntry;
import org.betterx.bclib.complexmaterials.entry.ItemEntry;
import org.betterx.bclib.complexmaterials.entry.RecipeEntry;
import org.betterx.bclib.config.PathConfig;
import org.betterx.bclib.registry.BlockRegistry;
import org.betterx.bclib.registry.ItemRegistry;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
public abstract class ComplexMaterial {
private static final Map<ResourceLocation, List<RecipeEntry>> RECIPE_ENTRIES = Maps.newHashMap();
private static final Map<ResourceLocation, List<BlockEntry>> BLOCK_ENTRIES = Maps.newHashMap();
private static final Map<ResourceLocation, List<ItemEntry>> ITEM_ENTRIES = Maps.newHashMap();
private static final List<ComplexMaterial> MATERIALS = Lists.newArrayList();
private final List<RecipeEntry> defaultRecipeEntries = Lists.newArrayList();
private final List<BlockEntry> defaultBlockEntries = Lists.newArrayList();
private final List<ItemEntry> defaultItemEntries = Lists.newArrayList();
private final Map<String, TagKey<Block>> blockTags = Maps.newHashMap();
private final Map<String, TagKey<Item>> itemTags = Maps.newHashMap();
private final Map<String, Block> blocks = Maps.newHashMap();
private final Map<String, Item> items = Maps.newHashMap();
protected final String baseName;
protected final String modID;
protected final String receipGroupPrefix;
public ComplexMaterial(String modID, String baseName, String receipGroupPrefix) {
this.baseName = baseName;
this.modID = modID;
this.receipGroupPrefix = receipGroupPrefix;
MATERIALS.add(this);
}
/**
* Initialize and registers all content inside material, return material itself.
*
* @param blocksRegistry {@link BlockRegistry} instance to add blocks in;
* @param itemsRegistry {@link ItemRegistry} instance to add items in;
* @param recipeConfig {@link PathConfig} for recipes check.
* @return {@link ComplexMaterial}.
*/
public ComplexMaterial init(BlockRegistry blocksRegistry, ItemRegistry itemsRegistry, PathConfig recipeConfig) {
initTags();
final FabricBlockSettings blockSettings = getBlockSettings();
final FabricItemSettings itemSettings = getItemSettings(itemsRegistry);
initDefault(blockSettings, itemSettings);
getBlockEntries().forEach(entry -> {
Block block = entry.init(this, blockSettings, blocksRegistry);
blocks.put(entry.getSuffix(), block);
});
getItemEntries().forEach(entry -> {
Item item = entry.init(this, itemSettings, itemsRegistry);
items.put(entry.getSuffix(), item);
});
initDefaultRecipes();
getRecipeEntries().forEach(entry -> {
entry.init(this, recipeConfig);
});
initFlammable(FlammableBlockRegistry.getDefaultInstance());
return this;
}
/**
* Init default content for {@link ComplexMaterial} - blocks and items.
*
* @param blockSettings {@link FabricBlockSettings} default block settings for this material;
* @param itemSettings {@link FabricItemSettings} default item settings for this material.
*/
protected abstract void initDefault(FabricBlockSettings blockSettings, FabricItemSettings itemSettings);
/**
* Init custom tags for this {@link ComplexMaterial}, not required.
*/
protected void initTags() {
}
/**
* Init default recipes for this {@link ComplexMaterial}, not required.
*/
protected void initDefaultRecipes() {
}
/**
* Allows to add blocks into Fabric {@link FlammableBlockRegistry} for this {@link ComplexMaterial}, not required.
*/
protected void initFlammable(FlammableBlockRegistry registry) {
}
/**
* Adds custom block tag for this {@link ComplexMaterial}, tag can be created with {@link TagAPI} or you can use one of already created tags.
*
* @param tag {@link TagKey} for {@link Block}
*/
protected void addBlockTag(TagKey<Block> tag) {
String key = tag.location().getPath().replace(getBaseName() + "_", "");
blockTags.put(key, tag);
}
/**
* Adds custom item tag for this {@link ComplexMaterial}, tag can be created with {@link TagAPI} or you can use one of already created tags.
*
* @param tag {@link TagKey} for {@link Item}
*/
protected void addItemTag(TagKey<Item> tag) {
String key = tag.location().getPath().replace(getBaseName() + "_", "");
itemTags.put(key, tag);
}
/**
* Get custom {@link Block} {@link TagKey} from this {@link ComplexMaterial}.
*
* @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix.
* @return {@link TagKey} for {@link Block} or {@code null} if nothing is stored.
*/
@Nullable
public TagKey<Block> getBlockTag(String key) {
return blockTags.get(key);
}
/**
* Get custom {@link Item} {@link TagKey} from this {@link ComplexMaterial}.
*
* @param key {@link String} tag name (path of its {@link ResourceLocation}), for inner tags created inside material its tag suffix.
* @return {@link TagKey} for {@link Item} or {@code null} if nothing is stored.
*/
@Nullable
public TagKey<Item> getItemTag(String key) {
return itemTags.get(key);
}
/**
* Get initiated {@link Block} from this {@link ComplexMaterial}.
*
* @param key {@link String} block name suffix (example: "mod:custom_log" will have a "log" suffix if "custom" is a base name of this material)
* @return {@link Block} or {@code null} if nothing is stored.
*/
@Nullable
public Block getBlock(String key) {
return blocks.get(key);
}
/**
* Get initiated {@link Item} from this {@link ComplexMaterial}.
*
* @param key {@link String} block name suffix (example: "mod:custom_apple" will have a "apple" suffix if "custom" is a base name of this material)
* @return {@link Item} or {@code null} if nothing is stored.
*/
@Nullable
public Item getItem(String key) {
return items.get(key);
}
/**
* Get default block settings for this material.
*
* @return {@link FabricBlockSettings}
*/
protected abstract FabricBlockSettings getBlockSettings();
/**
* Get default item settings for this material.
*
* @return {@link FabricItemSettings}
*/
protected FabricItemSettings getItemSettings(ItemRegistry registry) {
return registry.makeItemSettings();
}
private Collection<BlockEntry> getBlockEntries() {
List<BlockEntry> result = Lists.newArrayList(defaultBlockEntries);
List<BlockEntry> entries = BLOCK_ENTRIES.get(this.getMaterialID());
if (entries != null) {
result.addAll(entries);
}
return result;
}
private Collection<ItemEntry> getItemEntries() {
List<ItemEntry> result = Lists.newArrayList(defaultItemEntries);
List<ItemEntry> entries = ITEM_ENTRIES.get(this.getMaterialID());
if (entries != null) {
result.addAll(entries);
}
return result;
}
private Collection<RecipeEntry> getRecipeEntries() {
List<RecipeEntry> result = Lists.newArrayList(defaultRecipeEntries);
List<RecipeEntry> entries = RECIPE_ENTRIES.get(this.getMaterialID());
if (entries != null) {
result.addAll(entries);
}
return result;
}
/**
* Get base name of this {@link ComplexMaterial}.
*
* @return {@link String} name
*/
public String getBaseName() {
return baseName;
}
/**
* Get mod ID for this {@link ComplexMaterial}.
*
* @return {@link String} mod ID.
*/
public String getModID() {
return modID;
}
/**
* Get a unique {@link ResourceLocation} for each material class.
* For example WoodenComplexMaterial will have a "bclib:Wooden_Complex_Material" {@link ResourceLocation}.
* This is used to add custom entries before mods init using Fabric "preLaunch" entry point.
*
* @return {@link ResourceLocation} for this material
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public abstract ResourceLocation getMaterialID();
/**
* Get all initiated block from this {@link ComplexMaterial}.
*
* @return {@link Collection} of {@link Block}.
*/
public Collection<Block> getBlocks() {
return blocks.values();
}
/**
* Get all initiated items from this {@link ComplexMaterial}.
*
* @return {@link Collection} of {@link Item}.
*/
public Collection<Item> getItems() {
return items.values();
}
/**
* Adds a default {@link BlockEntry} to this {@link ComplexMaterial}. Used to initiate blocks later.
*
* @param entry {@link BlockEntry}
*/
protected void addBlockEntry(BlockEntry entry) {
defaultBlockEntries.add(entry);
}
/**
* Replaces or Adds a default {@link BlockEntry} to this {@link ComplexMaterial}. Used to initiate blocks later.
* <p>
* If this {@link ComplexMaterial} does already contain an entry for the {@link ResourceLocation}, the entry will
* be removed first.
*
* @param entry {@link BlockEntry}
*/
protected void replaceOrAddBlockEntry(BlockEntry entry) {
int pos = defaultBlockEntries.indexOf(entry);
if (pos >= 0) defaultBlockEntries.remove(entry);
addBlockEntry(entry);
}
/**
* Adds a default {@link ItemEntry} to this {@link ComplexMaterial}. Used to initiate items later.
*
* @param entry {@link ItemEntry}
*/
protected void addItemEntry(ItemEntry entry) {
defaultItemEntries.add(entry);
}
/**
* Adds a default {@link RecipeEntry} to this {@link ComplexMaterial}. Used to initiate items later.
*
* @param entry {@link RecipeEntry}
*/
protected void addRecipeEntry(RecipeEntry entry) {
defaultRecipeEntries.add(entry);
}
/**
* Adds a custom {@link BlockEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}.
* Used to add custom entry for all instances of {@link ComplexMaterial}.
* Should be called only using Fabric "preLaunch" entry point.
*
* @param materialName {@link ResourceLocation} id of {@link ComplexMaterial};
* @param entry {@link BlockEntry}.
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addBlockEntry(ResourceLocation materialName, BlockEntry entry) {
List<BlockEntry> entries = BLOCK_ENTRIES.get(materialName);
if (entries == null) {
entries = Lists.newArrayList();
BLOCK_ENTRIES.put(materialName, entries);
}
entries.add(entry);
}
/**
* Adds a custom {@link ItemEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}.
* Used to add custom entry for all instances of {@link ComplexMaterial}.
* Should be called only using Fabric "preLaunch" entry point.
*
* @param materialName {@link ResourceLocation} id of {@link ComplexMaterial};
* @param entry {@link ItemEntry}.
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addItemEntry(ResourceLocation materialName, ItemEntry entry) {
List<ItemEntry> entries = ITEM_ENTRIES.get(materialName);
if (entries == null) {
entries = Lists.newArrayList();
ITEM_ENTRIES.put(materialName, entries);
}
entries.add(entry);
}
/**
* Adds a custom {@link RecipeEntry} for specified {@link ComplexMaterial} using its {@link ResourceLocation}.
* Used to add custom entry for all instances of {@link ComplexMaterial}.
* Should be called only using Fabric "preLaunch" entry point.
*
* @param materialName {@link ResourceLocation} id of {@link ComplexMaterial};
* @param entry {@link RecipeEntry}.
* @see <a href="https://fabricmc.net/wiki/documentation:entrypoint">Fabric Documentation: Entrypoint</a>
*/
public static void addRecipeEntry(ResourceLocation materialName, RecipeEntry entry) {
List<RecipeEntry> entries = RECIPE_ENTRIES.get(materialName);
if (entries == null) {
entries = Lists.newArrayList();
RECIPE_ENTRIES.put(materialName, entries);
}
entries.add(entry);
}
/**
* Get all instances of all materials.
*
* @return {@link Collection} of {@link ComplexMaterial}.
*/
public static Collection<ComplexMaterial> getAllMaterials() {
return MATERIALS;
}
}

View file

@ -0,0 +1,386 @@
package org.betterx.bclib.complexmaterials;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.tag.*;
import org.betterx.bclib.blocks.*;
import org.betterx.bclib.complexmaterials.entry.BlockEntry;
import org.betterx.bclib.complexmaterials.entry.RecipeEntry;
import org.betterx.bclib.recipes.GridRecipe;
public class WoodenComplexMaterial extends ComplexMaterial {
public static final ResourceLocation MATERIAL_ID = BCLib.makeID("wooden_material");
public static final String BLOCK_CRAFTING_TABLE = "crafting_table";
public static final String BLOCK_STRIPPED_BARK = "stripped_bark";
public static final String BLOCK_STRIPPED_LOG = "stripped_log";
public static final String BLOCK_PRESSURE_PLATE = "plate";
public static final String BLOCK_BOOKSHELF = "bookshelf";
public static final String BLOCK_COMPOSTER = "composter";
public static final String BLOCK_TRAPDOOR = "trapdoor";
public static final String BLOCK_BARREL = "barrel";
public static final String BLOCK_BUTTON = "button";
public static final String BLOCK_LADDER = "ladder";
public static final String BLOCK_PLANKS = "planks";
public static final String BLOCK_STAIRS = "stairs";
public static final String BLOCK_CHEST = "chest";
public static final String BLOCK_FENCE = "fence";
public static final String BLOCK_BARK = "bark";
public static final String BLOCK_DOOR = "door";
public static final String BLOCK_GATE = "gate";
public static final String BLOCK_SIGN = "sign";
public static final String BLOCK_SLAB = "slab";
public static final String BLOCK_LOG = "log";
public static final String TAG_LOGS = "logs";
public final MaterialColor planksColor;
public final MaterialColor woodColor;
public WoodenComplexMaterial(String modID,
String baseName,
String receipGroupPrefix,
MaterialColor woodColor,
MaterialColor planksColor) {
super(modID, baseName, receipGroupPrefix);
this.planksColor = planksColor;
this.woodColor = woodColor;
}
@Override
protected FabricBlockSettings getBlockSettings() {
return FabricBlockSettings.copyOf(Blocks.OAK_PLANKS)
.materialColor(planksColor);
}
@Override
public ResourceLocation getMaterialID() {
return MATERIAL_ID;
}
@Override
protected void initTags() {
addBlockTag(TagAPI.makeBlockTag(getModID(), getBaseName() + "_logs"));
addItemTag(TagAPI.makeItemTag(getModID(), getBaseName() + "_logs"));
}
@Override
protected void initDefault(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
initBase(blockSettings, itemSettings);
initStorage(blockSettings, itemSettings);
initDecorations(blockSettings, itemSettings);
}
final protected void initBase(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
TagKey<Block> tagBlockLog = getBlockTag(TAG_LOGS);
TagKey<Item> tagItemLog = getItemTag(TAG_LOGS);
addBlockEntry(
new BlockEntry(BLOCK_STRIPPED_LOG, (complexMaterial, settings) -> new BaseRotatedPillarBlock(settings))
.setBlockTags(NamedBlockTags.LOGS, NamedBlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(NamedItemTags.LOGS, NamedItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_STRIPPED_BARK, (complexMaterial, settings) -> new BaseBarkBlock(settings))
.setBlockTags(NamedBlockTags.LOGS, NamedBlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(NamedItemTags.LOGS, NamedItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_LOG,
(complexMaterial, settings) -> new BaseStripableLogBlock(woodColor,
getBlock(BLOCK_STRIPPED_LOG)))
.setBlockTags(NamedBlockTags.LOGS, NamedBlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(NamedItemTags.LOGS, NamedItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry(BLOCK_BARK,
(complexMaterial, settings) -> new StripableBarkBlock(woodColor,
getBlock(BLOCK_STRIPPED_BARK)))
.setBlockTags(NamedBlockTags.LOGS, NamedBlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(NamedItemTags.LOGS, NamedItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(new BlockEntry(BLOCK_PLANKS, (complexMaterial, settings) -> new BaseBlock(settings))
.setBlockTags(NamedBlockTags.PLANKS)
.setItemTags(NamedItemTags.PLANKS));
addBlockEntry(new BlockEntry(BLOCK_STAIRS,
(complexMaterial, settings) -> new BaseStairsBlock(getBlock(BLOCK_PLANKS), false))
.setBlockTags(NamedBlockTags.WOODEN_STAIRS, NamedBlockTags.STAIRS)
.setItemTags(NamedItemTags.WOODEN_STAIRS, NamedItemTags.STAIRS));
addBlockEntry(new BlockEntry(BLOCK_SLAB,
(complexMaterial, settings) -> new BaseSlabBlock(getBlock(BLOCK_PLANKS), false))
.setBlockTags(NamedBlockTags.WOODEN_SLABS, NamedBlockTags.SLABS)
.setItemTags(NamedItemTags.WOODEN_SLABS, NamedItemTags.SLABS));
addBlockEntry(new BlockEntry(BLOCK_FENCE,
(complexMaterial, settings) -> new BaseFenceBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.FENCES, NamedBlockTags.WOODEN_FENCES)
.setItemTags(NamedItemTags.FENCES, NamedItemTags.WOODEN_FENCES));
addBlockEntry(new BlockEntry(BLOCK_GATE,
(complexMaterial, settings) -> new BaseGateBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.FENCE_GATES));
addBlockEntry(new BlockEntry(BLOCK_BUTTON,
(complexMaterial, settings) -> new BaseWoodenButtonBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.BUTTONS, NamedBlockTags.WOODEN_BUTTONS)
.setItemTags(NamedItemTags.BUTTONS, NamedItemTags.WOODEN_BUTTONS));
addBlockEntry(new BlockEntry(BLOCK_PRESSURE_PLATE,
(complexMaterial, settings) -> new WoodenPressurePlateBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.PRESSURE_PLATES, NamedBlockTags.WOODEN_PRESSURE_PLATES)
.setItemTags(NamedItemTags.WOODEN_PRESSURE_PLATES));
addBlockEntry(new BlockEntry(BLOCK_TRAPDOOR,
(complexMaterial, settings) -> new BaseTrapdoorBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.TRAPDOORS, NamedBlockTags.WOODEN_TRAPDOORS)
.setItemTags(NamedItemTags.TRAPDOORS, NamedItemTags.WOODEN_TRAPDOORS));
addBlockEntry(new BlockEntry(BLOCK_DOOR,
(complexMaterial, settings) -> new BaseDoorBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.DOORS, NamedBlockTags.WOODEN_DOORS)
.setItemTags(NamedItemTags.DOORS, NamedItemTags.WOODEN_DOORS));
addBlockEntry(new BlockEntry(BLOCK_LADDER,
(complexMaterial, settings) -> new BaseLadderBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.CLIMBABLE));
addBlockEntry(new BlockEntry(BLOCK_SIGN,
(complexMaterial, settings) -> new BaseSignBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(NamedBlockTags.SIGNS)
.setItemTags(NamedItemTags.SIGNS));
}
final protected void initStorage(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
addBlockEntry(new BlockEntry(BLOCK_CHEST,
(complexMaterial, settings) -> new BaseChestBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(CommonBlockTags.CHEST, CommonBlockTags.WOODEN_CHEST)
.setItemTags(CommonItemTags.CHEST, CommonItemTags.WOODEN_CHEST));
addBlockEntry(new BlockEntry(BLOCK_BARREL,
(complexMaterial, settings) -> new BaseBarrelBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(CommonBlockTags.BARREL, CommonBlockTags.WOODEN_BARREL)
.setItemTags(CommonItemTags.BARREL, CommonItemTags.WOODEN_BARREL));
}
final protected void initDecorations(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
addBlockEntry(new BlockEntry(BLOCK_CRAFTING_TABLE,
(complexMaterial, settings) -> new BaseCraftingTableBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(CommonBlockTags.WORKBENCHES)
.setItemTags(CommonItemTags.WORKBENCHES));
addBlockEntry(new BlockEntry(BLOCK_BOOKSHELF,
(complexMaterial, settings) -> new BaseBookshelfBlock(getBlock(BLOCK_PLANKS)))
.setBlockTags(CommonBlockTags.BOOKSHELVES));
addBlockEntry(new BlockEntry(BLOCK_COMPOSTER,
(complexMaterial, settings) -> new BaseComposterBlock(getBlock(BLOCK_PLANKS))));
}
@Override
protected void initFlammable(FlammableBlockRegistry registry) {
getBlocks().forEach(block -> {
registry.add(block, 5, 20);
});
registry.add(getBlock(BLOCK_LOG), 5, 5);
registry.add(getBlock(BLOCK_BARK), 5, 5);
registry.add(getBlock(BLOCK_STRIPPED_LOG), 5, 5);
registry.add(getBlock(BLOCK_STRIPPED_BARK), 5, 5);
}
@Override
public void initDefaultRecipes() {
Block planks = getBlock(BLOCK_PLANKS);
addRecipeEntry(new RecipeEntry("planks", (material, config, id) -> {
Block log_stripped = getBlock(BLOCK_STRIPPED_LOG);
Block bark_stripped = getBlock(BLOCK_STRIPPED_BARK);
Block log = getBlock(BLOCK_LOG);
Block bark = getBlock(BLOCK_BARK);
GridRecipe.make(id, planks)
.checkConfig(config)
.setOutputCount(4)
.setList("#")
.addMaterial('#', log, bark, log_stripped, bark_stripped)
.setGroup(receipGroupPrefix + "_planks")
.build();
}));
addRecipeEntry(new RecipeEntry("stairs", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STAIRS))
.checkConfig(config)
.setOutputCount(4)
.setShape("# ", "## ", "###")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_stairs")
.build();
}));
addRecipeEntry(new RecipeEntry("slab", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_SLAB))
.checkConfig(config)
.setOutputCount(6)
.setShape("###")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_slabs")
.build();
}));
addRecipeEntry(new RecipeEntry("fence", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_FENCE))
.checkConfig(config)
.setOutputCount(3)
.setShape("#I#", "#I#")
.addMaterial('#', planks)
.addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_planks_fences")
.build();
}));
addRecipeEntry(new RecipeEntry("gate", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_GATE))
.checkConfig(config)
.setShape("I#I", "I#I")
.addMaterial('#', planks)
.addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_planks_gates")
.build();
}));
addRecipeEntry(new RecipeEntry("button", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BUTTON))
.checkConfig(config)
.setList("#")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_buttons")
.build();
}));
addRecipeEntry(new RecipeEntry("pressure_plate", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_PRESSURE_PLATE))
.checkConfig(config)
.setShape("##")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_planks_plates")
.build();
}));
addRecipeEntry(new RecipeEntry("trapdoor", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_TRAPDOOR))
.checkConfig(config)
.setOutputCount(2)
.setShape("###", "###")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_trapdoors")
.build();
}));
addRecipeEntry(new RecipeEntry("door", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_DOOR))
.checkConfig(config)
.setOutputCount(3)
.setShape("##", "##", "##")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_doors")
.build();
}));
addRecipeEntry(new RecipeEntry("crafting_table", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CRAFTING_TABLE))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_tables")
.build();
}));
addRecipeEntry(new RecipeEntry("ladder", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_LADDER))
.checkConfig(config)
.setOutputCount(3)
.setShape("I I", "I#I", "I I")
.addMaterial('#', planks)
.addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_ladders")
.build();
}));
addRecipeEntry(new RecipeEntry("sign", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_SIGN))
.checkConfig(config)
.setOutputCount(3)
.setShape("###", "###", " I ")
.addMaterial('#', planks)
.addMaterial('I', Items.STICK)
.setGroup(receipGroupPrefix + "_signs")
.build();
}));
addRecipeEntry(new RecipeEntry("chest", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_CHEST))
.checkConfig(config)
.setShape("###", "# #", "###")
.addMaterial('#', planks)
.setGroup(receipGroupPrefix + "_chests")
.build();
}));
addRecipeEntry(new RecipeEntry("barrel", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARREL))
.checkConfig(config)
.setShape("#S#", "# #", "#S#")
.addMaterial('#', planks)
.addMaterial('S', getBlock(BLOCK_SLAB))
.setGroup(receipGroupPrefix + "_barrels")
.build();
}));
addRecipeEntry(new RecipeEntry("bookshelf", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BOOKSHELF))
.checkConfig(config)
.setShape("###", "PPP", "###")
.addMaterial('#', planks)
.addMaterial('P', Items.BOOK)
.setGroup(receipGroupPrefix + "_bookshelves")
.build();
}));
addRecipeEntry(new RecipeEntry("bark", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_BARK))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_LOG))
.setOutputCount(3)
.build();
}));
addRecipeEntry(new RecipeEntry("log", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_LOG))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_BARK))
.setOutputCount(3)
.build();
}));
addRecipeEntry(new RecipeEntry("stripped_bark", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STRIPPED_BARK))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_STRIPPED_LOG))
.setOutputCount(3)
.build();
}));
addRecipeEntry(new RecipeEntry("stripped_log", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_STRIPPED_LOG))
.checkConfig(config)
.setShape("##", "##")
.addMaterial('#', getBlock(BLOCK_STRIPPED_BARK))
.setOutputCount(3)
.build();
}));
addRecipeEntry(new RecipeEntry("composter", (material, config, id) -> {
GridRecipe.make(id, getBlock(BLOCK_COMPOSTER))
.checkConfig(config)
.setShape("# #", "# #", "###")
.addMaterial('#', getBlock(BLOCK_SLAB))
.build();
}));
}
}

View file

@ -0,0 +1,61 @@
package org.betterx.bclib.complexmaterials.entry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import org.betterx.bclib.api.tag.TagAPI;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.registry.BlockRegistry;
import java.util.function.BiFunction;
public class BlockEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction;
final boolean hasItem;
TagKey<Block>[] blockTags;
TagKey<Item>[] itemTags;
public BlockEntry(String suffix, BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction) {
this(suffix, true, initFunction);
}
public BlockEntry(String suffix,
boolean hasItem,
BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction) {
super(suffix);
this.initFunction = initFunction;
this.hasItem = hasItem;
}
public BlockEntry setBlockTags(TagKey<Block>... blockTags) {
this.blockTags = blockTags;
return this;
}
public BlockEntry setItemTags(TagKey<Item>... itemTags) {
this.itemTags = itemTags;
return this;
}
public Block init(ComplexMaterial material, FabricBlockSettings blockSettings, BlockRegistry registry) {
ResourceLocation location = getLocation(material.getModID(), material.getBaseName());
Block block = initFunction.apply(material, blockSettings);
if (hasItem) {
registry.register(location, block);
if (itemTags != null) {
TagAPI.addItemTags(block, itemTags);
}
} else {
registry.registerBlockOnly(location, block);
}
if (blockTags != null) {
TagAPI.addBlockTags(block, blockTags);
}
return block;
}
}

View file

@ -0,0 +1,40 @@
package org.betterx.bclib.complexmaterials.entry;
import net.minecraft.resources.ResourceLocation;
import java.util.Objects;
import org.jetbrains.annotations.NotNull;
public abstract class ComplexMaterialEntry {
@NotNull
private final String suffix;
protected ComplexMaterialEntry(String suffix) {
this.suffix = suffix;
}
public String getName(String baseName) {
return baseName + "_" + suffix;
}
public ResourceLocation getLocation(String modID, String baseName) {
return new ResourceLocation(modID, getName(baseName));
}
public String getSuffix() {
return suffix;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ComplexMaterialEntry that = (ComplexMaterialEntry) o;
return suffix.equals(that.suffix);
}
@Override
public int hashCode() {
return Objects.hash(suffix);
}
}

View file

@ -0,0 +1,39 @@
package org.betterx.bclib.complexmaterials.entry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import org.betterx.bclib.api.tag.TagAPI;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.registry.ItemRegistry;
import java.util.function.BiFunction;
public class ItemEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, FabricItemSettings, Item> initFunction;
TagKey<Item>[] itemTags;
public ItemEntry(String suffix, BiFunction<ComplexMaterial, FabricItemSettings, Item> initFunction) {
super(suffix);
this.initFunction = initFunction;
}
public ItemEntry setItemTags(TagKey<Item>[] itemTags) {
this.itemTags = itemTags;
return this;
}
public Item init(ComplexMaterial material, FabricItemSettings itemSettings, ItemRegistry registry) {
ResourceLocation location = getLocation(material.getModID(), material.getBaseName());
Item item = initFunction.apply(material, itemSettings);
registry.register(location, item);
if (itemTags != null) {
TagAPI.addItemTags(item, itemTags);
}
return item;
}
}

View file

@ -0,0 +1,20 @@
package org.betterx.bclib.complexmaterials.entry;
import net.minecraft.resources.ResourceLocation;
import org.betterx.bclib.complexmaterials.ComplexMaterial;
import org.betterx.bclib.config.PathConfig;
import org.betterx.bclib.interfaces.TriConsumer;
public class RecipeEntry extends ComplexMaterialEntry {
final TriConsumer<ComplexMaterial, PathConfig, ResourceLocation> initFunction;
public RecipeEntry(String suffix, TriConsumer<ComplexMaterial, PathConfig, ResourceLocation> initFunction) {
super(suffix);
this.initFunction = initFunction;
}
public void init(ComplexMaterial material, PathConfig recipeConfig) {
initFunction.accept(material, recipeConfig, getLocation(material.getModID(), material.getBaseName()));
}
}