Complex materials, wood material (WIP)
This commit is contained in:
parent
eb4f70b8a2
commit
0eaaae2f99
7 changed files with 435 additions and 250 deletions
169
src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java
Normal file
169
src/main/java/ru/bclib/complexmaterials/ComplexMaterial.java
Normal 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;
|
||||
}
|
||||
}
|
149
src/main/java/ru/bclib/complexmaterials/WoodenMaterial.java
Normal file
149
src/main/java/ru/bclib/complexmaterials/WoodenMaterial.java
Normal 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() {
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
37
src/main/java/ru/bclib/complexmaterials/entry/ItemEntry.java
Normal file
37
src/main/java/ru/bclib/complexmaterials/entry/ItemEntry.java
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue