Skip to content

Commit b848180

Browse files
feat: loads of changes
1 parent 13df396 commit b848180

21 files changed

Lines changed: 495 additions & 353 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class MineTaleClient implements ClientModInitializer {
1717
@Override
1818
public void onInitializeClient() {
1919
MenuScreens.register(ModMenuTypes.FURNACE_WORKBENCH_MENU, FurnaceWorkbenchScreen::new);
20-
MenuScreens.register(ModMenuTypes.CAMPFIRE_WORKBENCH_MENU, CampfireWorkbenchScreen::new);
20+
MenuScreens.register(ModMenuTypes.CAMPFIRE_WORKBENCH_MENU, CampfireWorkbenchScreen::new);
2121
}
2222
}

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

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import com.tcm.MineTale.MineTale;
44
import com.tcm.MineTale.block.workbenches.menu.FurnaceWorkbenchMenu;
5+
import com.tcm.MineTale.recipe.FurnaceRecipeBookComponent;
56

67
import net.minecraft.client.gui.GuiGraphics;
78
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
9+
import net.minecraft.client.input.KeyEvent;
810
import net.minecraft.client.renderer.RenderPipelines;
911
import net.minecraft.resources.Identifier;
1012
import net.minecraft.world.entity.player.Inventory;
@@ -14,6 +16,8 @@ public class FurnaceWorkbenchScreen extends AbstractContainerScreen<FurnaceWorkb
1416
private static final Identifier TEXTURE =
1517
Identifier.fromNamespaceAndPath(MineTale.MOD_ID, "textures/gui/container/furnace_workbench.png");
1618

