11package com .tcm .MineTale .datagen ;
22
3+ import com .tcm .MineTale .MineTale ;
34import com .tcm .MineTale .registry .ModBlocks ;
45import net .fabricmc .fabric .api .client .datagen .v1 .provider .FabricModelProvider ;
56import net .fabricmc .fabric .api .datagen .v1 .FabricDataOutput ;
67import net .minecraft .client .data .models .BlockModelGenerators ;
78import net .minecraft .client .data .models .ItemModelGenerators ;
89import net .minecraft .client .data .models .blockstates .MultiVariantGenerator ;
910import net .minecraft .client .data .models .blockstates .PropertyDispatch ;
10- import net .minecraft .client .data .models .model .ModelLocationUtils ;
1111import net .minecraft .client .renderer .block .model .VariantMutator ;
1212import net .minecraft .core .Direction ;
1313import net .minecraft .resources .Identifier ;
1414import net .minecraft .world .level .block .Block ;
1515import net .minecraft .world .level .block .state .properties .BlockStateProperties ;
16- import net .minecraft .world .level .block .state .properties .ChestType ;
1716import net .minecraft .world .level .block .state .properties .DoubleBlockHalf ;
1817
1918public class ModModelProvider extends FabricModelProvider {
@@ -32,12 +31,12 @@ public class ModModelProvider extends FabricModelProvider {
3231 .select (Direction .WEST , BlockModelGenerators .Y_ROT_270 );
3332
3433 /**
35- * Registers block state and model definitions for the mod's log blocks.
34+ * Registers block state and model definitions for the mod's custom log blocks and furnace workbenches .
3635 *
37- * This configures horizontal and vertical log models for each custom log block and, for
38- * WILD_WISTERIA_LOG, also registers the corresponding wood model (WILD_WISTERIA_WOOD) .
36+ * Configures horizontal and vertical variants for each custom log block and registers the wood model for
37+ * WILD_WISTERIA_LOG; registers blockstate variants and item models for the mod's furnace workbench blocks .
3938 *
40- * @param blockStateModelGenerator the generator used to create block state and model entries
39+ * @param blockStateModelGenerator generator used to create block state and model entries
4140 */
4241 @ Override
4342 public void generateBlockStateModels (BlockModelGenerators blockStateModelGenerator ) {
@@ -72,38 +71,41 @@ public void generateBlockStateModels(BlockModelGenerators blockStateModelGenerat
7271 blockStateModelGenerator .woodProvider (ModBlocks .WINDWILLOW_LOG ).logWithHorizontal (ModBlocks .WINDWILLOW_LOG );
7372 blockStateModelGenerator .woodProvider (ModBlocks .WILD_WISTERIA_LOG ).logWithHorizontal (ModBlocks .WILD_WISTERIA_LOG ).wood (ModBlocks .WILD_WISTERIA_WOOD );
7473
75- registerLargeWorkbench (blockStateModelGenerator , ModBlocks .FURNACE_WORKBENCH_BLOCK_T1 );
76- registerLargeWorkbench (blockStateModelGenerator , ModBlocks .FURNACE_WORKBENCH_BLOCK_T2 );
74+ registerFurnaceWorkbench (blockStateModelGenerator , ModBlocks .FURNACE_WORKBENCH_BLOCK_T1 );
75+ registerFurnaceWorkbench (blockStateModelGenerator , ModBlocks .FURNACE_WORKBENCH_BLOCK_T2 );
7776 }
7877
79- private void registerLargeWorkbench (BlockModelGenerators generator , Block block ) {
80- // 1. Get the base identifier (e.g., minetale:block/furnace_workbench_block_t1)
81- Identifier blockId = ModelLocationUtils .getModelLocation (block );
82-
83- // 2. Build the references to your manual JSON files
84- // .withSuffix() creates: minetale:block/furnace_workbench_block_t1_bottom_left, etc.
85- Identifier bottomLeft = blockId .withSuffix ("_bottom_left" );
86- Identifier bottomRight = blockId .withSuffix ("_bottom_right" );
87- Identifier topLeft = blockId .withSuffix ("_top_left" );
88- Identifier topRight = blockId .withSuffix ("_top_right" );
89- Identifier inventory = blockId .withSuffix ("_inventory" );
78+ /**
79+ * Registers block state variants and the item model for a two-block furnace workbench.
80+ *
81+ * Uses explicit shared model identifiers for the top, bottom, and inventory models, dispatches
82+ * the block state by `DOUBLE_BLOCK_HALF` to select the top or bottom model, applies
83+ * `WORKBENCH_ROTATION` for horizontal orientation, and registers the simple item model.
84+ *
85+ * @param generator the BlockModelGenerators instance used to emit blockstate and item model data
86+ * @param block the furnace workbench block to register models for
87+ */
88+ private void registerFurnaceWorkbench (BlockModelGenerators generator , Block block ) {
89+ Identifier topModel = Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "block/bench/furnace_top" );
90+ Identifier bottomModel = Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "block/bench/furnace_bottom" );
91+ Identifier inventoryModel = Identifier .fromNamespaceAndPath (MineTale .MOD_ID , "block/bench/furnace_inventory" );
9092
91- // 3. Dispatch to Blockstate (Tells the game which model to show for each state)
9293 generator .blockStateOutput .accept (MultiVariantGenerator .dispatch (block )
93- .with (PropertyDispatch .initial (BlockStateProperties .DOUBLE_BLOCK_HALF , BlockStateProperties .CHEST_TYPE )
94- .select (DoubleBlockHalf .LOWER , ChestType .LEFT , BlockModelGenerators .plainVariant (bottomLeft ))
95- .select (DoubleBlockHalf .LOWER , ChestType .RIGHT , BlockModelGenerators .plainVariant (bottomRight ))
96- .select (DoubleBlockHalf .UPPER , ChestType .LEFT , BlockModelGenerators .plainVariant (topLeft ))
97- .select (DoubleBlockHalf .UPPER , ChestType .RIGHT , BlockModelGenerators .plainVariant (topRight ))
98- // Support the 'SINGLE' state as a fallback
99- .select (DoubleBlockHalf .LOWER , ChestType .SINGLE , BlockModelGenerators .plainVariant (bottomLeft ))
100- .select (DoubleBlockHalf .UPPER , ChestType .SINGLE , BlockModelGenerators .plainVariant (topLeft ))
94+ .with (PropertyDispatch .initial (
95+ BlockStateProperties .DOUBLE_BLOCK_HALF ,
96+ BlockStateProperties .CHEST_TYPE ,
97+ BlockStateProperties .LIT
98+ )
99+ .generate ((half , type , lit ) -> {
100+ return half == DoubleBlockHalf .UPPER
101+ ? BlockModelGenerators .plainVariant (topModel )
102+ : BlockModelGenerators .plainVariant (bottomModel );
103+ })
101104 )
102105 .with (WORKBENCH_ROTATION )
103106 );
104107
105- // 4. Map the Item in your hand to the inventory JSON
106- generator .registerSimpleItemModel (block , inventory );
108+ generator .registerSimpleItemModel (block , inventoryModel );
107109 }
108110
109111 /**
0 commit comments