Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.tcm.MineTale.block.workbenches.menu.AbstractWorkbenchContainerMenu;
import com.tcm.MineTale.block.workbenches.menu.ArmorersWorkbenchMenu;
import com.tcm.MineTale.mixin.client.ClientRecipeBookAccessor;
import com.tcm.MineTale.mixin.client.RecipeBookComponentAccessor;
import com.tcm.MineTale.network.CraftRequestPayload;
import com.tcm.MineTale.recipe.MineTaleRecipeBookComponent;
import com.tcm.MineTale.registry.ModBlocks;
Expand All @@ -23,7 +22,6 @@
import net.minecraft.client.gui.navigation.ScreenPosition;
import net.minecraft.client.gui.screens.inventory.AbstractRecipeBookScreen;
import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent;
import net.minecraft.client.gui.screens.recipebook.RecipeCollection;
import net.minecraft.client.renderer.RenderPipelines;
import net.minecraft.core.Holder;
import net.minecraft.resources.Identifier;
Expand All @@ -43,6 +41,8 @@ public class ArmorersWorkbenchScreen extends AbstractRecipeBookScreen<ArmorersWo

private final MineTaleRecipeBookComponent mineTaleRecipeBook;

private RecipeDisplayId lastKnownSelectedId = null;

private Button craftOneBtn;
private Button craftTenBtn;
private Button craftAllBtn;
Expand Down Expand Up @@ -81,10 +81,10 @@ private static MineTaleRecipeBookComponent createRecipeBookComponent(ArmorersWor
ItemStack tabIcon = new ItemStack(ModBlocks.ARMORERS_WORKBENCH_BLOCK.asItem());

List<RecipeBookComponent.TabInfo> tabs = List.of(
new RecipeBookComponent.TabInfo(tabIcon.getItem(), ModRecipeDisplay.WORKBENCH_SEARCH)
new RecipeBookComponent.TabInfo(tabIcon.getItem(), ModRecipeDisplay.ARMORERS_SEARCH)
);

return new MineTaleRecipeBookComponent(menu, tabs, ModRecipes.WORKBENCH_TYPE);
return new MineTaleRecipeBookComponent(menu, tabs, ModRecipes.ARMORERS_TYPE);
}

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

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

RecipeCollection collection = accessor.getLastRecipeCollection();
RecipeDisplayId displayId = accessor.getLastRecipe();

