Skip to content

Commit 1d06564

Browse files
Merge pull request #53 from CodeMonkeysMods/feat/plant-fibre-recipes
Feature - plant fibre recipes
2 parents c218eac + dfa4e57 commit 1d06564

19 files changed

Lines changed: 1376 additions & 87 deletions

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

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import com.tcm.MineTale.block.workbenches.menu.AbstractWorkbenchContainerMenu;
1010
import com.tcm.MineTale.block.workbenches.menu.ArmorersWorkbenchMenu;
1111
import com.tcm.MineTale.mixin.client.ClientRecipeBookAccessor;
12-
import com.tcm.MineTale.mixin.client.RecipeBookComponentAccessor;
1312
import com.tcm.MineTale.network.CraftRequestPayload;
1413
import com.tcm.MineTale.recipe.MineTaleRecipeBookComponent;
1514
import com.tcm.MineTale.registry.ModBlocks;
@@ -23,7 +22,6 @@
2322
import net.minecraft.client.gui.navigation.ScreenPosition;
2423
import net.minecraft.client.gui.screens.inventory.AbstractRecipeBookScreen;
2524
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
26-
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
2725
import net.minecraft.client.renderer.RenderPipelines;
2826
import net.minecraft.core.Holder;
2927
import net.minecraft.resources.Identifier;
@@ -43,6 +41,8 @@ public class ArmorersWorkbenchScreen extends AbstractRecipeBookScreen<ArmorersWo
4341

4442
private final MineTaleRecipeBookComponent mineTaleRecipeBook;
4543

44+
private RecipeDisplayId lastKnownSelectedId = null;
45+
4646
private Button craftOneBtn;
4747
private Button craftTenBtn;
4848
private Button craftAllBtn;
@@ -81,10 +81,10 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(ArmorersWor
8181
ItemStack tabIcon = new ItemStack(ModBlocks.ARMORERS_WORKBENCH_BLOCK.asItem());
8282

8383
List<RecipeBookComponent.TabInfo> tabs = List.of(
84-
new RecipeBookComponent.TabInfo(tabIcon.getItem(), ModRecipeDisplay.WORKBENCH_SEARCH)
84+
new RecipeBookComponent.TabInfo(tabIcon.getItem(), ModRecipeDisplay.ARMORERS_SEARCH)
8585
);
8686

87-
return new MineTaleRecipeBookComponent(menu, tabs, ModRecipes.WORKBENCH_TYPE);
87+
return new MineTaleRecipeBookComponent(menu, tabs, ModRecipes.ARMORERS_TYPE);
8888
}
8989

9090
/**
@@ -128,34 +128,52 @@ protected void init() {
128128
* @param amount the quantity to craft; use -1 to request crafting of the full available stack ("All")
129129
*/
130130

