Skip to content

Commit dfdc081

Browse files
fix: AI comments
1 parent 3b76025 commit dfdc081

2 files changed

Lines changed: 13 additions & 21 deletions

File tree

src/main/java/com/tcm/MineTale/block/workbenches/entity/AbstractWorkbenchEntity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ public void setItem(int slot, ItemStack stack) {
278278
}
279279

280280
/**
281-
* Indicates whether this workbench currently has fuel available to perform crafting.
282-
*
283-
* @return `true` if the workbench has fuel available, `false` otherwise.
284-
*/
281+
* Indicates whether this workbench currently has fuel available to perform crafting.
282+
*
283+
* @return `true` if the workbench has fuel available, `false` otherwise.
284+
*/
285285
protected abstract boolean hasFuel();
286286

287287
/**

src/main/java/com/tcm/MineTale/block/workbenches/entity/AlchemistsWorkbenchEntity.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.ArrayList;
2323
import java.util.List;
24+
import java.util.stream.IntStream;
2425

2526
public 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
}
@@ -161,14 +161,6 @@ public RecipeType<WorkbenchRecipe> getWorkbenchRecipeType() {
161161
*/
162162
@Override
163163
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;
164+
return true;
173165
}
174166
}

0 commit comments

Comments
 (0)