Skip to content

Commit 12e2904

Browse files
fix: AI comments
1 parent 0127f22 commit 12e2904

3 files changed

Lines changed: 30 additions & 29 deletions

File tree

src/client/java/com/tcm/MineTale/block/workbenches/screen/WorkbenchWorkbenchScreen.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.List;
55
import java.util.Map;
66
import java.util.Optional;
7-
import java.util.stream.Collectors;
87

98
import com.tcm.MineTale.MineTale;
109
import com.tcm.MineTale.block.workbenches.menu.AbstractWorkbenchContainerMenu;
@@ -26,7 +25,7 @@
2625
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
2726
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
2827
import net.minecraft.client.renderer.RenderPipelines;
29-
import net.minecraft.core.HolderSet;
28+
import net.minecraft.core.Holder;
3029
import net.minecraft.resources.Identifier;
3130
import net.minecraft.world.entity.player.Inventory;
3231
import net.minecraft.world.entity.player.Player;
@@ -222,32 +221,31 @@ private boolean canCraft(Player player, RecipeDisplayEntry entry, int craftCount
222221
Optional<List<Ingredient>> reqs = entry.craftingRequirements();
223222
if (reqs.isEmpty()) return false;
224223

225-
// 1. Group ingredients by their underlying Item HolderSet.
226-
// Since Ingredient doesn't override hashCode, we use the values field directly
227-
// or use a List of Holders as the key for stable hashing.
228-
Map<HolderSet<Item>, Integer> aggregatedRequirements = new HashMap<>();
229-
230-
// Helper map to get back to an Ingredient object for the final check
231-
Map<HolderSet<Item>, Ingredient> holderToIngredient = new HashMap<>();
224+
// 1. Group ingredients by their underlying Item Holders.
225+
// Using List<Holder<Item>> as the key ensures structural equality (content-based hashing).
226+
Map<List<Holder<Item>>, Integer> aggregatedRequirements = new HashMap<>();
227+
Map<List<Holder<Item>>, Ingredient> holderToIngredient = new HashMap<>();
232228

233229
for (Ingredient ing : reqs.get()) {
234-
// Accessing the 'values' via a custom accessor or reflection if private,
235-
// but based on your source, we can use the Ingredient object itself
236-
// IF we use a helper that handles the hashing correctly.
237-
238-
// Strategy: Use the stream of holders as a List key (Lists have stable hashcodes)
230+
// Collect holders into a List to get a stable hashCode() and equals()
239231
@SuppressWarnings("deprecation")
240-
HolderSet<Item> key = ing.items().collect(Collectors.collectingAndThen(Collectors.toList(), HolderSet::direct));
241-
232+
List<Holder<Item>> key = ing.items().toList();
233+
234+
// Aggregate the counts (how many of this specific ingredient set are required)
242235
aggregatedRequirements.put(key, aggregatedRequirements.getOrDefault(key, 0) + 1);
236+
237+
// Map the list back to the original ingredient for use in hasIngredientAmount
243238
holderToIngredient.putIfAbsent(key, ing);
244239
}
245240

246-
// 2. Check the player's inventory
241+
// 2. Check the player's inventory against the aggregated totals
247242
Inventory inv = player.getInventory();
248-
for (Map.Entry<HolderSet<Item>, Integer> entryReq : aggregatedRequirements.entrySet()) {
243+
for (Map.Entry<List<Holder<Item>>, Integer> entryReq : aggregatedRequirements.entrySet()) {
244+
List<Holder<Item>> key = entryReq.getKey();
249245
int totalNeeded = entryReq.getValue() * craftCount;
250-
Ingredient originalIng = holderToIngredient.get(entryReq.getKey());
246+
247+
// Retrieve the original Ingredient object associated with this list of holders
248+
Ingredient originalIng = holderToIngredient.get(key);
251249

252250
if (!hasIngredientAmount(inv, originalIng, totalNeeded)) {
253251
return false;

src/client/java/com/tcm/MineTale/datagen/ModModelProvider.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,25 @@ public void generateBlockStateModels(BlockModelGenerators blockStateModelGenerat
8686
* @param block the furnace workbench block to register models for
8787
*/
8888
private void registerFurnaceWorkbench(BlockModelGenerators generator, Block block) {
89-
// 1. Manually define the shared model paths
90-
// Path: assets/minetale/models/block/bench/furnace_top.json
9189
Identifier topModel = Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "block/bench/furnace_top");
9290
Identifier bottomModel = Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "block/bench/furnace_bottom");
9391
Identifier inventoryModel = Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "block/bench/furnace_inventory");
9492

95-
// 4. Dispatch to Blockstate
9693
generator.blockStateOutput.accept(MultiVariantGenerator.dispatch(block)
97-
.with(PropertyDispatch.initial(BlockStateProperties.DOUBLE_BLOCK_HALF)
98-
.select(DoubleBlockHalf.LOWER, BlockModelGenerators.plainVariant(bottomModel))
99-
.select(DoubleBlockHalf.UPPER, BlockModelGenerators.plainVariant(topModel))
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+
})
100104
)
101105
.with(WORKBENCH_ROTATION)
102106
);
103107

104-
// 5. Register the Item Model
105108
generator.registerSimpleItemModel(block, inventoryModel);
106109
}
107110

src/main/java/com/tcm/MineTale/block/workbenches/FurnaceWorkbench.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ public RenderShape getRenderShape(BlockState state) {
131131
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
132132
Direction dir = state.getValue(FACING);
133133
boolean isUpper = state.getValue(HALF) == DoubleBlockHalf.UPPER;
134-
boolean isRightSide = state.getValue(TYPE) == ChestType.LEFT || state.getValue(TYPE) == ChestType.SINGLE;
134+
boolean isLeftSide = state.getValue(TYPE) == ChestType.LEFT || state.getValue(TYPE) == ChestType.SINGLE;
135135

136136
VoxelShape baseShape = isUpper
137-
? (isRightSide ? RAW_UL : RAW_UR)
138-
: (isRightSide ? RAW_LL : RAW_LR);
137+
? (isLeftSide ? RAW_UL : RAW_UR)
138+
: (isLeftSide ? RAW_LL : RAW_LR);
139139

140140
// Call the method now living in AbstractWorkbench
141141
return rotateShape(dir, baseShape);

0 commit comments

Comments
 (0)