Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
refactor: convert several more block types to chimericlib
Browse files Browse the repository at this point in the history
  • Loading branch information
chimericdream committed Oct 6, 2024
1 parent be936f1 commit ab89f2e
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 103 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ archives_base_name = minekea-fabric
fabric_version = 0.101.1+1.21
cloth_config_version = 15.0.128
mod_menu_version = 11.0.1
chimericlib_version = 1.0.0-alpha.10
chimericlib_version = 1.0.0-alpha.13

# Optional Dependencies
patchouli_version = 1.21-87-FABRIC
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.chimericdream.minekea.block.building.walls;

import com.chimericdream.lib.blocks.ModBlock;
import com.chimericdream.lib.fabric.blocks.FabricModWallBlock;
import com.chimericdream.minekea.ModInfo;
import com.chimericdream.minekea.util.MinekeaBlock;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricRecipeProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
Expand All @@ -10,7 +11,6 @@
import net.fabricmc.fabric.api.registry.FuelRegistry;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.WallBlock;
import net.minecraft.block.enums.WallShape;
import net.minecraft.data.client.BlockStateModelGenerator;
import net.minecraft.data.client.BlockStateVariant;
Expand All @@ -36,37 +36,20 @@

import java.util.function.Function;

public class GenericWallBlock extends WallBlock implements MinekeaBlock {
public class GenericWallBlock extends FabricModWallBlock {
public final Identifier BLOCK_ID;

protected final String materialName;
protected final String material;
protected final boolean isFlammable;
protected final Block ingredient;
protected final Identifier textureId;
public GenericWallBlock(ModBlock.ModBlockConfig config) {
super(config.settings(AbstractBlock.Settings.copy(config.getIngredient())));

public GenericWallBlock(String materialName, String material, boolean isFlammable, Block ingredient) {
this(materialName, material, isFlammable, ingredient, TextureMap.getId(ingredient));
BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("building/walls/%s", config.getMaterial()));
}

public GenericWallBlock(String materialName, String material, boolean isFlammable, Block ingredient, Identifier textureId) {
super(AbstractBlock.Settings.copy(ingredient));

this.materialName = materialName;
this.material = material;
this.isFlammable = isFlammable;
this.ingredient = ingredient;
this.textureId = textureId;

BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("building/walls/%s", material));
}

@Override
public void register() {
Registry.register(Registries.BLOCK, BLOCK_ID, this);
Registry.register(Registries.ITEM, BLOCK_ID, new BlockItem(this, new Item.Settings()));

if (isFlammable) {
if (config.isFlammable()) {
FuelRegistry.INSTANCE.add(this, 300);
FlammableBlockRegistry.getDefaultInstance().add(this, 30, 20);
}
Expand All @@ -84,6 +67,8 @@ public void configureBlockTags(RegistryWrapper.WrapperLookup registryLookup, Fun

@Override
public void configureRecipes(RecipeExporter exporter) {
Block ingredient = config.getIngredient();

ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, this, 6)
.pattern("###")
.pattern("###")
Expand All @@ -100,13 +85,13 @@ public void configureBlockLootTables(RegistryWrapper.WrapperLookup registryLooku

@Override
public void configureTranslations(RegistryWrapper.WrapperLookup registryLookup, FabricLanguageProvider.TranslationBuilder translationBuilder) {
translationBuilder.add(this, String.format("%s Wall", materialName));
translationBuilder.add(this, String.format("%s Wall", config.getMaterialName()));
}

@Override
public void configureBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
TextureMap textures = new TextureMap()
.put(TextureKey.WALL, textureId);
.put(TextureKey.WALL, config.getTexture());

Identifier inventoryModelId = blockStateModelGenerator.createSubModel(this, "", Models.WALL_INVENTORY, unused -> textures);
Identifier postModelId = blockStateModelGenerator.createSubModel(this, "", Models.TEMPLATE_WALL_POST, unused -> textures);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.chimericdream.minekea.block.building.walls;

import com.chimericdream.lib.blocks.ModBlock;
import com.chimericdream.minekea.block.building.BuildingBlocks;
import com.chimericdream.minekea.block.building.general.BasaltBricksBlock;
import com.chimericdream.minekea.block.building.general.CrackedBasaltBricksBlock;
import com.chimericdream.minekea.block.building.general.CrimsonBasaltBricksBlock;
import com.chimericdream.minekea.block.building.general.MossyBasaltBricksBlock;
import com.chimericdream.minekea.block.building.general.WarpedBasaltBricksBlock;
import com.chimericdream.minekea.block.building.general.WarpedNetherBricksBlock;
import com.chimericdream.minekea.util.MinekeaBlock;
import com.chimericdream.minekea.util.MinekeaBlockCategory;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricLanguageProvider;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
Expand All @@ -25,20 +25,20 @@
import java.util.function.Function;

public class Walls implements MinekeaBlockCategory {
public static final List<MinekeaBlock> WALLS = new ArrayList<>();
public static final List<GenericWallBlock> WALLS = new ArrayList<>();

static {
WALLS.add(new GenericWallBlock("Basalt Brick", "basalt_bricks", false, BuildingBlocks.BASALT_BRICKS_BLOCK, BasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock("Cracked Basalt Brick", "cracked_basalt_bricks", false, BuildingBlocks.CRACKED_BASALT_BRICKS_BLOCK, CrackedBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock("Crimson Basalt Brick", "crimson_basalt_bricks", false, BuildingBlocks.CRIMSON_BASALT_BRICKS_BLOCK, CrimsonBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock("Mossy Basalt Brick", "mossy_basalt_bricks", false, BuildingBlocks.MOSSY_BASALT_BRICKS_BLOCK, MossyBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock("Warped Basalt Brick", "warped_basalt_bricks", false, BuildingBlocks.WARPED_BASALT_BRICKS_BLOCK, WarpedBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock("Warped Nether Brick", "warped_nether_bricks", false, BuildingBlocks.WARPED_NETHER_BRICKS_BLOCK, WarpedNetherBricksBlock.BLOCK_ID.withPrefixedPath("block/")));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("basalt_bricks").materialName("Basalt Brick").ingredient(BuildingBlocks.BASALT_BRICKS_BLOCK).texture(BasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("cracked_basalt_bricks").materialName("Cracked Basalt Brick").ingredient(BuildingBlocks.CRACKED_BASALT_BRICKS_BLOCK).texture(CrackedBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("crimson_basalt_bricks").materialName("Crimson Basalt Brick").ingredient(BuildingBlocks.CRIMSON_BASALT_BRICKS_BLOCK).texture(CrimsonBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("mossy_basalt_bricks").materialName("Mossy Basalt Brick").ingredient(BuildingBlocks.MOSSY_BASALT_BRICKS_BLOCK).texture(MossyBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("warped_basalt_bricks").materialName("Warped Basalt Brick").ingredient(BuildingBlocks.WARPED_BASALT_BRICKS_BLOCK).texture(WarpedBasaltBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
WALLS.add(new GenericWallBlock(new ModBlock.ModBlockConfig().material("warped_nether_bricks").materialName("Warped Nether Brick").ingredient(BuildingBlocks.WARPED_NETHER_BRICKS_BLOCK).texture(WarpedNetherBricksBlock.BLOCK_ID.withPrefixedPath("block/"))));
}

@Override
public void registerBlocks() {
WALLS.forEach(MinekeaBlock::register);
WALLS.forEach(GenericWallBlock::register);
}

@Override
Expand Down Expand Up @@ -78,6 +78,6 @@ public void configureItemModels(ItemModelGenerator itemModelGenerator) {

@Override
public void generateTextures() {
WALLS.forEach(MinekeaBlock::generateTextures);
WALLS.forEach(GenericWallBlock::generateTextures);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.chimericdream.minekea.block.furniture.armoires;

import com.chimericdream.lib.blocks.ModBlock;
import com.chimericdream.lib.fabric.blocks.FabricModBlock;
import com.chimericdream.minekea.client.render.block.ArmoireBlockEntityRenderer;
import com.chimericdream.minekea.entities.blocks.furniture.ArmoireBlockEntity;
import com.chimericdream.minekea.util.MinekeaBlockCategory;
Expand Down Expand Up @@ -31,7 +30,7 @@
import java.util.function.Function;

public class Armoires implements MinekeaBlockCategory {
public static final List<FabricModBlock> ARMOIRES = new ArrayList<>();
public static final List<GenericArmoireBlock> ARMOIRES = new ArrayList<>();

public static BlockEntityType<ArmoireBlockEntity> ARMOIRE_BLOCK_ENTITY;

Expand Down Expand Up @@ -59,7 +58,7 @@ public void initializeClient() {

@Override
public void registerBlocks() {
ARMOIRES.forEach(ModBlock::register);
ARMOIRES.forEach(GenericArmoireBlock::register);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public GenericArmoireBlock(ModBlockConfig config) {
.with(HALF, DoubleBlockHalf.LOWER)
);

BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/armoires/%s", this.getMaterial()));
BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/armoires/%s", this.config.getMaterial()));
}

protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
Expand Down Expand Up @@ -513,12 +513,11 @@ public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockSt
}
}

@Override
public void register() {
Registry.register(Registries.BLOCK, BLOCK_ID, this);
Registry.register(Registries.ITEM, BLOCK_ID, new BlockItem(this, new Item.Settings()));

if (this.isFlammable()) {
if (this.config.isFlammable()) {
FuelRegistry.INSTANCE.add(this, 300);
FlammableBlockRegistry.getDefaultInstance().add(this, 30, 20);
}
Expand All @@ -535,8 +534,8 @@ public void configureBlockTags(RegistryWrapper.WrapperLookup registryLookup, Fun

@Override
public void configureRecipes(RecipeExporter exporter) {
Block slabIngredient = this.getIngredient("slab");
Block plankIngredient = this.getIngredient("planks");
Block slabIngredient = this.config.getIngredient("slab");
Block plankIngredient = this.config.getIngredient("planks");

ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, this, 1)
.pattern("BSB")
Expand Down Expand Up @@ -564,14 +563,14 @@ public void configureBlockLootTables(RegistryWrapper.WrapperLookup registryLooku

@Override
public void configureTranslations(RegistryWrapper.WrapperLookup registryLookup, FabricLanguageProvider.TranslationBuilder translationBuilder) {
translationBuilder.add(this, String.format("%s Armor-oire", this.getMaterialName()));
translationBuilder.add(this, String.format("%s Armor-oire", this.config.getMaterialName()));
}

@Override
public void configureBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
TextureMap textures = new TextureMap()
.put(MinekeaTextures.BAR, Registries.BLOCK.getId(Blocks.NETHERITE_BLOCK).withPrefixedPath("block/"))
.put(MinekeaTextures.MATERIAL, Registries.BLOCK.getId(this.getIngredient("log")).withPrefixedPath("block/"))
.put(MinekeaTextures.MATERIAL, Registries.BLOCK.getId(this.config.getIngredient("log")).withPrefixedPath("block/"))
.put(MinekeaTextures.PLANKS, Registries.BLOCK.getId(Blocks.OAK_PLANKS).withPrefixedPath("block/"));

Identifier topModelId = blockStateModelGenerator.createSubModel(this, "_top", TOP_MODEL, unused -> textures);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,16 @@ public class GenericBookshelf extends FabricModBlock {
public GenericBookshelf(ModBlockConfig config) {
super(config);

BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/bookshelves/%s", this.getMaterial()));
BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/bookshelves/%s", this.config.getMaterial()));
}

@Override
public void register() {
Registry.register(Registries.BLOCK, BLOCK_ID, this);
Registry.register(Registries.ITEM, BLOCK_ID, new BlockItem(this, new Item.Settings()));

ItemGroupEvents.modifyEntriesEvent(ItemGroups.BUILDING_BLOCKS).register(itemGroup -> itemGroup.add(this));

if (this.isFlammable()) {
if (this.config.isFlammable()) {
FuelRegistry.INSTANCE.add(this, 300);
FlammableBlockRegistry.getDefaultInstance().add(this, 30, 20);
}
Expand All @@ -72,7 +71,7 @@ public void configureBlockTags(RegistryWrapper.WrapperLookup registryLookup, Fun

@Override
public void configureRecipes(RecipeExporter exporter) {
Block ingredient = this.getIngredient();
Block ingredient = this.config.getIngredient();

ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, this, 3)
.pattern("###")
Expand All @@ -94,12 +93,12 @@ public void configureBlockLootTables(RegistryWrapper.WrapperLookup registryLooku

@Override
public void configureTranslations(RegistryWrapper.WrapperLookup registryLookup, FabricLanguageProvider.TranslationBuilder translationBuilder) {
translationBuilder.add(this, String.format("%s Bookshelf", this.getMaterialName()));
translationBuilder.add(this, String.format("%s Bookshelf", this.config.getMaterialName()));
}

@Override
public void configureBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
TextureMap textures = new TextureMap().put(MinekeaTextures.MATERIAL, this.getTexture());
TextureMap textures = new TextureMap().put(MinekeaTextures.MATERIAL, this.config.getTexture());

Identifier variant0Id = blockStateModelGenerator.createSubModel(this, "_v0", BOOKSHELF_MODEL, unused -> textures.put(MinekeaTextures.SHELF, Identifier.of(ModInfo.MOD_ID, "block/furniture/bookshelves/shelf0")));
Identifier variant1Id = blockStateModelGenerator.createSubModel(this, "_v1", BOOKSHELF_MODEL, unused -> textures.put(MinekeaTextures.SHELF, Identifier.of(ModInfo.MOD_ID, "block/furniture/bookshelves/shelf1")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void initializeClient() {

@Override
public void registerBlocks() {
DISPLAY_CASES.forEach(ModBlock::register);
DISPLAY_CASES.forEach(GenericDisplayCase::register);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public class GenericDisplayCase extends FabricModBlockWithEntity implements Wate
public GenericDisplayCase(ModBlockConfig config) {
super(config.settings(AbstractBlock.Settings.copy(config.getIngredient("planks"))));

BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/display_cases/%s", this.getMaterial()));
BLOCK_ID = Identifier.of(ModInfo.MOD_ID, String.format("furniture/display_cases/%s", this.config.getMaterial()));

this.setDefaultState(
this.stateManager.getDefaultState()
Expand All @@ -98,7 +98,6 @@ public GenericDisplayCase(ModBlockConfig config) {
);
}

@Override
public void register() {
Registry.register(Registries.BLOCK, BLOCK_ID, this);
Registry.register(Registries.ITEM, BLOCK_ID, new BlockItem(this, new Item.Settings()));
Expand All @@ -107,7 +106,7 @@ public void register() {
itemGroup.add(this);
});

if (this.isFlammable()) {
if (this.config.isFlammable()) {
FuelRegistry.INSTANCE.add(this, 300);
FlammableBlockRegistry.getDefaultInstance().add(this, 30, 20);
}
Expand Down Expand Up @@ -320,8 +319,8 @@ public void configureItemTags(RegistryWrapper.WrapperLookup registryLookup, Func

@Override
public void configureRecipes(RecipeExporter exporter) {
Block plankIngredient = this.getIngredient("planks");
Block logIngredient = this.getIngredient("log");
Block plankIngredient = this.config.getIngredient("planks");
Block logIngredient = this.config.getIngredient("log");

ShapedRecipeJsonBuilder.create(RecipeCategory.BUILDING_BLOCKS, this, 1)
.pattern(" G ")
Expand All @@ -346,13 +345,13 @@ public void configureBlockLootTables(RegistryWrapper.WrapperLookup registryLooku

@Override
public void configureTranslations(RegistryWrapper.WrapperLookup registryLookup, FabricLanguageProvider.TranslationBuilder translationBuilder) {
translationBuilder.add(this, String.format("%s Display Case", this.getMaterialName()));
translationBuilder.add(this, String.format("%s Display Case", this.config.getMaterialName()));
}

@Override
public void configureBlockStateModels(BlockStateModelGenerator blockStateModelGenerator) {
Block logIngredient = this.getIngredient("log");
Block strippedLogIngredient = Optional.ofNullable(this.getIngredient("stripped_log")).orElse(logIngredient);
Block logIngredient = this.config.getIngredient("log");
Block strippedLogIngredient = Optional.ofNullable(this.config.getIngredient("stripped_log")).orElse(logIngredient);

TextureMap textures = new TextureMap()
.put(MinekeaTextures.MATERIAL, TextureMap.getId(logIngredient))
Expand Down
Loading

0 comments on commit ab89f2e

Please sign in to comment.