Complex materials, wood material (WIP)

This commit is contained in:
paulevsGitch 2021-07-23 13:40:37 +03:00
parent eb4f70b8a2
commit 0eaaae2f99
7 changed files with 435 additions and 250 deletions

View file

@ -1,246 +0,0 @@
package ru.bclib.blocks.complex;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
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.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import org.jetbrains.annotations.NotNull;
import ru.bclib.api.TagAPI;
import ru.bclib.blocks.BaseBarkBlock;
import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blocks.BaseBlock;
import ru.bclib.blocks.BaseBookshelfBlock;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseComposterBlock;
import ru.bclib.blocks.BaseCraftingTableBlock;
import ru.bclib.blocks.BaseDoorBlock;
import ru.bclib.blocks.BaseFenceBlock;
import ru.bclib.blocks.BaseGateBlock;
import ru.bclib.blocks.BaseLadderBlock;
import ru.bclib.blocks.BaseRotatedPillarBlock;
import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.blocks.BaseSlabBlock;
import ru.bclib.blocks.BaseStairsBlock;
import ru.bclib.blocks.BaseStripableLogBlock;
import ru.bclib.blocks.BaseTrapdoorBlock;
import ru.bclib.blocks.BaseWoodenButtonBlock;
import ru.bclib.blocks.StripableBarkBlock;
import ru.bclib.blocks.WoodenPressurePlateBlock;
import ru.bclib.config.Configs;
import ru.bclib.recipes.GridRecipe;
import java.util.function.BiFunction;
public class WoodenMaterial {
public final static String NAME_STRIPPED_LOG = "stripped_log";
public final static String NAME_STRIPPED_BARK = "stripped_bark";
public final static String NAME_LOG = "log";
public final static String NAME_BARK = "bark";
public final static String NAME_PLANKS = "planks";
public final static String NAME_STAIRS = "stairs";
public final static String NAME_SLAB = "slab";
public final static String NAME_FENCE = "fence";
public final static String NAME_GATE = "gate";
public final static String NAME_BUTTON = "button";
public final static String NAME_PLATE = "plate";
public final static String NAME_TRAPDOOR = "trapdoor";
public final static String NAME_DOOR = "door";
public final static String NAME_CRAFTING_TABLE = "crafting_table";
public final static String NAME_LADDER = "ladder";
public final static String NAME_SIGN = "sign";
public final static String NAME_CHEST = "chest";
public final static String NAME_BARREL = "barrel";
public final static String NAME_BOOKSHELF = "bookshelf";
public final static String NAME_COMPOSTER = "composter";
public final static String NAME_PRESSURE_PLATE = "pressure_plate";
public final static String NAME_SHULKER = "shulker";
public final Block log;
public final Block bark;
public final Block log_stripped;
public final Block bark_stripped;
public final Block planks;
public final Block stairs;
public final Block slab;
public final Block fence;
public final Block gate;
public final Block button;
public final Block pressurePlate;
public final Block trapdoor;
public final Block door;
public final Block craftingTable;
public final Block ladder;
public final Block sign;
public final Block chest;
public final Block barrel;
//public final Block shelf;
//public final Block composter;
protected final FabricBlockSettings materialPlanks;
protected final String modID;
protected final String name;
protected final String receipGroupPrefix;
public final Tag.Named<Block> logBlockTag;
public final Tag.Named<Item> logItemTag;
protected Block newLogStripped(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseRotatedPillarBlock(materialPlanks); }
protected Block newBarkStripped(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBarkBlock(materialPlanks); }
protected Block newLog(FabricBlockSettings materialPlanks, MaterialColor woodColor) { if (log_stripped!=null) return new BaseStripableLogBlock(woodColor, log_stripped); else return null;}
protected Block newBark(FabricBlockSettings materialPlanks, MaterialColor woodColor) { if (bark_stripped!=null) return new StripableBarkBlock(woodColor, bark_stripped); else return null;}
protected Block newPlanks(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBlock(materialPlanks); }
protected Block newStairs(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseStairsBlock(planks); }
protected Block newSlab(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseSlabBlock(planks); }
protected Block newFence(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseFenceBlock(planks); }
protected Block newGate(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseGateBlock(planks); }
protected Block newButton(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseWoodenButtonBlock(planks); }
protected Block newPressurePlate(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new WoodenPressurePlateBlock(planks); }
protected Block newTrapdoor(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseTrapdoorBlock(planks); }
protected Block newDoor(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseDoorBlock(planks); }
protected Block newCraftingTable(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseCraftingTableBlock(planks); }
protected Block newLadder(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseLadderBlock(planks); }
protected Block newSign(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseSignBlock(planks); }
protected Block newChest(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseChestBlock(planks); }
protected Block newBarrel(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBarrelBlock(planks); }
//protected Block newShelf(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseBookshelfBlock(planks); }
//protected Block newComposter(FabricBlockSettings materialPlanks, MaterialColor woodColor) { return new BaseComposterBlock(planks); }
public WoodenMaterial(String modID, String name, MaterialColor woodColor, MaterialColor planksColor, String receipGroupPrefix, BiFunction<String, Block, Block> registerBlock) {
materialPlanks = FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).mapColor(planksColor);
this.modID = modID;
this.receipGroupPrefix = receipGroupPrefix;
this.name = name;
log_stripped = registerBlock.apply(name + "_" + NAME_STRIPPED_LOG, newLogStripped(materialPlanks, woodColor));
bark_stripped = registerBlock.apply(name + "_" + NAME_STRIPPED_BARK, newBarkStripped(materialPlanks, woodColor));
log = registerBlock.apply(name + "_" + NAME_LOG, newLog(materialPlanks, woodColor));
bark = registerBlock.apply(name + "_" + NAME_BARK, newBark(materialPlanks, woodColor));
planks = registerBlock.apply(name + "_" + NAME_PLANKS, newPlanks(materialPlanks, woodColor));
stairs = registerBlock.apply(name + "_" + NAME_STAIRS, newStairs(materialPlanks, woodColor));
slab = registerBlock.apply(name + "_" + NAME_SLAB, newSlab(materialPlanks, woodColor));
fence = registerBlock.apply(name + "_" + NAME_FENCE, newFence(materialPlanks, woodColor));
gate = registerBlock.apply(name + "_" + NAME_GATE, newGate(materialPlanks, woodColor));
button = registerBlock.apply(name + "_" + NAME_BUTTON, newButton(materialPlanks, woodColor));
pressurePlate = registerBlock.apply(name + "_" + NAME_PLATE, newPressurePlate(materialPlanks, woodColor));
trapdoor = registerBlock.apply(name + "_" + NAME_TRAPDOOR, newTrapdoor(materialPlanks, woodColor));
door = registerBlock.apply(name + "_" + NAME_DOOR, newDoor(materialPlanks, woodColor));
craftingTable = registerBlock.apply(name + "_" + NAME_CRAFTING_TABLE, newCraftingTable(materialPlanks, woodColor));
ladder = registerBlock.apply(name + "_" + NAME_LADDER, newLadder(materialPlanks, woodColor));
sign = registerBlock.apply(name + "_" + NAME_SIGN, newSign(materialPlanks, woodColor));
chest = registerBlock.apply(name + "_" + NAME_CHEST, newChest(materialPlanks, woodColor));
barrel = registerBlock.apply(name + "_" + NAME_BARREL, newBarrel(materialPlanks, woodColor));
//shelf = registerBlock.apply(name + "_" + NAME_BOOKSHELF, newShelf(materialPlanks, woodColor));
//composter = registerBlock.apply(name + "_" + NAME_COMPOSTER, newComposter(materialPlanks, woodColor));
// Recipes //
GridRecipe.make(modID, name + "_" + NAME_PLANKS, planks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setList("#").addMaterial('#', log, bark, log_stripped, bark_stripped).setGroup(receipGroupPrefix + "_planks").build();
GridRecipe.make(modID, name + "_" + NAME_STAIRS, stairs).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("# ", "## ", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_stairs").build();
GridRecipe.make(modID, name + "_" + NAME_SLAB, slab).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(6).setShape("###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_slabs").build();
GridRecipe.make(modID, name + "_" + NAME_FENCE, fence).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("#I#", "#I#").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_planks_fences").build();
GridRecipe.make(modID, name + "_" + NAME_GATE, gate).checkConfig(Configs.RECIPE_CONFIG).setShape("I#I", "I#I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_planks_gates").build();
GridRecipe.make(modID, name + "_" + NAME_BUTTON, button).checkConfig(Configs.RECIPE_CONFIG).setList("#").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_buttons").build();
GridRecipe.make(modID, name + "_" + NAME_PRESSURE_PLATE, pressurePlate).checkConfig(Configs.RECIPE_CONFIG).setShape("##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_planks_plates").build();
GridRecipe.make(modID, name + "_" + NAME_TRAPDOOR, trapdoor).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(2).setShape("###", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_trapdoors").build();
GridRecipe.make(modID, name + "_" + NAME_DOOR, door).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("##", "##", "##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_doors").build();
GridRecipe.make(modID, name + "_" + NAME_CRAFTING_TABLE, craftingTable).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', planks).setGroup(receipGroupPrefix + "_tables").build();
GridRecipe.make(modID, name + "_" + NAME_LADDER, ladder).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("I I", "I#I", "I I").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_ladders").build();
GridRecipe.make(modID, name + "_" + NAME_SIGN, sign).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(3).setShape("###", "###", " I ").addMaterial('#', planks).addMaterial('I', Items.STICK).setGroup(receipGroupPrefix + "_signs").build();
GridRecipe.make(modID, name + "_" + NAME_CHEST, chest).checkConfig(Configs.RECIPE_CONFIG).setShape("###", "# #", "###").addMaterial('#', planks).setGroup(receipGroupPrefix + "_chests").build();
GridRecipe.make(modID, name + "_" + NAME_BARREL, barrel).checkConfig(Configs.RECIPE_CONFIG).setShape("#S#", "# #", "#S#").addMaterial('#', planks).addMaterial('S', slab).setGroup(receipGroupPrefix + "_barrels").build();
//GridRecipe.make(modID, name + "_" + NAME_BOOKSHELF, shelf).checkConfig(Configs.RECIPE_CONFIG).setShape("###", "PPP", "###").addMaterial('#', planks).addMaterial('P', Items.BOOK).setGroup(receipGroupPrefix + "_bookshelves").build();
GridRecipe.make(modID, name + "_" + NAME_BARK, bark).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', log).setOutputCount(3).build();
GridRecipe.make(modID, name + "_" + NAME_LOG, log).checkConfig(Configs.RECIPE_CONFIG).setShape("##", "##").addMaterial('#', bark).setOutputCount(3).build();
//GridRecipe.make(modID, name + "_" + NAME_COMPOSTER, composter).checkConfig(Configs.RECIPE_CONFIG).setShape("# #", "# #", "###").addMaterial('#', slab).build();
GridRecipe.make(modID, name + "_" + NAME_SHULKER, Items.SHULKER_BOX).checkConfig(Configs.RECIPE_CONFIG).setShape("S", "#", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('#', chest).build();
// Item Tags //
TagAPI.addTag(ItemTags.PLANKS, planks);
TagAPI.addTag(ItemTags.WOODEN_PRESSURE_PLATES, pressurePlate);
TagAPI.addTag(ItemTags.LOGS, log, bark, log_stripped, bark_stripped);
TagAPI.addTag(ItemTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped);
TagAPI.addTags(button, ItemTags.WOODEN_BUTTONS, ItemTags.BUTTONS);
TagAPI.addTags(door, ItemTags.WOODEN_DOORS, ItemTags.DOORS);
TagAPI.addTags(fence, ItemTags.WOODEN_FENCES, ItemTags.FENCES);
TagAPI.addTags(slab, ItemTags.WOODEN_SLABS, ItemTags.SLABS);
TagAPI.addTags(stairs, ItemTags.WOODEN_STAIRS, ItemTags.STAIRS);
TagAPI.addTags(trapdoor, ItemTags.WOODEN_TRAPDOORS, ItemTags.TRAPDOORS);
TagAPI.addTag(TagAPI.ITEM_CHEST, chest);
// Block Tags //
TagAPI.addTag(BlockTags.PLANKS, planks);
TagAPI.addTag(BlockTags.CLIMBABLE, ladder);
TagAPI.addTag(BlockTags.LOGS, log, bark, log_stripped, bark_stripped);
TagAPI.addTag(BlockTags.LOGS_THAT_BURN, log, bark, log_stripped, bark_stripped);
TagAPI.addTags(button, BlockTags.WOODEN_BUTTONS, BlockTags.BUTTONS);
TagAPI.addTags(door, BlockTags.WOODEN_DOORS, BlockTags.DOORS);
TagAPI.addTags(fence, BlockTags.WOODEN_FENCES, BlockTags.FENCES);
TagAPI.addTags(slab, BlockTags.WOODEN_SLABS, BlockTags.SLABS);
TagAPI.addTags(stairs, BlockTags.WOODEN_STAIRS, BlockTags.STAIRS);
TagAPI.addTags(trapdoor, BlockTags.WOODEN_TRAPDOORS, BlockTags.TRAPDOORS);
//TagAPI.addTag(TagAPI.BLOCK_BOOKSHELVES, shelf);
TagAPI.addTag(TagAPI.BLOCK_CHEST, chest);
logBlockTag = TagAPI.makeBlockTag(modID, name + "_logs");
logItemTag = TagAPI.makeItemTag(modID, name + "_logs");
TagAPI.addTag(logBlockTag, log_stripped, bark_stripped, log, bark);
TagAPI.addTag(logItemTag, log_stripped, bark_stripped, log, bark);
addFlammable();
}
protected void addFlammable() {
FlammableBlockRegistry.getDefaultInstance().add(log, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(bark, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(log_stripped, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(bark_stripped, 5, 5);
FlammableBlockRegistry.getDefaultInstance().add(planks, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(stairs, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(slab, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(fence, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(gate, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(button, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(pressurePlate, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(trapdoor, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(door, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(craftingTable, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(ladder, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(sign, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(chest, 5, 20);
FlammableBlockRegistry.getDefaultInstance().add(barrel, 5, 20);
//FlammableBlockRegistry.getDefaultInstance().add(shelf, 5, 20);
//FlammableBlockRegistry.getDefaultInstance().add(composter, 5, 20);
}
public boolean isTreeLog(Block block) {
return block!=null && (block == log || block == bark);
}
public boolean isTreeLog(BlockState state) {
return isTreeLog(state.getBlock());
}
}

View file

@ -0,0 +1,169 @@
package ru.bclib.complexmaterials;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import org.jetbrains.annotations.Nullable;
import ru.bclib.complexmaterials.entry.BlockEntry;
import ru.bclib.complexmaterials.entry.ItemEntry;
import ru.bclib.registry.BlocksRegistry;
import ru.bclib.registry.ItemsRegistry;
import java.util.Collection;
import java.util.List;
import java.util.Map;
public abstract class ComplexMaterial {
private static final Map<Class<? extends ComplexMaterial>, List<BlockEntry>> BLOCK_ENTRIES = Maps.newHashMap();
private static final Map<Class<? extends ComplexMaterial>, List<ItemEntry>> ITEM_ENTRIES = Maps.newHashMap();
private static final List<ComplexMaterial> MATERIALS = Lists.newArrayList();
private final List<BlockEntry> defaultBlockEntries = Lists.newArrayList();
private final List<ItemEntry> defaultItemEntries = Lists.newArrayList();
private final Map<String, Tag.Named<Block>> blockTags = Maps.newHashMap();
private final Map<String, Tag.Named<Item>> itemTags = Maps.newHashMap();
private final Map<String, Block> blocks = Maps.newHashMap();
private final Map<String, Item> items = Maps.newHashMap();
private final BlocksRegistry blocksRegistry;
private final ItemsRegistry itemsRegistry;
private final String baseName;
private final String modID;
public ComplexMaterial(String modID, String baseName, BlocksRegistry blocksRegistry, ItemsRegistry itemsRegistry) {
this.blocksRegistry = blocksRegistry;
this.itemsRegistry = itemsRegistry;
this.baseName = baseName;
this.modID = modID;
MATERIALS.add(this);
}
public void init() {
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.getName(baseName), block);
});
getItemEntries().forEach(entry -> {
Item item = entry.init(this, itemSettings, itemsRegistry);
items.put(entry.getName(baseName), item);
});
initRecipes();
}
public abstract void initDefault(FabricBlockSettings blockSettings, FabricItemSettings itemSettings);
public void initTags() {}
public void initRecipes() {}
protected void addBlockTag(Tag.Named<Block> tag) {
blockTags.put(tag.getName().getPath(), tag);
}
protected void addItemTag(Tag.Named<Item> tag) {
itemTags.put(tag.getName().getPath(), tag);
}
@Nullable
public Tag.Named<Block> getBlockTag(String key) {
return blockTags.get(key);
}
@Nullable
public Tag.Named<Item> getItemTag(String key) {
return itemTags.get(key);
}
@Nullable
public Block getBlock(String key) {
return blocks.get(key);
}
@Nullable
public Item getItem(String key) {
return items.get(key);
}
protected abstract FabricBlockSettings getBlockSettings();
protected FabricItemSettings getItemSettings(ItemsRegistry registry) {
return registry.makeItemSettings();
}
private Collection<BlockEntry> getBlockEntries() {
List<BlockEntry> result = Lists.newArrayList(defaultBlockEntries);
List<BlockEntry> entries = BLOCK_ENTRIES.get(this.getClass());
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.getClass());
if (entries != null) {
result.addAll(entries);
}
return result;
}
public BlocksRegistry getBlocksRegistry() {
return blocksRegistry;
}
public ItemsRegistry getItemsRegistry() {
return itemsRegistry;
}
public String getBaseName() {
return baseName;
}
public String getModID() {
return modID;
}
protected void addBlockEntry(BlockEntry entry) {
defaultBlockEntries.add(entry);
}
protected void addItemEntry(ItemEntry entry) {
defaultItemEntries.add(entry);
}
public static void addBlockEntry(Class<? extends ComplexMaterial> key, BlockEntry entry) {
List<BlockEntry> entries = BLOCK_ENTRIES.get(key);
if (entries == null) {
entries = Lists.newArrayList();
BLOCK_ENTRIES.put(key, entries);
}
entries.add(entry);
}
public static void addItemEntry(Class<? extends ComplexMaterial> key, ItemEntry entry) {
List<ItemEntry> entries = ITEM_ENTRIES.get(key);
if (entries == null) {
entries = Lists.newArrayList();
ITEM_ENTRIES.put(key, entries);
}
entries.add(entry);
}
public static Collection<ComplexMaterial> getAllMaterials() {
return MATERIALS;
}
}

View file

@ -0,0 +1,149 @@
package ru.bclib.complexmaterials;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor;
import ru.bclib.api.TagAPI;
import ru.bclib.blocks.BaseBarkBlock;
import ru.bclib.blocks.BaseBarrelBlock;
import ru.bclib.blocks.BaseBlock;
import ru.bclib.blocks.BaseBookshelfBlock;
import ru.bclib.blocks.BaseChestBlock;
import ru.bclib.blocks.BaseComposterBlock;
import ru.bclib.blocks.BaseCraftingTableBlock;
import ru.bclib.blocks.BaseDoorBlock;
import ru.bclib.blocks.BaseFenceBlock;
import ru.bclib.blocks.BaseGateBlock;
import ru.bclib.blocks.BaseLadderBlock;
import ru.bclib.blocks.BaseRotatedPillarBlock;
import ru.bclib.blocks.BaseSignBlock;
import ru.bclib.blocks.BaseSlabBlock;
import ru.bclib.blocks.BaseStairsBlock;
import ru.bclib.blocks.BaseTrapdoorBlock;
import ru.bclib.blocks.BaseWoodenButtonBlock;
import ru.bclib.blocks.StripableBarkBlock;
import ru.bclib.blocks.WoodenPressurePlateBlock;
import ru.bclib.complexmaterials.entry.BlockEntry;
import ru.bclib.registry.BlocksRegistry;
import ru.bclib.registry.ItemsRegistry;
public class WoodenMaterial extends ComplexMaterial {
public final MaterialColor planksColor;
public final MaterialColor woodColor;
public WoodenMaterial(String modID, String baseName, MaterialColor woodColor, MaterialColor planksColor, BlocksRegistry blocksRegistry, ItemsRegistry itemsRegistry) {
super(modID, baseName, blocksRegistry, itemsRegistry);
this.planksColor = planksColor;
this.woodColor = woodColor;
}
@Override
protected FabricBlockSettings getBlockSettings() {
return FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).materialColor(planksColor);
}
@Override
public void initTags() {
addBlockTag(TagAPI.makeBlockTag(getModID(), getBaseName() + "_logs"));
addItemTag(TagAPI.makeItemTag(getModID(), getBaseName() + "_logs"));
}
@Override
public void initDefault(FabricBlockSettings blockSettings, FabricItemSettings itemSettings) {
Tag.Named<Block> tagBlockLog = getBlockTag(getBaseName() + "_logs");
Tag.Named<Item> tagItemLog = getItemTag(getBaseName() + "_logs");
addBlockEntry(
new BlockEntry("stripped_log", (complexMaterial, settings) -> {
return new BaseRotatedPillarBlock(settings);
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry("stripped_bark", (complexMaterial, settings) -> {
return new BaseBarkBlock(settings);
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry("log", (complexMaterial, settings) -> {
return new StripableBarkBlock(woodColor, getBlock("log_stripped"));
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(
new BlockEntry("bark", (complexMaterial, settings) -> {
return new StripableBarkBlock(woodColor, getBlock("bark_stripped"));
})
.setBlockTags(BlockTags.LOGS, BlockTags.LOGS_THAT_BURN, tagBlockLog)
.setItemTags(ItemTags.LOGS, ItemTags.LOGS_THAT_BURN, tagItemLog)
);
addBlockEntry(new BlockEntry("planks", (complexMaterial, settings) -> {
return new BaseBlock(settings);
}).setBlockTags(BlockTags.PLANKS));
final Block planks = getBlock("planks");
addBlockEntry(new BlockEntry("stairs", (complexMaterial, settings) -> {
return new BaseStairsBlock(planks);
}));
addBlockEntry(new BlockEntry("slab", (complexMaterial, settings) -> {
return new BaseSlabBlock(planks);
}));
addBlockEntry(new BlockEntry("fence", (complexMaterial, settings) -> {
return new BaseFenceBlock(planks);
}));
addBlockEntry(new BlockEntry("gate", (complexMaterial, settings) -> {
return new BaseGateBlock(planks);
}));
addBlockEntry(new BlockEntry("button", (complexMaterial, settings) -> {
return new BaseWoodenButtonBlock(planks);
}));
addBlockEntry(new BlockEntry("plate", (complexMaterial, settings) -> {
return new WoodenPressurePlateBlock(planks);
}));
addBlockEntry(new BlockEntry("trapdoor", (complexMaterial, settings) -> {
return new BaseTrapdoorBlock(planks);
}));
addBlockEntry(new BlockEntry("door", (complexMaterial, settings) -> {
return new BaseDoorBlock(planks);
}));
addBlockEntry(new BlockEntry("crafting_table", (complexMaterial, settings) -> {
return new BaseCraftingTableBlock(planks);
}));
addBlockEntry(new BlockEntry("ladder", (complexMaterial, settings) -> {
return new BaseLadderBlock(planks);
}).setBlockTags(BlockTags.CLIMBABLE));
addBlockEntry(new BlockEntry("sign", (complexMaterial, settings) -> {
return new BaseSignBlock(planks);
}));
addBlockEntry(new BlockEntry("chest", (complexMaterial, settings) -> {
return new BaseChestBlock(planks);
}));
addBlockEntry(new BlockEntry("barrel", (complexMaterial, settings) -> {
return new BaseBarrelBlock(planks);
}));
addBlockEntry(new BlockEntry("bookshelf", (complexMaterial, settings) -> {
return new BaseBookshelfBlock(planks);
}));
addBlockEntry(new BlockEntry("composter", (complexMaterial, settings) -> {
return new BaseComposterBlock(planks);
}));
}
@Override
public void initRecipes() {
}
}

View file

@ -0,0 +1,58 @@
package ru.bclib.complexmaterials.entry;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import ru.bclib.api.TagAPI;
import ru.bclib.complexmaterials.ComplexMaterial;
import ru.bclib.registry.BlocksRegistry;
import java.util.function.BiFunction;
public class BlockEntry extends ComplexMaterialEntry {
final BiFunction<ComplexMaterial, FabricBlockSettings, Block> initFunction;
final boolean hasItem;
Tag.Named<Block>[] blockTags;
Tag.Named<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(Tag.Named<Block>... blockTags) {
this.blockTags = blockTags;
return this;
}
public BlockEntry setItemTags(Tag.Named<Item>... itemTags) {
this.itemTags = itemTags;
return this;
}
public Block init(ComplexMaterial material, FabricBlockSettings blockSettings, BlocksRegistry registry) {
ResourceLocation location = getLocation(material.getModID(), material.getBaseName());
Block block = initFunction.apply(material, blockSettings);
if (hasItem) {
registry.register(location, block);
if (itemTags != null) {
TagAPI.addTags(block, itemTags);
}
}
else {
registry.registerBlockOnly(location, block);
}
if (blockTags != null) {
TagAPI.addTags(block, blockTags);
}
return block;
}
}

View file

@ -0,0 +1,19 @@
package ru.bclib.complexmaterials.entry;
import net.minecraft.resources.ResourceLocation;
public abstract class ComplexMaterialEntry {
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));
}
}

View file

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

View file

@ -10,7 +10,6 @@ import net.minecraft.world.level.block.Block;
import ru.bclib.interfaces.CustomItemProvider;
public abstract class BlocksRegistry extends BaseRegistry<Block> {
protected BlocksRegistry(CreativeModeTab creativeTab) {
super(creativeTab);
}
@ -33,11 +32,11 @@ public abstract class BlocksRegistry extends BaseRegistry<Block> {
return Registry.register(Registry.BLOCK, id, block);
}
public Block registerBlockOnly(String name, Block block) {
return Registry.register(Registry.BLOCK, createModId(name), block);
public Block registerBlockOnly(ResourceLocation id, Block block) {
return Registry.register(Registry.BLOCK, id, block);
}
public Item registerBlockItem(ResourceLocation id, Item item) {
private Item registerBlockItem(ResourceLocation id, Item item) {
registerItem(id, item, BaseRegistry.getModBlocks(id.getNamespace()));
return item;
}