if (collection != null && displayId != null) {
// 2. Find the visual entry
for (RecipeDisplayEntry entry : collection.getSelectedRecipes(RecipeCollection.CraftableStatus.ANY)) {
if (entry.id().equals(displayId)) {
// 3. Resolve result for the packet
List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
// RecipeCollection collection = accessor.getLastRecipeCollection();
// RecipeDisplayId displayId = accessor.getLastRecipe();

// if (collection != null && displayId != null) {
// // 2. Find the visual entry
// for (RecipeDisplayEntry entry : collection.getSelectedRecipes(RecipeCollection.CraftableStatus.ANY)) {
// if (entry.id().equals(displayId)) {
// // 3. Resolve result for the packet
// List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));

if (!results.isEmpty()) {
ItemStack resultStack = results.get(0);
// if (!results.isEmpty()) {
// ItemStack resultStack = results.get(0);

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

ClientPlayNetworking.send(new CraftRequestPayload(resultStack, amount));
}
break;
// ClientPlayNetworking.send(new CraftRequestPayload(resultStack, amount));
// }
// break;
// }
// }
// } else {
// System.out.println("Request failed: Collection or DisplayID is null!");
// }
// }

private void handleCraftRequest(int amount) {
// Look at our "Memory" instead of the component
if (this.lastKnownSelectedId != null) {
ClientRecipeBook book = this.minecraft.player.getRecipeBook();
RecipeDisplayEntry entry = ((ClientRecipeBookAccessor) book).getKnown().get(this.lastKnownSelectedId);

if (entry != null) {
List<ItemStack> results = entry.resultItems(SlotDisplayContext.fromLevel(this.minecraft.level));
if (!results.isEmpty()) {
System.out.println("Persistent Selection Success: " + results.get(0));
ClientPlayNetworking.send(new CraftRequestPayload(results.get(0), amount));
return;
}
}
} else {
System.out.println("Request failed: Collection or DisplayID is null!");
}
System.out.println("Request failed: No recipe was ever selected!");
}

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

// Get the ID of the recipe clicked in the ghost-book
RecipeDisplayId displayId = this.mineTaleRecipeBook.getSelectedRecipeId();
RecipeDisplayEntry selectedEntry = null;
// 1. Get the current selection from the book
RecipeDisplayId currentId = this.mineTaleRecipeBook.getSelectedRecipeId();

// 2. If it's NOT null, remember it!
if (currentId != null) {
this.lastKnownSelectedId = currentId;
}

if (displayId != null && this.minecraft.level != null) {
// 3. Use the remembered ID to find the entry for button activation
RecipeDisplayEntry selectedEntry = null;
if (this.lastKnownSelectedId != null && this.minecraft.level != null) {
ClientRecipeBook book = this.minecraft.player.getRecipeBook();
// Accessing the known recipes via your Accessor
Map<RecipeDisplayId, RecipeDisplayEntry> knownRecipes = ((ClientRecipeBookAccessor) book).getKnown();
selectedEntry = knownRecipes.get(displayId);
selectedEntry = ((ClientRecipeBookAccessor) book).getKnown().get(this.lastKnownSelectedId);
}

// 2. Button Activation Logic
// Logic for enabling/disabling buttons...
if (selectedEntry != null) {
// We use the entry directly. It contains the 15 ingredients needed!
boolean canCraftOne = canCraft(this.minecraft.player, selectedEntry, 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tcm.MineTale.datagen;

import com.jcraft.jorbis.Block;
import com.tcm.MineTale.registry.ModBlocks;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.tcm.MineTale.block.workbenches.AbstractWorkbench;
import com.tcm.MineTale.registry.ModBlocks;
import com.tcm.MineTale.registry.ModItems;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import net.fabricmc.fabric.api.datagen.v1.provider.FabricBlockLootTableProvider;
import net.minecraft.advancements.criterion.StatePropertiesPredicate;
Expand Down
50 changes: 28 additions & 22 deletions src/client/java/com/tcm/MineTale/datagen/ModRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@

import com.tcm.MineTale.MineTale;
import com.tcm.MineTale.datagen.builders.WorkbenchRecipeBuilder;
import com.tcm.MineTale.registry.ModBlocks;
import com.tcm.MineTale.datagen.recipes.AlchemistRecipes;
import com.tcm.MineTale.datagen.recipes.ArmorRecipes;
import com.tcm.MineTale.datagen.recipes.BlacksmithRecipes;
import com.tcm.MineTale.datagen.recipes.BuilderRecipes;
import com.tcm.MineTale.datagen.recipes.FarmerRecipes;
import com.tcm.MineTale.datagen.recipes.ForgeRecipes;
import com.tcm.MineTale.datagen.recipes.FurnitureRecipes;
import com.tcm.MineTale.datagen.recipes.GeneralRecipes;
import com.tcm.MineTale.datagen.recipes.WorkbenchRecipes;
import com.tcm.MineTale.registry.ModRecipeDisplay;
import com.tcm.MineTale.registry.ModRecipes;

Expand Down Expand Up @@ -68,27 +76,6 @@ public void buildRecipes() {
.bookCategory(ModRecipeDisplay.CAMPFIRE_SEARCH)
.save(exporter, "campfire_pork_cooking");

// Workbench Recipes

// 1. Workbenches
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
.input(Items.COPPER_INGOT, 2)
.input(ItemTags.LOGS, registryLookup, 10)
.input(ItemTags.STONE_TOOL_MATERIALS, registryLookup, 5)
.output(ModBlocks.ARMORERS_WORKBENCH_BLOCK.asItem())
.unlockedBy("has_workbench", has(ModBlocks.WORKBENCH_WORKBENCH_BLOCK.asItem()))
.bookCategory(ModRecipeDisplay.WORKBENCH_SEARCH)
.save(exporter, "workbench_armorers_workbench");

new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
.input(ItemTags.LOGS, registryLookup, 6)
.input(ItemTags.STONE_TOOL_MATERIALS, registryLookup, 6)
.output(ModBlocks.FURNACE_WORKBENCH_BLOCK_T1.asItem())
.unlockedBy("has_workbench", has(ModBlocks.WORKBENCH_WORKBENCH_BLOCK.asItem()))
.bookCategory(ModRecipeDisplay.WORKBENCH_SEARCH)
.save(exporter, "workbench_furnace_workbench_t1");


// 2. Chests
new WorkbenchRecipeBuilder(ModRecipes.WORKBENCH_TYPE, ModRecipes.WORKBENCH_SERIALIZER)
.input(ItemTags.LOGS, registryLookup, 10)
Expand All @@ -108,6 +95,25 @@ public void buildRecipes() {
.unlockedBy("has_copper_ore", has(Items.COPPER_ORE))
.bookCategory(ModRecipeDisplay.FURNACE_T1_SEARCH)
.save(exporter, "furnace_t1_copper_ingot");

// Alchemist Recipes
AlchemistRecipes.buildRecipes(this, exporter, registryLookup);
// Armor Recipes
ArmorRecipes.buildRecipes(this, exporter, registryLookup);
// Blacksmith Recipes
BlacksmithRecipes.buildRecipes(this, exporter, registryLookup);
// Builder Recipes
BuilderRecipes.buildRecipes(this, exporter, registryLookup);
// Farmer Recipes
FarmerRecipes.buildRecipes(this, exporter, registryLookup);
// Forge Recipes
ForgeRecipes.buildRecipes(this, exporter, registryLookup);
// Furniture Recipes
FurnitureRecipes.buildRecipes(this, exporter, registryLookup);
// General Recipes
GeneralRecipes.buildRecipes(this, exporter, registryLookup);
// Workbench Recipes
WorkbenchRecipes.buildRecipes(this, exporter, registryLookup);
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WorkbenchRecipeBuilder implements RecipeBuilder {
private CraftingBookCategory category = CraftingBookCategory.MISC;
private Identifier bookCategory = BuiltInRegistries.RECIPE_BOOK_CATEGORY
.getKey(ModRecipeDisplay.CAMPFIRE_SEARCH);
private int cookTime = 200;
private float cookTime = 200;
@Nullable private String group;

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ public WorkbenchRecipeBuilder output(ItemLike stack) {
* @param seconds the cook time in seconds
* @return the builder instance
*/
public WorkbenchRecipeBuilder time(int seconds) {
public WorkbenchRecipeBuilder time(float seconds) {
this.cookTime = seconds * 20;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.tcm.MineTale.datagen.recipes;

import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;

public class AlchemistRecipes {
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
// new WorkbenchRecipeBuilder(ModRecipes.ALCHEMIST_TYPE, ModRecipes.ALCHEMIST_SERIALIZER)
// .input(ModItems.EMPTY_POTION_BOTTLE)
// .input(ModItems.PLANT_FIBER, 5)
// .input(ModItems.ESSENCE_OF_LIFE, 2)
// .input(ModItems.VENOM_SACK, 1)
// .output(ModItems.ANTIDOTE)
// .time(1)
// .unlockedBy("has_alchemist_workbench", provider.has(ModBlocks.ALCHEMIST_WORKBENCH_BLOCK.asItem()))
// .bookCategory(ModRecipeDisplay.ALCHEMIST_SEARCH)
// .save(exporter, "ANTIDOTE");

// new WorkbenchRecipeBuilder(ModRecipes.ALCHEMIST_TYPE, ModRecipes.ALCHEMIST_SERIALIZER)
// .input(ModItems.WILD_BERRY, 6)
// .input(ModItems.BOOM_POWDER, 2)
// .input(ModItems.PLANT_FIBER, 4)
// .output(ModItems.POPBERRY_BOMB, 2)
// .time(0.5)
// .unlockedBy("has_alchemist_workbench", provider.has(ModBlocks.ALCHEMIST_WORKBENCH_BLOCK.asItem()))
// .bookCategory(ModRecipeDisplay.ALCHEMIST_SEARCH)
// .save(exporter, "POPBERRY_BOMB");
}
}
89 changes: 89 additions & 0 deletions src/client/java/com/tcm/MineTale/datagen/recipes/ArmorRecipes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.tcm.MineTale.datagen.recipes;

import com.tcm.MineTale.datagen.builders.WorkbenchRecipeBuilder;
import com.tcm.MineTale.registry.ModItems;
import com.tcm.MineTale.registry.ModRecipeDisplay;
import com.tcm.MineTale.registry.ModRecipes;

import net.minecraft.core.HolderLookup;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.world.item.Items;

public class ArmorRecipes {
public static void buildRecipes(RecipeProvider provider, RecipeOutput exporter, HolderLookup.Provider lookup) {
// Copper Armor
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
.input(Items.COPPER_INGOT, 11)
.input(ModItems.PLANT_FIBER, 4)
.output(Items.COPPER_CHESTPLATE)
.time(3)
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
.save(exporter, "copper_cuirass");
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
.input(Items.COPPER_INGOT, 6)
.input(ModItems.PLANT_FIBER, 2)
.output(Items.COPPER_HELMET)
.time(3)
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
.save(exporter, "copper_helmet");
new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
.input(Items.COPPER_INGOT, 9)
.input(ModItems.PLANT_FIBER, 3)
.output(Items.COPPER_LEGGINGS)
.time(3)
.unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
.bookCategory(ModRecipeDisplay.ARMORERS_SEARCH)
.save(exporter, "copper_greaves");
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(Items.COPPER_INGOT, 5)
// .input(ModItems.PLANT_FIBER, 1)
// .output(Items.COPPER_LEGGINGS)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "copper_gauntlets");
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(Items.COPPER_INGOT, 2)
// .input(ModItems.PLANT_FIBER, 3)
// .input(ItemTags.LOGS, lookup)
// .output(ModItems.COPPER_SHIELD)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "COPPER_SHIELD");

// Wood Armor
// TODO: WoodenArmor Not Implemented
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(ItemTags.LOGS, lookup, 15)
// .input(ModItems.PLANT_FIBER, 3)
// .output(Items.COPPER_CHESTPLATE)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "copper_cuirass");
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(Items.COPPER_INGOT, 6)
// .input(ModItems.PLANT_FIBER, 2)
// .output(Items.COPPER_HELMET)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "copper_helmet");
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(Items.COPPER_INGOT, 9)
// .input(ModItems.PLANT_FIBER, 3)
// .output(Items.COPPER_LEGGINGS)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "copper_greaves");
// new WorkbenchRecipeBuilder(ModRecipes.ARMORERS_TYPE, ModRecipes.ARMORERS_SERIALIZER)
// .input(Items.COPPER_INGOT, 5)
// .input(ModItems.PLANT_FIBER, 1)
// .output(Items.COPPER_LEGGINGS)
// .time(3)
// .unlockedBy("has_copper_ingot", provider.has(Items.COPPER_INGOT))
// .save(exporter, "copper_gauntlets");


}
}
Loading