19+
private FurnaceRecipeBookComponent recipeBookComponent;
20+
1721
/**
1822
* Creates a new furnace workbench screen for the given menu, player inventory, and title.
1923
*
@@ -31,7 +35,38 @@ public FurnaceWorkbenchScreen(FurnaceWorkbenchMenu menu, Inventory inventory, Co
3135
@Override
3236
protected void init() {
3337
super.init();
34-
this.titleLabelX = (this.imageWidth - this.font.width(this.title)) / 2;
38+
39+
// 2. Initialize it here where 'this.menu' is available
40+
if (this.recipeBookComponent == null) {
41+
this.recipeBookComponent = new FurnaceRecipeBookComponent(this.menu);
42+
}
43+
44+
// Standard init and visibility logic
45+
this.recipeBookComponent.init(this.width, this.height, this.minecraft, false);
46+
if (!this.recipeBookComponent.isVisible()) {
47+
this.recipeBookComponent.toggleVisibility();
48+
}
49+
this.leftPos = this.recipeBookComponent.updateScreenPosition(this.width, this.imageWidth);
50+
}
51+
52+
@Override
53+
public boolean keyPressed(KeyEvent keyEvent) {
54+
// 1. Let the search bar in the recipe book use the key first
55+
// If your RecipeBookComponent doesn't take KeyEvent, you'll need to map
56+
// the keyEvent.getKeyCode() to the standard int keyCode version.
57+
if (this.recipeBookComponent.keyPressed(keyEvent)) {
58+
return true;
59+
}
60+
61+
// 2. Identify the Recipe Book toggle key (Standard 'B')
62+
// We check the code to see if it matches the vanilla keybind
63+
// int keyCode = keyEvent.getKeyCode();
64+
// this.minecraft.options.ke
65+
// if (this.minecraft.options.keyRecipeBook.matches(keyCode, 0)) {
66+
// return true; // Return true to "consume" the press and do nothing
67+
// }
68+
69+
return super.keyPressed(keyEvent);
3570
}
3671

3772
/**
@@ -56,10 +91,39 @@ protected void renderBg(GuiGraphics guiGraphics, float f, int i, int j) {
5691
* @param mouseY the current mouse Y coordinate
5792
* @param delta the frame time delta (partial tick) used for animated rendering
5893
*/
94+
// @Override
95+
// public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
96+
// // Render the dark background tint
97+
// renderBackground(graphics, mouseX, mouseY, delta);
98+
99+
// // Always render the book and the main GUI together
100+
// this.recipeBookComponent.render(graphics, mouseX, mouseY, delta);
101+
// super.render(graphics, mouseX, mouseY, delta);
102+
// this.recipeBookComponent.renderGhostRecipe(graphics, true);
103+
104+
// renderTooltip(graphics, mouseX, mouseY);
105+
// // this.recipeBookComponent.renderTooltip(graphics, this.leftPos, this.topPos, mouseX, mouseY);
106+
// }
107+
59108
@Override
60109
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
110+
// 1. Always render the dark background tint first
61111
renderBackground(graphics, mouseX, mouseY, delta);
112+
113+
// 2. Add a null check before calling ANY methods on the component
114+
if (this.recipeBookComponent != null) {
115+
this.recipeBookComponent.render(graphics, mouseX, mouseY, delta);
116+
}
117+
118+
// 3. Call super (this draws your slots and items)
62119
super.render(graphics, mouseX, mouseY, delta);
120+
121+
// 4. Ghost recipes and Tooltips also need the null check
122+
if (this.recipeBookComponent != null) {
123+
this.recipeBookComponent.renderGhostRecipe(graphics, true);
124+
this.recipeBookComponent.renderTooltip(graphics, this.leftPos, this.topPos, this.hoveredSlot);
125+
}
126+
63127
renderTooltip(graphics, mouseX, mouseY);
64128
}
65129
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package com.tcm.MineTale.recipe;
2+
3+
import net.minecraft.client.gui.components.WidgetSprites;
4+
import net.minecraft.client.gui.screens.recipebook.GhostSlots;
5+
import net.minecraft.client.gui.screens.recipebook.GhostSlotsProxy;
6+
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
7+
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
8+
import net.minecraft.network.chat.Component;
9+
import net.minecraft.resources.Identifier;
10+
import net.minecraft.util.context.ContextMap;
11+
import net.minecraft.world.entity.player.StackedItemContents;
12+
import net.minecraft.world.inventory.RecipeBookMenu;
13+
import net.minecraft.world.inventory.Slot;
14+
import net.minecraft.world.item.ItemStack;
15+
import net.minecraft.world.item.Items;
16+
import net.minecraft.world.item.crafting.RecipeBookCategories;
17+
import net.minecraft.world.item.crafting.display.FurnaceRecipeDisplay;
18+
import net.minecraft.world.item.crafting.display.RecipeDisplay;
19+
import net.minecraft.world.item.crafting.display.SlotDisplay;
20+
21+
import java.util.List;
22+
import java.util.Optional;
23+
24+
import org.jetbrains.annotations.Nullable;
25+
26+
public class FurnaceRecipeBookComponent extends RecipeBookComponent<RecipeBookMenu> {
27+
28+
public FurnaceRecipeBookComponent(RecipeBookMenu menu) {
29+
// Pass the menu and the list of tabs required by the super constructor
30+
super(menu, List.of(
31+
new RecipeBookComponent.TabInfo(new ItemStack(Items.PORKCHOP), Optional.empty(), RecipeBookCategories.FURNACE_FOOD)
32+
));
33+
}
34+
35+
// Standard Furnace filter button textures (the little flame/ore icon)
36+
private static final WidgetSprites FILTER_BUTTON_SPRITES = new WidgetSprites(
37+
Identifier.withDefaultNamespace("recipe_book/furnace_filter_enabled"),
38+
Identifier.withDefaultNamespace("recipe_book/furnace_filter_disabled"),
39+
Identifier.withDefaultNamespace("recipe_book/furnace_filter_enabled_highlighted"),
40+
Identifier.withDefaultNamespace("recipe_book/furnace_filter_disabled_highlighted")
41+
);
42+
43+
@Override
44+
public void slotClicked(@Nullable Slot slot) {
45+
// This is often where the 'can I craft this' state is refreshed
46+
super.slotClicked(slot);
47+
}
48+
49+
@Override
50+
protected WidgetSprites getFilterButtonTextures() {
51+
return FILTER_BUTTON_SPRITES;
52+
}
53+
54+
@Override
55+
protected Component getRecipeFilterName() {
56+
// This is the tooltip text when hovering over the "show craftable" toggle
57+
return Component.translatable("gui.recipebook.toggleRecipes.smeltable");
58+
}
59+
60+
@Override
61+
protected boolean isCraftingSlot(Slot slot) {
62+
// Temporarily allow the book to 'see' all furnace slots (0-3)
63+
// to see if the pork recipe finally enables.
64+
return slot.index == 0 || slot.index == 1;
65+
}
66+
67+
@Override
68+
protected void selectMatchingRecipes(RecipeCollection recipeCollection, StackedItemContents stackedItemContents) {
69+
// selectRecipes takes the items you have (stackedContents)
70+
// and a Predicate to decide if the recipe "fits" this machine.
71+
recipeCollection.selectRecipes(stackedItemContents, recipeDisplay -> {
72+
// Option A: Check if it's your custom display type (if you made one)
73+
// Option B: For now, let's accept everything to see if it lights up
74+
return true;
75+
});
76+
}
77+
78+
// @Override
79+
// protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipeDisplay, ContextMap contextMap) {
80+
// GhostSlotsProxy.setResultProxy(ghostSlots, this.menu.getSlot(3), contextMap, recipeDisplay.result());
81+
82+
// if (recipeDisplay instanceof FurnaceRecipeDisplay cooking) {
83+
// GhostSlotsProxy.setInputProxy(ghostSlots, this.menu.getSlot(1), contextMap, cooking.ingredient());
84+
// }
85+
// }
86+
87+
@Override
88+
protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipeDisplay, ContextMap contextMap) {
89+
// 1. Set the Result (Index 2 in your Menu)
90+
// recipeDisplay.result() provides the SlotDisplay for the output
91+
GhostSlotsProxy.setResultProxy(ghostSlots, this.menu.getSlot(2), contextMap, recipeDisplay.result());
92+
93+
94+
// 2. Map Ingredients to your Inputs (Indices 0 and 1)
95+
SlotDisplay ingredient = recipeDisplay.result();
96+
97+
if (ingredient != null) {
98+
GhostSlotsProxy.setInputProxy(ghostSlots, this.menu.getSlot(0), contextMap, ingredient);
99+
}
100+
}
101+
102+
// @Override
103+
// protected void fillGhostRecipe(GhostSlots ghostSlots, RecipeDisplay recipeDisplay, ContextMap contextMap) {
104+
// // 1. Clear any existing ghost items first
105+
// ghostSlots.clear();
106+
107+
// // 2. Set the Result (Output) Slot Ghost
108+
// // Assuming index 2 is your output slot in the Menu
109+
// ghostSlots.setResult(this.menu.slots.get(2), contextMap, recipeDisplay.result());
110+
111+
// // 3. Set the Input (Ingredient) Slot Ghost
112+
// // We check if the recipe has ingredients to avoid IndexOutOfBounds
113+
// if (!recipeDisplay.ingredients().isEmpty()) {
114+
// // We target the 'Active' processing slot (index 0)
115+
// // This is the physical slot at the front of your queue
116+
// SlotDisplay inputDisplay = recipeDisplay.ingredients().get(0);
117+
// ghostSlots.setInput(this.menu.slots.get(0), contextMap, inputDisplay);
118+
// }
119+
// }
120+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package net.minecraft.client.gui.screens.recipebook;
2+
3+
import net.minecraft.world.inventory.Slot;
4+
import net.minecraft.util.context.ContextMap;
5+
import net.minecraft.world.item.crafting.display.SlotDisplay;
6+
7+
public class GhostSlotsProxy {
8+
public static void setInputProxy(GhostSlots ghostSlots, Slot slot, ContextMap contextMap, SlotDisplay display) {
9+
// Because this class is in the same package, it can see protected methods!
10+
ghostSlots.setInput(slot, contextMap, display);
11+
}
12+
13+
public static void setResultProxy(GhostSlots ghostSlots, Slot slot, ContextMap contextMap, SlotDisplay display) {
14+
ghostSlots.setResult(slot, contextMap, display);
15+
}
16+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// 1.21.11 -999999999-01-01T00:00:00 MineTale/minetaleModRecipeProvider
2+
dcc5dac31dc51d16b53e14666f87d47297089c0d data/minetale/advancement/recipes/campfire_pork_cooking.json
3+
751394b2de2b8d65df4ffd587bf371f4b0bf81fd data/minetale/recipe/campfire_pork_cooking.json

src/main/generated/.cache/a0bb9d1f192aa1460a2925285bfedebf2e41cc8c

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/generated/.cache/ec0550601f03a0db10fc60ced710401e24a6dc4f

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/main/generated/assets/minetale/lang/en_us.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/generated/data/minetale/recipe/campfire_pork_cooking.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"type": "minetale:campfire_alloying",
3-
"cookTime": 600,
3+
"category": "food",
4+
"cookTime": 10,
45
"ingredients": [
56
"minecraft:porkchop"
67
],

0 commit comments

Comments
 (0)