95 lines
3.6 KiB
Java
95 lines
3.6 KiB
Java
package org.betterx.bclib.registry;
|
|
|
|
import org.betterx.bclib.blocks.BaseLeavesBlock;
|
|
import org.betterx.bclib.blocks.BaseOreBlock;
|
|
import org.betterx.bclib.blocks.FeatureSaplingBlock;
|
|
import org.betterx.bclib.config.PathConfig;
|
|
import org.betterx.bclib.interfaces.CustomItemProvider;
|
|
import org.betterx.worlds.together.tag.CommonBlockTags;
|
|
import org.betterx.worlds.together.tag.CommonItemTags;
|
|
import org.betterx.worlds.together.tag.MineableTags;
|
|
import org.betterx.worlds.together.tag.TagManager;
|
|
|
|
import net.minecraft.core.Registry;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.tags.BlockTags;
|
|
import net.minecraft.tags.ItemTags;
|
|
import net.minecraft.world.item.BlockItem;
|
|
import net.minecraft.world.item.CreativeModeTab;
|
|
import net.minecraft.world.item.Item;
|
|
import net.minecraft.world.item.Items;
|
|
import net.minecraft.world.level.block.Block;
|
|
|
|
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
|
|
|
|
public class BlockRegistry extends BaseRegistry<Block> {
|
|
public BlockRegistry(CreativeModeTab creativeTab, PathConfig config) {
|
|
super(creativeTab, config);
|
|
}
|
|
|
|
@Override
|
|
public Block register(ResourceLocation id, Block block) {
|
|
if (!config.getBooleanRoot(id.getNamespace(), true)) {
|
|
return block;
|
|
}
|
|
|
|
BlockItem item = null;
|
|
if (block instanceof CustomItemProvider) {
|
|
item = ((CustomItemProvider) block).getCustomItem(id, makeItemSettings());
|
|
} else {
|
|
item = new BlockItem(block, makeItemSettings());
|
|
}
|
|
registerBlockItem(id, item);
|
|
if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance()
|
|
.get(block)
|
|
.getBurnChance() == 0) {
|
|
FlammableBlockRegistry.getDefaultInstance().add(block, 5, 5);
|
|
}
|
|
|
|
block = Registry.register(Registry.BLOCK, id, block);
|
|
getModBlocks(id.getNamespace()).add(block);
|
|
|
|
if (block instanceof BaseLeavesBlock) {
|
|
TagManager.BLOCKS.add(
|
|
block,
|
|
BlockTags.LEAVES,
|
|
CommonBlockTags.LEAVES,
|
|
MineableTags.HOE,
|
|
MineableTags.SHEARS
|
|
);
|
|
if (item != null) {
|
|
TagManager.ITEMS.add(item, CommonItemTags.LEAVES, ItemTags.LEAVES);
|
|
}
|
|
} else if (block instanceof BaseOreBlock) {
|
|
TagManager.BLOCKS.add(block, MineableTags.PICKAXE);
|
|
} else if (block instanceof FeatureSaplingBlock) {
|
|
TagManager.BLOCKS.add(block, CommonBlockTags.SAPLINGS, BlockTags.SAPLINGS);
|
|
if (item != null) {
|
|
TagManager.ITEMS.add(item, CommonItemTags.SAPLINGS, ItemTags.SAPLINGS);
|
|
}
|
|
}
|
|
|
|
return block;
|
|
}
|
|
|
|
public Block registerBlockOnly(ResourceLocation id, Block block) {
|
|
if (!config.getBooleanRoot(id.getNamespace(), true)) {
|
|
return block;
|
|
}
|
|
getModBlocks(id.getNamespace()).add(block);
|
|
return Registry.register(Registry.BLOCK, id, block);
|
|
}
|
|
|
|
private Item registerBlockItem(ResourceLocation id, Item item) {
|
|
registerItem(id, item);
|
|
return item;
|
|
}
|
|
|
|
@Override
|
|
public void registerItem(ResourceLocation id, Item item) {
|
|
if (item != null && item != Items.AIR) {
|
|
Registry.register(Registry.ITEM, id, item);
|
|
getModBlockItems(id.getNamespace()).add(item);
|
|
}
|
|
}
|
|
}
|