Fixes
This commit is contained in:
parent
50861c4c1c
commit
8e9165cd0c
6 changed files with 39 additions and 32 deletions
|
@ -4,6 +4,8 @@ import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import ru.bclib.registry.BaseBlockEntities;
|
||||||
|
import ru.bclib.registry.BaseRegistry;
|
||||||
import ru.bclib.util.Logger;
|
import ru.bclib.util.Logger;
|
||||||
import ru.bclib.world.surface.BCLSurfaceBuilders;
|
import ru.bclib.world.surface.BCLSurfaceBuilders;
|
||||||
import ru.bclib.api.TagAPI;
|
import ru.bclib.api.TagAPI;
|
||||||
|
@ -14,6 +16,8 @@ public class BCLib implements ModInitializer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
BaseRegistry.register();
|
||||||
|
BaseBlockEntities.register();
|
||||||
BCLSurfaceBuilders.register();
|
BCLSurfaceBuilders.register();
|
||||||
TagAPI.init();
|
TagAPI.init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,8 +46,8 @@ import ru.bclib.client.sound.BlockSounds;
|
||||||
public class BaseTerrainBlock extends BaseBlock {
|
public class BaseTerrainBlock extends BaseBlock {
|
||||||
private Block pathBlock;
|
private Block pathBlock;
|
||||||
|
|
||||||
public BaseTerrainBlock(MaterialColor color) {
|
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
|
||||||
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
|
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathBlock(Block roadBlock) {
|
public void setPathBlock(Block roadBlock) {
|
||||||
|
|
|
@ -40,9 +40,9 @@ import ru.bclib.client.models.PatternsHelper;
|
||||||
public class TripleTerrainBlock extends BaseTerrainBlock {
|
public class TripleTerrainBlock extends BaseTerrainBlock {
|
||||||
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
|
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
|
||||||
|
|
||||||
public TripleTerrainBlock(MaterialColor color) {
|
public TripleTerrainBlock(Block baseBlock, MaterialColor color) {
|
||||||
super(color);
|
super(baseBlock, color);
|
||||||
this.registerDefaultState(this.defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM));
|
this.registerDefaultState(defaultBlockState().setValue(SHAPE, TripleShape.BOTTOM));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +54,7 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
|
||||||
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||||
Direction dir = ctx.getClickedFace();
|
Direction dir = ctx.getClickedFace();
|
||||||
TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE;
|
TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE;
|
||||||
return this.defaultBlockState().setValue(SHAPE, shape);
|
return defaultBlockState().setValue(SHAPE, shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -21,22 +21,22 @@ import ru.bclib.blocks.BaseFurnaceBlock;
|
||||||
import ru.bclib.blocks.BaseSignBlock;
|
import ru.bclib.blocks.BaseSignBlock;
|
||||||
|
|
||||||
public class BaseBlockEntities {
|
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()));
|
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()));
|
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()));
|
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()));
|
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));
|
return Registry.register(Registry.BLOCK_ENTITY_TYPE, blockId, builder.build(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void register() {}
|
public static void register() {}
|
||||||
|
|
||||||
static Block[] getChests() {
|
private static Block[] getChests() {
|
||||||
List<Block> result = Lists.newArrayList();
|
List<Block> result = Lists.newArrayList();
|
||||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||||
if (item instanceof BlockItem) {
|
if (item instanceof BlockItem) {
|
||||||
|
@ -48,8 +48,8 @@ public class BaseBlockEntities {
|
||||||
});
|
});
|
||||||
return result.toArray(new Block[] {});
|
return result.toArray(new Block[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Block[] getBarrels() {
|
private static Block[] getBarrels() {
|
||||||
List<Block> result = Lists.newArrayList();
|
List<Block> result = Lists.newArrayList();
|
||||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||||
if (item instanceof BlockItem) {
|
if (item instanceof BlockItem) {
|
||||||
|
@ -61,8 +61,8 @@ public class BaseBlockEntities {
|
||||||
});
|
});
|
||||||
return result.toArray(new Block[] {});
|
return result.toArray(new Block[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Block[] getSigns() {
|
private static Block[] getSigns() {
|
||||||
List<Block> result = Lists.newArrayList();
|
List<Block> result = Lists.newArrayList();
|
||||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||||
if (item instanceof BlockItem) {
|
if (item instanceof BlockItem) {
|
||||||
|
@ -74,8 +74,8 @@ public class BaseBlockEntities {
|
||||||
});
|
});
|
||||||
return result.toArray(new Block[] {});
|
return result.toArray(new Block[] {});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Block[] getFurnaces() {
|
private static Block[] getFurnaces() {
|
||||||
List<Block> result = Lists.newArrayList();
|
List<Block> result = Lists.newArrayList();
|
||||||
BaseRegistry.getModBlocks().forEach((item) -> {
|
BaseRegistry.getModBlocks().forEach((item) -> {
|
||||||
if (item instanceof BlockItem) {
|
if (item instanceof BlockItem) {
|
||||||
|
|
|
@ -5,15 +5,17 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.*;
|
import net.minecraft.world.item.*;
|
||||||
|
import ru.bclib.BCLib;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class BaseRegistry<T> {
|
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_BLOCKS = Lists.newArrayList();
|
||||||
protected static final List<Item> MOD_ITEMS = Lists.newArrayList();
|
protected static final List<Item> MOD_ITEMS = Lists.newArrayList();
|
||||||
|
|
||||||
public static void register() {}
|
|
||||||
|
|
||||||
public static List<Item> getModBlocks() {
|
public static List<Item> getModBlocks() {
|
||||||
return MOD_BLOCKS;
|
return MOD_BLOCKS;
|
||||||
}
|
}
|
||||||
|
@ -22,21 +24,28 @@ public abstract class BaseRegistry<T> {
|
||||||
return MOD_ITEMS;
|
return MOD_ITEMS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
REGISTRIES.forEach(BaseRegistry::registerDependency);
|
||||||
|
}
|
||||||
|
|
||||||
protected final CreativeModeTab creativeTab;
|
protected final CreativeModeTab creativeTab;
|
||||||
|
|
||||||
protected BaseRegistry(CreativeModeTab creativeTab) {
|
protected BaseRegistry(CreativeModeTab creativeTab) {
|
||||||
this.creativeTab = 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);
|
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) {
|
if (item != Items.AIR) {
|
||||||
Registry.register(Registry.ITEM, id, item);
|
Registry.register(Registry.ITEM, id, item);
|
||||||
registry.add(item);
|
registry.add(item);
|
||||||
|
@ -47,4 +56,6 @@ public abstract class BaseRegistry<T> {
|
||||||
FabricItemSettings properties = new FabricItemSettings();
|
FabricItemSettings properties = new FabricItemSettings();
|
||||||
return (FabricItemSettings) properties.tab(creativeTab);
|
return (FabricItemSettings) properties.tab(creativeTab);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void registerDependency() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,18 +38,10 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Item register(ResourceLocation itemId, Item item) {
|
public Item register(ResourceLocation itemId, Item item) {
|
||||||
if (item instanceof ArmorItem) {
|
|
||||||
return registerArmor(itemId, item);
|
|
||||||
}
|
|
||||||
registerItem(itemId, item, BaseRegistry.MOD_ITEMS);
|
registerItem(itemId, item, BaseRegistry.MOD_ITEMS);
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Item registerArmor(ResourceLocation id, Item item) {
|
|
||||||
registerItem(id, item, BaseRegistry.MOD_ITEMS);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TieredItem registerTool(String name, TieredItem item) {
|
public TieredItem registerTool(String name, TieredItem item) {
|
||||||
ResourceLocation id = createModId(name);
|
ResourceLocation id = createModId(name);
|
||||||
registerItem(id, item, BaseRegistry.MOD_ITEMS);
|
registerItem(id, item, BaseRegistry.MOD_ITEMS);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue