Skip to content

Commit ce734fd

Browse files
fix: Update relevant AI comments
1 parent 5105790 commit ce734fd

9 files changed

Lines changed: 9 additions & 145 deletions

File tree

src/client/java/com/tcm/MineTale/MineTaleClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void onInitializeClient() {
4141

4242
@Override
4343
public void run() {
44-
if (context.client().player.containerMenu instanceof AbstractWorkbenchContainerMenu menu) {
44+
if (context.client().player != null && context.client().player.containerMenu instanceof AbstractWorkbenchContainerMenu menu) {
4545
applyItemsToMenu(menu, items, context.client().screen);
4646
} else if (retries < 10) { // Try for up to 10 frames (~0.5 seconds)
4747
retries++;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void generateBlockStateModels(BlockModelGenerators blockStateModelGenerat
7373
blockStateModelGenerator.woodProvider(ModBlocks.WILD_WISTERIA_LOG).logWithHorizontal(ModBlocks.WILD_WISTERIA_LOG).wood(ModBlocks.WILD_WISTERIA_WOOD);
7474

7575
registerLargeWorkbench(blockStateModelGenerator, ModBlocks.FURNACE_WORKBENCH_BLOCK_T1);
76+
registerLargeWorkbench(blockStateModelGenerator, ModBlocks.FURNACE_WORKBENCH_BLOCK_T2);
7677
}
7778

7879
private void registerLargeWorkbench(BlockModelGenerators generator, Block block) {

src/main/java/com/tcm/MineTale/MineTale.java

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void onInitialize() {
117117
WorkbenchRecipe recipe = recipeOpt.get().value();
118118

119119
// 2. Determine craft limit (Handle "All" logic)
120-
int limit = (amount == -1) ? 64 : Math.min(Math.max(amount, 0), 64);;
120+
int limit = (amount == -1) ? 64 : Math.min(Math.max(amount, 0), 64);
121121

122122
for (int i = 0; i < limit; i++) {
123123
if (hasIngredients(player, recipe)) {
@@ -137,34 +137,6 @@ public void onInitialize() {
137137
LOGGER.info("Hello Fabric world!");
138138
}
139139

140-
/**
141-
* Checks whether the player's inventory contains the necessary ingredients to craft the given recipe without modifying the real inventory.
142-
*
143-
* @param player the server player whose inventory will be simulated
144-
* @param recipe the workbench recipe to validate against the player's inventory
145-
* @return `true` if all required ingredients can be satisfied from the player's current inventory, `false` otherwise
146-
*/
147-
// private boolean hasIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
148-
// // We simulate the craft using a copy of the inventory
149-
// List<ItemStack> tempInv = new java.util.ArrayList<>();
150-
// for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
151-
// tempInv.add(player.getInventory().getItem(i).copy());
152-
// }
153-
154-
// for (Ingredient ingredient : recipe.ingredients()) {
155-
// boolean found = false;
156-
// for (ItemStack stack : tempInv) {
157-
// if (!stack.isEmpty() && ingredient.test(stack)) {
158-
// stack.shrink(1);
159-
// found = true;
160-
// break;
161-
// }
162-
// }
163-
// if (!found) return false;
164-
// }
165-
// return true;
166-
// }
167-
168140
private boolean hasIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
169141
if (!(player.containerMenu instanceof AbstractWorkbenchContainerMenu menu)) return false;
170142
AbstractWorkbenchEntity be = menu.getBlockEntity();
@@ -206,24 +178,6 @@ private boolean hasIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
206178
return true;
207179
}
208180

209-
/**
210-
* Consumes one matching item from the player's inventory for each ingredient in the given workbench recipe.
211-
*
212-
* @param player the player whose inventory will be modified
213-
* @param recipe the workbench recipe whose ingredients should be consumed
214-
*/
215-
// private void consumeIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
216-
// for (Ingredient ingredient : recipe.ingredients()) {
217-
// for (int i = 0; i < player.getInventory().getContainerSize(); i++) {
218-
// ItemStack stack = player.getInventory().getItem(i);
219-
// if (!stack.isEmpty() && ingredient.test(stack)) {
220-
// stack.shrink(1);
221-
// break;
222-
// }
223-
// }
224-
// }
225-
// }
226-
227181
private void consumeIngredients(ServerPlayer player, WorkbenchRecipe recipe) {
228182
if (!(player.containerMenu instanceof AbstractWorkbenchContainerMenu menu)) return;
229183
AbstractWorkbenchEntity be = menu.getBlockEntity();

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public WorkbenchWorkbench(Properties properties) {
4646
* @param supplier supplier that provides the BlockEntityType for the WorkbenchWorkbenchEntity
4747
*/
4848
public WorkbenchWorkbench(Properties properties, Supplier<BlockEntityType<? extends WorkbenchWorkbenchEntity>> supplier) {
49-
// isWide = false, isTall = false (1x1 footprint)
5049
super(properties, supplier, IS_WIDE, IS_TALL, 1);
5150
}
5251

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -470,50 +470,6 @@ public boolean isCanPullFromNearby() {
470470
return canPullFromNearby;
471471
}
472472

473-
// public void fillMissingIngredientsFromNearby(WorkbenchRecipe recipe, StackedItemContents playerContents) {
474-
// if (this.level == null || this.level.isClientSide()) return;
475-
476-
// List<Ingredient> ingredients = recipe.ingredients();
477-
// List<Container> nearby = this.getNearbyInventories();
478-
479-
// // We target our input slots
480-
// int[] targetSlots = { Constants.INPUT_START, this.inputEnd };
481-
482-
// for (int i = 0; i < ingredients.size(); i++) {
483-
// Ingredient ingredient = ingredients.get(i);
484-
// if (ingredient.isEmpty()) continue;
485-
486-
// // CHECK PRIORITY: Does the player (or workbench) already have this?
487-
// // stackedContents.canCraft returns how many times the recipe can be made.
488-
// // We check if the ingredient is 'accounted for'.
489-
// if (playerContents.has(ingredient.getStackingIds().get(0))) {
490-
// // Player has it! Standard Minecraft logic will handle moving it.
491-
// continue;
492-
// }
493-
494-
// // PLAYER DOES NOT HAVE IT: Search nearby chests
495-
// int slotIndex = (i < targetSlots.length) ? targetSlots[i] : -1;
496-
// if (slotIndex == -1) continue;
497-
498-
// for (Container external : nearby) {
499-
// if (external == this.inventory) continue;
500-
501-
// for (int j = 0; j < external.getContainerSize(); j++) {
502-
// ItemStack remoteStack = external.getItem(j);
503-
// if (!remoteStack.isEmpty() && ingredient.test(remoteStack)) {
504-
// // Found it! Pull 1 into the workbench slot
505-
// ItemStack taken = external.removeItem(j, 1);
506-
// this.inventory.setItem(slotIndex, taken);
507-
508-
// external.setChanged();
509-
// this.setChanged();
510-
// return; // Move to next ingredient
511-
// }
512-
// }
513-
// }
514-
// }
515-
// }
516-
517473
public void fillMissingIngredientsFromNearby(WorkbenchRecipe recipe, StackedItemContents playerContents, int start, int end) {
518474
if (this.level == null || this.level.isClientSide() || start < 0) return;
519475

@@ -524,9 +480,6 @@ public void fillMissingIngredientsFromNearby(WorkbenchRecipe recipe, StackedItem
524480
Ingredient ingredient = ingredients.get(i);
525481
if (ingredient.isEmpty()) continue;
526482

527-
// --- UPDATED CHECK FOR 1.21.1 ---
528-
// We check if the playerContents has ANY item that matches the ingredient.
529-
// StackedItemContents is essentially a map of Item ID -> Count.
530483
if (hasIngredient(playerContents, ingredient)) {
531484
continue;
532485
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected void loadAdditional(ValueInput valueInput) {
142142
this.syncNearbyToPlayer(serverPlayer);
143143
}
144144

145-
// 2. Return the menu as usual
145+
// // 2. Return the menu as usual
146146
return new WorkbenchWorkbenchMenu(syncId, playerInventory, this.data, this);
147147
}
148148

src/main/java/com/tcm/MineTale/block/workbenches/menu/AbstractWorkbenchContainerMenu.java

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,6 @@ public AbstractWorkbenchContainerMenu(@Nullable MenuType<?> menuType, int syncId
105105
// --- PLAYER INVENTORY ---
106106
addPlayerInventory(playerInventory);
107107
addPlayerHotbar(playerInventory);
108-
109-
if (playerInventory.player instanceof ServerPlayer serverPlayer) {
110-
AbstractWorkbenchEntity be = this.getBlockEntity();
111-
if (be != null && be.isCanPullFromNearby()) { // Only sync if the feature is enabled
112-
be.syncNearbyToPlayer(serverPlayer);
113-
}
114-
}
115108
}
116109

117110
/**
@@ -246,6 +239,8 @@ public int getBurnProgress() {
246239

247240
@Override
248241
public ItemStack quickMoveStack(Player player, int index) {
242+
if (this.outputEnd <= 0) return ItemStack.EMPTY;
243+
249244
ItemStack itemStack = ItemStack.EMPTY;
250245
Slot slot = this.slots.get(index);
251246

@@ -300,42 +295,6 @@ public ItemStack quickMoveStack(Player player, int index) {
300295

301296
public abstract @Nullable AbstractWorkbenchEntity getBlockEntity();
302297

303-
// @Override
304-
// public RecipeBookMenu.PostPlaceAction handlePlacement(boolean placeAll, boolean isSpecial, RecipeHolder<?> recipe, ServerLevel serverLevel, Inventory inventory) {
305-
// if (!(recipe.value() instanceof WorkbenchRecipe workbenchRecipe)) return PostPlaceAction.NOTHING;
306-
307-
// AbstractWorkbenchEntity be = this.getBlockEntity();
308-
// boolean isSlotless = this.outputEnd < 0;
309-
310-
// // 1. Handle slot-based pulling
311-
// if (!isSlotless && be != null && be.isCanPullFromNearby()) {
312-
// StackedItemContents contents = new StackedItemContents();
313-
// inventory.fillStackedContents(contents);
314-
315-
// // Manual fill because Container doesn't have the method
316-
// for (int i = 0; i < this.container.getContainerSize(); i++) {
317-
// contents.accountStack(this.container.getItem(i));
318-
// }
319-
320-
// be.fillMissingIngredientsFromNearby(workbenchRecipe, contents, Constants.INPUT_START, this.inputEnd);
321-
// }
322-
323-
// // 2. Handle the Crafting Action
324-
// if (isSlotless && be != null) {
325-
// if (this.canCraftSlotless(workbenchRecipe, inventory, be)) {
326-
// this.consumeAndGiveToPlayer(workbenchRecipe, inventory, be);
327-
// // We return NOTHING because we've already manually moved the items
328-
// return PostPlaceAction.NOTHING;
329-
// }
330-
// return PostPlaceAction.NOTHING;
331-
// } else {
332-
// // This replaces the undefined 'handleStandardPlacement'
333-
// // using the logic we built previously with ServerPlaceRecipe
334-
// return this.performStandardPlacement(placeAll, recipe, serverLevel, inventory);
335-
// }
336-
// }
337-
338-
339298
@Override
340299
public RecipeBookMenu.PostPlaceAction handlePlacement(boolean placeAll, boolean isSpecial, RecipeHolder<?> recipe, ServerLevel serverLevel, Inventory inventory) {
341300
if (!(recipe.value() instanceof WorkbenchRecipe workbenchRecipe)) {

src/main/java/com/tcm/MineTale/recipe/WorkbenchRecipeDisplay.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public record WorkbenchRecipeDisplay(
2121
SlotDisplay craftingStation,
2222
RecipeType<?> recipeType
2323
) implements RecipeDisplay {
24-
2524
public static final MapCodec<WorkbenchRecipeDisplay> CODEC = RecordCodecBuilder.mapCodec(inst -> inst.group(
2625
SlotDisplay.CODEC.listOf().fieldOf("ingredients").forGetter(WorkbenchRecipeDisplay::ingredients),
2726
SlotDisplay.CODEC.fieldOf("result").forGetter(WorkbenchRecipeDisplay::result),
@@ -36,7 +35,7 @@ public WorkbenchRecipeDisplay(WorkbenchRecipe recipe) {
3635
new SlotDisplay.ItemStackSlotDisplay(recipe.results().isEmpty() ? ItemStack.EMPTY : recipe.results().get(0)),
3736
// Dynamic icon: If it's a campfire recipe, show the campfire item in the book
3837
new SlotDisplay.ItemStackSlotDisplay(new ItemStack(
39-
recipe.getType() == ModRecipes.CAMPFIRE_TYPE ? ModBlocks.CAMPFIRE_WORKBENCH_BLOCK : ModBlocks.FURNACE_WORKBENCH_BLOCK_T1
38+
ModBlocks.WORKBENCH_WORKBENCH_BLOCK
4039
)),
4140
recipe.getType()
4241
);
@@ -64,7 +63,6 @@ public RecipeType<?> getRecipeType() {
6463

6564
@Override
6665
public SlotDisplay craftingStation() {
67-
// Replace 'ModBlocks.YOUR_WORKBENCH' with your actual block item
68-
return new SlotDisplay.ItemStackSlotDisplay(new ItemStack(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1));
66+
return new SlotDisplay.ItemStackSlotDisplay(new ItemStack(ModBlocks.WORKBENCH_WORKBENCH_BLOCK));
6967
}
7068
}

src/main/java/com/tcm/MineTale/registry/ModRecipeDisplay.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class ModRecipeDisplay {
2828
new RecipeDisplay.Type<>(WorkbenchRecipeDisplay.CODEC, STREAM_CODEC);
2929

3030
// 1. Declare the fields but don't assign them yet
31-
public static final RecipeBookCategory CAMPFIRE_SEARCH = registerCategory("campfire_recipe_book_category");;
31+
public static final RecipeBookCategory CAMPFIRE_SEARCH = registerCategory("campfire_recipe_book_category");
3232
public static final RecipeBookCategory WORKBENCH_SEARCH = registerCategory("workbench_recipe_book_category");
3333
public static final RecipeBookCategory FURNACE_T1_SEARCH = registerCategory("furnace_t1_recipe_book_category");
3434

0 commit comments

Comments
 (0)