131-
private void handleCraftRequest(int amount) {
132-
// 1. Cast the book component to the Accessor to get the selected data
133-
RecipeBookComponentAccessor accessor = (RecipeBookComponentAccessor) this.mineTaleRecipeBook;
131+
// private void handleCraftRequest(int amount) {
132+
// // 1. Cast the book component to the Accessor to get the selected data
133+
// RecipeBookComponentAccessor accessor = (RecipeBookComponentAccessor) this.mineTaleRecipeBook;
134134

135-
RecipeCollection collection = accessor.getLastRecipeCollection();
136-
RecipeDisplayId displayId = accessor.getLastRecipe();
137-
138-
if (collection != null && displayId != null) {
139-
// 2. Find the visual entry
140-
for (RecipeDisplayEntry entry : collection.getSelectedRecipes(RecipeCollection.CraftableStatus.ANY)) {
141-
if (entry.id().equals(displayId)) {
142-
// 3. Resolve result for the packet
143-
List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
135+
// RecipeCollection collection = accessor.getLastRecipeCollection();
136+
// RecipeDisplayId displayId = accessor.getLastRecipe();
137+
138+
// if (collection != null && displayId != null) {
139+
// // 2. Find the visual entry
140+
// for (RecipeDisplayEntry entry : collection.getSelectedRecipes(RecipeCollection.CraftableStatus.ANY)) {
141+
// if (entry.id().equals(displayId)) {
142+
// // 3. Resolve result for the packet
143+
// List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
144144

145-
if (!results.isEmpty()) {
146-
ItemStack resultStack = results.get(0);
145+
// if (!results.isEmpty()) {
146+
// ItemStack resultStack = results.get(0);
147147

148-
// 4. LOG FOR DEBUGGING
149-
System.out.println("Sending craft request for: " + resultStack + " amount: " + amount);
148+
// // 4. LOG FOR DEBUGGING
149+
// System.out.println("Sending craft request for: " + resultStack + " amount: " + amount);
150150

151-
ClientPlayNetworking.send(new CraftRequestPayload(resultStack, amount));
152-
}
153-
break;
151+
// ClientPlayNetworking.send(new CraftRequestPayload(resultStack, amount));
152+
// }
153+
// break;
154+
// }
155+
// }
156+
// } else {
157+
// System.out.println("Request failed: Collection or DisplayID is null!");
158+
// }
159+
// }
160+
161+
private void handleCraftRequest(int amount) {
162+
// Look at our "Memory" instead of the component
163+
if (this.lastKnownSelectedId != null) {
164+
ClientRecipeBook book = this.minecraft.player.getRecipeBook();
165+
RecipeDisplayEntry entry = ((ClientRecipeBookAccessor) book).getKnown().get(this.lastKnownSelectedId);
166+
167+
if (entry != null) {
168+
List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
169+
if (!results.isEmpty()) {
170+
System.out.println("Persistent Selection Success: " + results.get(0));
171+
ClientPlayNetworking.send(new CraftRequestPayload(results.get(0), amount));
172+
return;
154173
}
155174
}
156-
} else {
157-
System.out.println("Request failed: Collection or DisplayID is null!");
158175
}
176+
System.out.println("Request failed: No recipe was ever selected!");
159177
}
160178

161179
/**
@@ -177,18 +195,22 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
177195
renderBackground(graphics, mouseX, mouseY, delta);
178196
super.render(graphics, mouseX, mouseY, delta);
179197

180-
// Get the ID of the recipe clicked in the ghost-book
181-
RecipeDisplayId displayId = this.mineTaleRecipeBook.getSelectedRecipeId();
182-
RecipeDisplayEntry selectedEntry = null;
198+
// 1. Get the current selection from the book
199+
RecipeDisplayId currentId = this.mineTaleRecipeBook.getSelectedRecipeId();
200+
201+
// 2. If it's NOT null, remember it!
202+
if (currentId != null) {
203+
this.lastKnownSelectedId = currentId;
204+
}
183205

184-
if (displayId != null && this.minecraft.level != null) {
206+
// 3. Use the remembered ID to find the entry for button activation
207+
RecipeDisplayEntry selectedEntry = null;
208+
if (this.lastKnownSelectedId != null && this.minecraft.level != null) {
185209
ClientRecipeBook book = this.minecraft.player.getRecipeBook();
186-
// Accessing the known recipes via your Accessor
187-
Map<RecipeDisplayId, RecipeDisplayEntry> knownRecipes = ((ClientRecipeBookAccessor) book).getKnown();
188-
selectedEntry = knownRecipes.get(displayId);
210+
selectedEntry = ((ClientRecipeBookAccessor) book).getKnown().get(this.lastKnownSelectedId);
189211
}
190212

191-
// 2. Button Activation Logic
213+
// Logic for enabling/disabling buttons...
192214
if (selectedEntry != null) {
193215
// We use the entry directly. It contains the 15 ingredients needed!
194216
boolean canCraftOne = canCraft(this.minecraft.player, selectedEntry, 1);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.tcm.MineTale.datagen;
22

3-
import com.jcraft.jorbis.Block;
43
import com.tcm.MineTale.registry.ModBlocks;
54
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
65
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import com.tcm.MineTale.block.workbenches.AbstractWorkbench;
44
import com.tcm.MineTale.registry.ModBlocks;
5-
import com.tcm.MineTale.registry.ModItems;
65
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
76
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
87
import net.minecraft.advancements.criterion.StatePropertiesPredicate;

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

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
import com.tcm.MineTale.MineTale;
66
import com.tcm.MineTale.datagen.builders.WorkbenchRecipeBuilder;
7-
import com.tcm.MineTale.registry.ModBlocks;
7+
import com.tcm.MineTale.datagen.recipes.AlchemistRecipes;
8+
import com.tcm.MineTale.datagen.recipes.ArmorRecipes;
9+
import com.tcm.MineTale.datagen.recipes.BlacksmithRecipes;
10+
import com.tcm.MineTale.datagen.recipes.BuilderRecipes;
11+
import com.tcm.MineTale.datagen.recipes.FarmerRecipes;
12+
import com.tcm.MineTale.datagen.recipes.ForgeRecipes;
13+
import com.tcm.MineTale.datagen.recipes.FurnitureRecipes;
14+
import com.tcm.MineTale.datagen.recipes.GeneralRecipes;
15+
import com.tcm.MineTale.datagen.recipes.WorkbenchRecipes;
816
import com.tcm.MineTale.registry.ModRecipeDisplay;
917
import com.tcm.MineTale.registry.ModRecipes;
1018

@@ -68,27 +76,6 @@ public void buildRecipes() {
6876
.bookCategory(ModRecipeDisplay.CAMPFIRE_SEARCH)
6977
.save(exporter, "campfire_pork_cooking");
7078

71-
// Workbench Recipes
72-
73-
// 1. Workbenches
74-
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
75-
.input(Items.COPPER_INGOT, 2)
76-
.input(ItemTags.LOGS, registryLookup, 10)
77-
.input(ItemTags.STONE_TOOL_MATERIALS, registryLookup, 5)
78-
.output(ModBlocks.ARMORERS_WORKBENCH_BLOCK.asItem())
79-
.unlockedBy("has_workbench", has(ModBlocks.WORKBENCH_WORKBENCH_BLOCK.asItem()))
80-
.bookCategory(ModRecipeDisplay.WORKBENCH_SEARCH)
81-
.save(exporter, "workbench_armorers_workbench");
82-
83-
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
84-
.input(ItemTags.LOGS, registryLookup, 6)
85-
.input(ItemTags.STONE_TOOL_MATERIALS, registryLookup, 6)
86-
.output(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1.asItem())
87-
.unlockedBy("has_workbench", has(ModBlocks.WORKBENCH_WORKBENCH_BLOCK.asItem()))
88-
.bookCategory(ModRecipeDisplay.WORKBENCH_SEARCH)
89-
.save(exporter, "workbench_furnace_workbench_t1");
90-
91-
9279
// 2. Chests
9380
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
9481
.input(ItemTags.LOGS, registryLookup, 10)
@@ -108,6 +95,25 @@ public void buildRecipes() {
10895
.unlockedBy("has_copper_ore", has(Items.COPPER_ORE))
10996
.bookCategory(ModRecipeDisplay.FURNACE_T1_SEARCH)
11097
.save(exporter, "furnace_t1_copper_ingot");
98+
99+
// Alchemist Recipes
100+
AlchemistRecipes.buildRecipes(this, exporter, registryLookup);
101+
// Armor Recipes
102+
ArmorRecipes.buildRecipes(this, exporter, registryLookup);
103+
// Blacksmith Recipes
104+
BlacksmithRecipes.buildRecipes(this, exporter, registryLookup);
105+
// Builder Recipes
106+
BuilderRecipes.buildRecipes(this, exporter, registryLookup);
107+
// Farmer Recipes
108+
FarmerRecipes.buildRecipes(this, exporter, registryLookup);
109+
// Forge Recipes
110+
ForgeRecipes.buildRecipes(this, exporter, registryLookup);
111+
// Furniture Recipes
112+
FurnitureRecipes.buildRecipes(this, exporter, registryLookup);
113+
// General Recipes
114+
GeneralRecipes.buildRecipes(this, exporter, registryLookup);
115+
// Workbench Recipes
116+
WorkbenchRecipes.buildRecipes(this, exporter, registryLookup);
111117
}
112118
};
113119
}

src/client/java/com/tcm/MineTale/datagen/builders/WorkbenchRecipeBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class WorkbenchRecipeBuilder implements RecipeBuilder {
4444
private CraftingBookCategory category = CraftingBookCategory.MISC;
4545
private Identifier bookCategory = BuiltInRegistries.RECIPE_BOOK_CATEGORY
4646
.getKey(ModRecipeDisplay.CAMPFIRE_SEARCH);
47-
private int cookTime = 200;
47+
private float cookTime = 200;
4848
@Nullable private String group;
4949

5050
/**
@@ -185,7 +185,7 @@ public WorkbenchRecipeBuilder output(ItemLike stack) {
185185
* @param seconds the cook time in seconds
186186
* @return the builder instance
187187
*/
188-
public WorkbenchRecipeBuilder time(int seconds) {
188+
public WorkbenchRecipeBuilder time(float seconds) {
189189
this.cookTime = seconds * 20;
190190
return this;
191191
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.tcm.MineTale.datagen.recipes;
2+
3+
import net.minecraft.core.HolderLookup;
4+
import net.minecraft.data.recipes.RecipeOutput;
5+
import net.minecraft.data.recipes.RecipeProvider;
6+
7+
public class AlchemistRecipes {
8+
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
9+
// new WorkbenchRecipeBuilder(ModRecipes.ALCHEMIST_TYPE, ModRecipes.ALCHEMIST_SERIALIZER)
10+
// .input(ModItems.EMPTY_POTION_BOTTLE)
11+
// .input(ModItems.PLANT_FIBER, 5)
12+
// .input(ModItems.ESSENCE_OF_LIFE, 2)
13+
// .input(ModItems.VENOM_SACK, 1)
14+
// .output(ModItems.ANTIDOTE)
15+
// .time(1)
16+
// .unlockedBy("has_alchemist_workbench", provider.has(ModBlocks.ALCHEMIST_WORKBENCH_BLOCK.asItem()))
17+
// .bookCategory(ModRecipeDisplay.ALCHEMIST_SEARCH)
18+
// .save(exporter, "ANTIDOTE");
19+
20+
// new WorkbenchRecipeBuilder(ModRecipes.ALCHEMIST_TYPE, ModRecipes.ALCHEMIST_SERIALIZER)
21+
// .input(ModItems.WILD_BERRY, 6)
22+
// .input(ModItems.BOOM_POWDER, 2)
23+
// .input(ModItems.PLANT_FIBER, 4)
24+
// .output(ModItems.POPBERRY_BOMB, 2)
25+
// .time(0.5)
26+
// .unlockedBy("has_alchemist_workbench", provider.has(ModBlocks.ALCHEMIST_WORKBENCH_BLOCK.asItem()))
27+
// .bookCategory(ModRecipeDisplay.ALCHEMIST_SEARCH)
28+
// .save(exporter, "POPBERRY_BOMB");
29+
}
30+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.tcm.MineTale.datagen.recipes;
2+
3+
import com.tcm.MineTale.datagen.builders.WorkbenchRecipeBuilder;
4+
import com.tcm.MineTale.registry.ModItems;
5+
import com.tcm.MineTale.registry.ModRecipeDisplay;
6+
import com.tcm.MineTale.registry.ModRecipes;
7+
8+
import net.minecraft.core.HolderLookup;
9+
import net.minecraft.data.recipes.RecipeOutput;
10+
import net.minecraft.data.recipes.RecipeProvider;
11+
import net.minecraft.world.item.Items;
12+
13+
public class ArmorRecipes {
14+
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
15+
// Copper Armor
16+
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
17+
.input(Items.COPPER_INGOT, 11)
18+
.input(ModItems.PLANT_FIBER, 4)
19+
.output(Items.COPPER_CHESTPLATE)
20+
.time(3)
21+
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
22+
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
23+
.save(exporter, "copper_cuirass");
24+
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
25+
.input(Items.COPPER_INGOT, 6)
26+
.input(ModItems.PLANT_FIBER, 2)
27+
.output(Items.COPPER_HELMET)
28+
.time(3)
29+
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
30+
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
31+
.save(exporter, "copper_helmet");
32+
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
33+
.input(Items.COPPER_INGOT, 9)
34+
.input(ModItems.PLANT_FIBER, 3)
35+
.output(Items.COPPER_LEGGINGS)
36+
.time(3)
37+
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
38+
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
39+
.save(exporter, "copper_greaves");
40+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
41+
// .input(Items.COPPER_INGOT, 5)
42+
// .input(ModItems.PLANT_FIBER, 1)
43+
// .output(Items.COPPER_LEGGINGS)
44+
// .time(3)
45+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
46+
// .save(exporter, "copper_gauntlets");
47+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
48+
// .input(Items.COPPER_INGOT, 2)
49+
// .input(ModItems.PLANT_FIBER, 3)
50+
// .input(ItemTags.LOGS, lookup)
51+
// .output(ModItems.COPPER_SHIELD)
52+
// .time(3)
53+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
54+
// .save(exporter, "COPPER_SHIELD");
55+
56+
// Wood Armor
57+
// TODO: WoodenArmor Not Implemented
58+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
59+
// .input(ItemTags.LOGS, lookup, 15)
60+
// .input(ModItems.PLANT_FIBER, 3)
61+
// .output(Items.COPPER_CHESTPLATE)
62+
// .time(3)
63+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
64+
// .save(exporter, "copper_cuirass");
65+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
66+
// .input(Items.COPPER_INGOT, 6)
67+
// .input(ModItems.PLANT_FIBER, 2)
68+
// .output(Items.COPPER_HELMET)
69+
// .time(3)
70+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
71+
// .save(exporter, "copper_helmet");
72+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
73+
// .input(Items.COPPER_INGOT, 9)
74+
// .input(ModItems.PLANT_FIBER, 3)
75+
// .output(Items.COPPER_LEGGINGS)
76+
// .time(3)
77+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
78+
// .save(exporter, "copper_greaves");
79+
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
80+
// .input(Items.COPPER_INGOT, 5)
81+
// .input(ModItems.PLANT_FIBER, 1)
82+
// .output(Items.COPPER_LEGGINGS)
83+
// .time(3)
84+
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
85+
// .save(exporter, "copper_gauntlets");
86+
87+
88+
}
89+
}

0 commit comments

Comments
 (0)