11package com .tcm .MineTale .block .workbenches ;
22
3- import java .util .function .Supplier ;
4-
53import org .jetbrains .annotations .Nullable ;
64
5+ import com .mojang .serialization .Codec ;
76import com .mojang .serialization .MapCodec ;
7+ import com .mojang .serialization .codecs .RecordCodecBuilder ;
88import com .tcm .MineTale .block .workbenches .entity .FurnaceWorkbenchEntity ;
9- import com .tcm .MineTale .registry .ModBlockEntities ;
9+ import com .tcm .MineTale .registry .ModTiers ;
10+ import com .tcm .MineTale .registry .ModTiers .FurnaceTier ;
1011
1112import net .minecraft .core .BlockPos ;
1213import net .minecraft .world .level .Level ;
@@ -21,26 +22,33 @@ public class FurnaceWorkbench extends AbstractWorkbench<FurnaceWorkbenchEntity>
2122 private static final boolean IS_WIDE = true ;
2223 private static final boolean IS_TALL = true ;
2324
24- public static final MapCodec <FurnaceWorkbench > CODEC = simpleCodec (FurnaceWorkbench ::new );
25+ public static final MapCodec <FurnaceWorkbench > CODEC = RecordCodecBuilder .mapCodec (instance ->
26+ instance .group (
27+ // This handles the standard block properties
28+ propertiesCodec (),
29+ // This handles the tier (assuming FurnaceTier is a record/enum with its own codec)
30+ Codec .INT .fieldOf ("tier" ).forGetter (block -> block .getTier ())
31+ ).apply (instance , (props , id ) -> new FurnaceWorkbench (props , ModTiers .getTierFromInt (id )))
32+ );
2533
2634 /**
2735 * Creates a FurnaceWorkbench using the default furnace workbench block entity type and a 2×2 footprint.
2836 *
2937 * @param properties block properties for this workbench
3038 */
31- public FurnaceWorkbench (Properties properties ) {
32- super (properties , () -> ModBlockEntities . FURNACE_WORKBENCH_BE , IS_WIDE , IS_TALL );
39+ public FurnaceWorkbench (Properties properties , FurnaceTier tier ) {
40+ super (properties , () -> ModTiers . TIER_MAP . get ( tier ) , IS_WIDE , IS_TALL , tier . id () );
3341 }
3442
35- /**
36- * Creates a FurnaceWorkbench that uses a custom BlockEntityType supplier and a 2x2 footprint.
37- *
38- * @param properties block properties for this workbench
39- * @param supplier supplies the BlockEntityType to use for the workbench's master block entity
40- */
41- public FurnaceWorkbench (Properties properties , Supplier <BlockEntityType <? extends FurnaceWorkbenchEntity >> supplier ) {
42- super (properties , supplier , IS_WIDE , IS_TALL );
43- }
43+ // / **
44+ // * Creates a FurnaceWorkbench that uses a custom BlockEntityType supplier and a 2x2 footprint.
45+ // *
46+ // * @param properties block properties for this workbench
47+ // * @param supplier supplies the BlockEntityType to use for the workbench's master block entity
48+ // */
49+ // public FurnaceWorkbench(Properties properties, Supplier<BlockEntityType<? extends FurnaceWorkbenchEntity>> supplier) {
50+ // super(properties, supplier, IS_WIDE, IS_TALL, 1 );
51+ // }
4452
4553 /**
4654 * Ensures the block is rendered using its model so the 2x2 workbench model is visible.
@@ -72,26 +80,13 @@ public RenderShape getRenderShape(BlockState state) {
7280 public <T extends BlockEntity > BlockEntityTicker <T > getTicker (Level level , BlockState state , BlockEntityType <T > type ) {
7381 // Only the Master block (Lower-Left) should tick to process smelting
7482 // This helper ensures the logic only runs on the Server side for our specific BE
75- return createTickerHelper (type , ModBlockEntities . FURNACE_WORKBENCH_BE , (lvl , pos , st , be ) -> {
83+ return createTickerHelper (type , ModTiers . TIER_MAP . get ( ModTiers . getTierFromInt ( this . tier )) , (lvl , pos , st , be ) -> {
7684 if (be instanceof FurnaceWorkbenchEntity furnace ) {
7785 furnace .tick (lvl , pos , st );
7886 }
7987 });
8088 }
8189
82- /**
83- * Create the block entity for this block; only the master block of the multi-block workbench receives an entity.
84- *
85- * @return the created {@link BlockEntity} for the master block, or `null` if this position does not host an entity
86- */
87- @ Nullable
88- @ Override
89- public BlockEntity newBlockEntity (BlockPos pos , BlockState state ) {
90- // AbstractWorkbench logic ensures only the Master block gets the entity.
91- // We override it here to point specifically to our Furnace entity.
92- return super .newBlockEntity (pos , state );
93- }
94-
9590 /**
9691 * Supply the codec used to serialize and deserialize this FurnaceWorkbench.
9792 *
0 commit comments