2121
2222import java .util .ArrayList ;
2323import java .util .List ;
24+ import java .util .stream .IntStream ;
2425
2526public class AlchemistsWorkbenchEntity extends AbstractWorkbenchEntity {
2627 protected final ContainerData data = new ContainerData () {
@@ -85,18 +86,14 @@ public AlchemistsWorkbenchEntity(BlockPos blockPos, BlockState blockState) {
8586 @ Override
8687 protected void saveAdditional (ValueOutput valueOutput ) {
8788 super .saveAdditional (valueOutput );
88- // store() uses Codecs for type safety
8989 valueOutput .store ("WorkbenchTier" , Codec .INT , this .tier );
9090 valueOutput .store ("ScanRadius" , Codec .DOUBLE , this .scanRadius );
9191
92- // Convert the SimpleContainer to a List of ItemStacks for the Codec
93- // Or use the built-in NBT helper if your framework supports it
94- List <ItemStack > stacks = new ArrayList <>();
95- for (int i = 0 ; i < inventory .getContainerSize (); i ++) {
96- stacks .add (inventory .getItem (i ));
97- }
92+ // Optimized: Stream the inventory slots directly into a list
93+ List <ItemStack > stacks = IntStream .range (0 , inventory .getContainerSize ())
94+ .mapToObj (inventory ::getItem )
95+ .toList ();
9896
99- // CHANGE: Use OPTIONAL_CODEC instead of CODEC
10097 valueOutput .store ("Inventory" , ItemStack .OPTIONAL_CODEC .listOf (), stacks );
10198 }
10299
@@ -117,6 +114,9 @@ protected void loadAdditional(ValueInput valueInput) {
117114
118115 // Read the inventory list back
119116 valueInput .read ("Inventory" , ItemStack .OPTIONAL_CODEC .listOf ()).ifPresent (stacks -> {
117+ // Fix: Clear existing items to prevent stale data if the saved list is smaller
118+ inventory .clearContent ();
119+
120120 for (int i = 0 ; i < stacks .size () && i < inventory .getContainerSize (); i ++) {
121121 inventory .setItem (i , stacks .get (i ));
122122 }
@@ -153,22 +153,12 @@ public RecipeType<WorkbenchRecipe> getWorkbenchRecipeType() {
153153 }
154154
155155 /**
156- * Determines whether the workbench currently has fuel available.
157- *
158- * Checks that the entity is in a loaded level and that the configured fuel slot contains an item.
156+ * Report that the workbench has fuel available.
159157 *
160- * @return `true` if the entity is in a loaded level and the fuel slot contains an item, `false` otherwise .
158+ * @return `true` always .
161159 */
162160 @ Override
163161 protected boolean hasFuel () {
164- if (this .level == null ) return false ;
165-
166- // Check if block is lit
167- // BlockState state = this.level.getBlockState(this.worldPosition);
168- // boolean isLit = state.hasProperty(BlockStateProperties.LIT) && state.getValue(BlockStateProperties.LIT);
169-
170- boolean hasFuelItem = !this .getItem (Constants .FUEL_SLOT ).isEmpty ();
171-
172- return hasFuelItem ;
162+ return true ;
173163 }
174164}
0 commit comments