Fixes
This commit is contained in:
parent
50861c4c1c
commit
8e9165cd0c
6 changed files with 39 additions and 32 deletions
|
@ -21,22 +21,22 @@ import ru.bclib.blocks.BaseFurnaceBlock;
|
|||
import ru.bclib.blocks.BaseSignBlock;
|
||||
|
||||
public class BaseBlockEntities {
|
||||
public static final BlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntity(BCLib.makeID("chest"),
|
||||
public static final BlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"),
|
||||
BlockEntityType.Builder.of(BaseChestBlockEntity::new, getChests()));
|
||||
public static final BlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntity(BCLib.makeID("barrel"),
|
||||
public static final BlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"),
|
||||
BlockEntityType.Builder.of(BaseBarrelBlockEntity::new, getBarrels()));
|
||||
public static final BlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntity(BCLib.makeID("sign"),
|
||||
public static final BlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"),
|
||||
BlockEntityType.Builder.of(BaseSignBlockEntity::new, getSigns()));
|
||||
public static final BlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntity(BCLib.makeID("furnace"),
|
||||
public static final BlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"),
|
||||
BlockEntityType.Builder.of(BaseFurnaceBlockEntity::new, getFurnaces()));
|
||||
|
||||
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntity(ResourceLocation blockId, BlockEntityType.Builder<T> builder) {
|
||||
public static <T extends BlockEntity> BlockEntityType<T> registerBlockEntityType(ResourceLocation blockId, BlockEntityType.Builder<T> builder) {
|
||||
return Registry.register(Registry.BLOCK_ENTITY_TYPE, blockId, builder.build(null));
|
||||
}
|
||||
|
||||
public static void register() {}
|
||||
|
||||
static Block[] getChests() {
|
||||
private static Block[] getChests() {
|
||||
List<Block> result = Lists.newArrayList();
|
||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
|
@ -48,8 +48,8 @@ public class BaseBlockEntities {
|
|||
});
|
||||
return result.toArray(new Block[] {});
|
||||
}
|
||||
|
||||
static Block[] getBarrels() {
|
||||
|
||||
private static Block[] getBarrels() {
|
||||
List<Block> result = Lists.newArrayList();
|
||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
|
@ -61,8 +61,8 @@ public class BaseBlockEntities {
|
|||
});
|
||||
return result.toArray(new Block[] {});
|
||||
}
|
||||
|
||||
static Block[] getSigns() {
|
||||
|
||||
private static Block[] getSigns() {
|
||||
List<Block> result = Lists.newArrayList();
|
||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
|
@ -74,8 +74,8 @@ public class BaseBlockEntities {
|
|||
});
|
||||
return result.toArray(new Block[] {});
|
||||
}
|
||||
|
||||
static Block[] getFurnaces() {
|
||||
|
||||
private static Block[] getFurnaces() {
|
||||
List<Block> result = Lists.newArrayList();
|
||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||
if (item instanceof BlockItem) {
|
||||
|
|
|
@ -5,15 +5,17 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.*;
|
||||
import ru.bclib.BCLib;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseRegistry<T> {
|
||||
|
||||
private static final List<BaseRegistry<?>> REGISTRIES = Lists.newArrayList();
|
||||
|
||||
protected static final List<Item> MOD_BLOCKS = Lists.newArrayList();
|
||||
protected static final List<Item> MOD_ITEMS = Lists.newArrayList();
|
||||
|
||||
public static void register() {}
|
||||
|
||||
public static List<Item> getModBlocks() {
|
||||
return MOD_BLOCKS;
|
||||
}
|
||||
|
@ -22,21 +24,28 @@ public abstract class BaseRegistry<T> {
|
|||
return MOD_ITEMS;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
REGISTRIES.forEach(BaseRegistry::registerDependency);
|
||||
}
|
||||
|
||||
protected final CreativeModeTab creativeTab;
|
||||
|
||||
protected BaseRegistry(CreativeModeTab creativeTab) {
|
||||
this.creativeTab = creativeTab;
|
||||
REGISTRIES.add(this);
|
||||
}
|
||||
|
||||
protected T register(String name, T obj) {
|
||||
public T register(String name, T obj) {
|
||||
return register(createModId(name), obj);
|
||||
}
|
||||
|
||||
protected abstract T register(ResourceLocation objId, T obj);
|
||||
public abstract T register(ResourceLocation objId, T obj);
|
||||
|
||||
protected abstract ResourceLocation createModId(String name);
|
||||
public ResourceLocation createModId(String name) {
|
||||
return BCLib.makeID(name);
|
||||
}
|
||||
|
||||
protected void registerItem(ResourceLocation id, Item item, List<Item> registry) {
|
||||
public void registerItem(ResourceLocation id, Item item, List<Item> registry) {
|
||||
if (item != Items.AIR) {
|
||||
Registry.register(Registry.ITEM, id, item);
|
||||
registry.add(item);
|
||||
|
@ -47,4 +56,6 @@ public abstract class BaseRegistry<T> {
|
|||
FabricItemSettings properties = new FabricItemSettings();
|
||||
return (FabricItemSettings) properties.tab(creativeTab);
|
||||
}
|
||||
|
||||
private void registerDependency() {}
|
||||
}
|
||||
|
|
|
@ -38,18 +38,10 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
|
|||
|
||||
@Override
|
||||
public Item register(ResourceLocation itemId, Item item) {
|
||||
if (item instanceof ArmorItem) {
|
||||
return registerArmor(itemId, item);
|
||||
}
|
||||
registerItem(itemId, item, BaseRegistry.MOD_ITEMS);
|
||||
return item;
|
||||
}
|
||||
|
||||
private Item registerArmor(ResourceLocation id, Item item) {
|
||||
registerItem(id, item, BaseRegistry.MOD_ITEMS);
|
||||
return item;
|
||||
}
|
||||
|
||||
public TieredItem registerTool(String name, TieredItem item) {
|
||||
ResourceLocation id = createModId(name);
|
||||
registerItem(id, item, BaseRegistry.MOD_ITEMS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue