BlueFFlame Posted November 2, 2023 Posted November 2, 2023 (edited) Hello! I'm writing a Minecraft based on tech and machines, and I'm making a furnace-esque machine for processing ores. However, I can't seem to get the recipes to work. Whenever I put the ore into the slot, nothing happens. I added the inventory property to the watchlist and it showed that it was detecting the block in the right slot, but for some reason its not triggering crafting. I'm at a loss right now. Please note that I am new to modding, and I followed a tutorial for this code, so I don't really know code conventions yet. Also, there's no crashes at all. No errors thrown. It just doesn't do anything. Below is some of the associated code: 1) The .json files for the recipes { "type": "darkcollective:ore_refining", "ingredients": [ { "item": "darkcollective:aernium_ore" } ], "output": { "count": 2, "item": "darkcollective:aernium_ingot" } } 2) The code in the OreRefineryEntityClass that looks for the recipe and, if found, starts the crafting private boolean hasRecipe() { Optional<OreRefineryRecipe> recipe = getCurrentRecipe(); System.out.println(recipe); if(recipe.isEmpty()) { return false; } ItemStack result = recipe.get().getResultItem(getLevel().registryAccess()); return canInsertAmountIntoOutputSlot(result.getCount()) && canInsertItemIntoOutputSlot(result.getItem()); } private Optional<OreRefineryRecipe> getCurrentRecipe() { SimpleContainer inventory = new SimpleContainer(this.itemHandler.getSlots()); for(int i = 0; i < itemHandler.getSlots(); i++) { inventory.setItem(i, this.itemHandler.getStackInSlot(i)); } return this.level.getRecipeManager().getRecipeFor(OreRefineryRecipe.Type.INSTANCE, inventory, level); } 3) The code for the RecipeSerializer. public static class Serializer implements RecipeSerializer<OreRefineryRecipe>{ public static final Serializer INSTANCE = new Serializer(); public static final ResourceLocation ID = new ResourceLocation(DarkCollective.ModID, "ore_refining"); @Override public OreRefineryRecipe fromJson(ResourceLocation recipeId, JsonObject serializedRecipe) { ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(serializedRecipe, "result")); JsonArray ingredients = GsonHelper.getAsJsonArray(serializedRecipe, "ingredients"); NonNullList<Ingredient> inputs = NonNullList.withSize(1, Ingredient.EMPTY); for(int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromJson(ingredients.get(i))); } return new OreRefineryRecipe(inputs, output, recipeId); } @Override public @Nullable OreRefineryRecipe fromNetwork(ResourceLocation recipeID, FriendlyByteBuf buffer) { NonNullList<Ingredient> inputs = NonNullList.withSize(buffer.readInt(), Ingredient.EMPTY); for(int i = 0; i < inputs.size(); i++) { inputs.set(i, Ingredient.fromNetwork(buffer)); } ItemStack output = buffer.readItem(); return new OreRefineryRecipe(inputs, output, recipeID); } @Override public void toNetwork(FriendlyByteBuf buffer, OreRefineryRecipe recipe) { buffer.writeInt(recipe.inputItems.size()); for (Ingredient ingredient : recipe.getIngredients()) { ingredient.toNetwork(buffer); } buffer.writeItemStack(recipe.getResultItem(null), false); } } If there's anything I missed, just tell me and I'd be happy to send. Also, I'm on version 1.20. Thank you! Edited November 2, 2023 by BlueFFlame Clarification Quote
Luis_ST Posted November 3, 2023 Posted November 3, 2023 (edited) Show more of your code, ideally a Git repo. BTW, wrong Forum, your questions has nothing to do with ForgeGradle. But please do not create a new thread, but remember it for the next time. Edited November 3, 2023 by Luis_ST Quote
BlueFFlame Posted November 4, 2023 Author Posted November 4, 2023 Ah, ok. What forum should I post in for next time? Also, here's my GitHub link: https://github.com/giornoggiovanna/DarkCollectiveGit/tree/main/src/main Quote
Luis_ST Posted November 6, 2023 Posted November 6, 2023 On 11/4/2023 at 5:33 AM, BlueFFlame said: Ah, ok. What forum should I post in for next time? Expand Direktly in Modder Support Have you used debugger to check your code? At first look the code should work, is a recipe found in the tick method? Quote
BlueFFlame Posted November 6, 2023 Author Posted November 6, 2023 Yeah, I’ve looked at it in the debugger. There’s no recipe found, as the getRecipeMethod is returning null. I’m not sure why though, as the inventory isn’t null: it’s detecting the correct item in the correct slot. Quote
BlueFFlame Posted November 6, 2023 Author Posted November 6, 2023 Just so you know, slot 0 its the input, and slot 1 is the output. Slot 2 is a fuel input (haven’t written functionality for that yet). Quote
BlueFFlame Posted November 6, 2023 Author Posted November 6, 2023 On 11/6/2023 at 1:44 PM, Luis_ST said: Direktly in Modder Support Have you used debugger to check your code? At first look the code should work, is a recipe found in the tick method? Expand Quoting this becuase I realized I wasn’t quoting before. Quote
Luis_ST Posted November 6, 2023 Posted November 6, 2023 On 11/6/2023 at 2:28 PM, BlueFFlame said: Yeah, I’ve looked at it in the debugger. There’s no recipe found, as the getRecipeMethod is returning null. I’m not sure why though, as the inventory isn’t null: it’s detecting the correct item in the correct slot. Expand RecipeManager#getRecipeFor uses OreRefineryRecipe#matches to enure the items in the container are valid for the given SimpleContainer are you sure the implemention is correct since you have a NonNullList as input but you only use the first item of the list? Quote
BlueFFlame Posted November 6, 2023 Author Posted November 6, 2023 On 11/6/2023 at 8:23 PM, Luis_ST said: RecipeManager#getRecipeFor uses OreRefineryRecipe#matches to enure the items in the container are valid for the given SimpleContainer are you sure the implemention is correct since you have a NonNullList as input but you only use the first item of the list? Expand Hmm, not sure. I can check with the tutorial. Again, I'm not 100% sure as to how the whole process functions, as the tutorial didn't really explain well. From what I understand, the recipes are gathered from the Json files and stored in the NonNullList. Quote
BlueFFlame Posted November 7, 2023 Author Posted November 7, 2023 On 11/6/2023 at 8:23 PM, Luis_ST said: RecipeManager#getRecipeFor uses OreRefineryRecipe#matches to enure the items in the container are valid for the given SimpleContainer are you sure the implemention is correct since you have a NonNullList as input but you only use the first item of the list? Expand Just checked with the tutorial, they’re doing the same thing. From what I understand, the non-null list is just storing the item that is in the input slot (in this case, the SimpleContainer slot 0). I can send the link to the tutorial GitHub: https://github.com/Tutorials-By-Kaupenjoe/Forge-Tutorial-1.20.X/tree/31-recipeTypes. Quote
Luis_ST Posted November 7, 2023 Posted November 7, 2023 I cloned your git repo to debug your mod locally on my PC, but it seems to be broken. The project is missing some important gradle files because you are using a java .gitignore file, you should use the file which comes with the mdk. Quote
BlueFFlame Posted November 7, 2023 Author Posted November 7, 2023 On 11/7/2023 at 7:59 PM, Luis_ST said: I cloned your git repo to debug your mod locally on my PC, but it seems to be broken. The project is missing some important gradle files because you are using a java .gitignore file, you should use the file which comes with the mdk. Expand Ok, I just changed the .gitignore. Not sure if that also added the gradle files you needed, but it added something. If it doesn't, I can just send you the files that you need manually. Quote
Luis_ST Posted November 8, 2023 Posted November 8, 2023 I am still not able to import your project into my IDE, I would recommend you to remove all files from github that can be found in the .gitignore file. Iedally you create a new branch. Quote
BlueFFlame Posted November 10, 2023 Author Posted November 10, 2023 On 11/8/2023 at 3:24 PM, Luis_ST said: I am still not able to import your project into my IDE, I would recommend you to remove all files from github that can be found in the .gitignore file. Iedally you create a new branch. Expand Ah, I realized my response didn't send. Would you be able to just copy and paste the necessary files into a new project? I didn't change much in my gradle files, basically just specifying the mod id (which can be seen in the main class) and the version of forge (40.0.14). If you're unable to do that, that's fine, but I may need some help with creating a new branch and working with Git since my Git expertise really only go up to branch merging. Quote
Luis_ST Posted November 10, 2023 Posted November 10, 2023 On 11/10/2023 at 3:55 PM, BlueFFlame said: Ah, I realized my response didn't send. Would you be able to just copy and paste the necessary files into a new project? Expand That would work, but note the correct .gitignore must be part of the first commit. I would recommend you to learn the basics of Git, it is very helpful for a programmer. Quote
BlueFFlame Posted November 10, 2023 Author Posted November 10, 2023 On 11/10/2023 at 9:47 PM, Luis_ST said: That would work, but note the correct .gitignore must be part of the first commit. I would recommend you to learn the basics of Git, it is very helpful for a programmer. Expand Yeah, it's been on my list of things to learn. As of now, I haven't really had a need to create branches or do anything more than commiting, pushing and pulling. I'll probably create a new branch for the .gitignore; I could just look at how to do it. Quote
BlueFFlame Posted November 16, 2023 Author Posted November 16, 2023 On 11/10/2023 at 9:47 PM, Luis_ST said: That would work, but note the correct .gitignore must be part of the first commit. I would recommend you to learn the basics of Git, it is very helpful for a programmer. Expand How's debugging going? Have you figured a root cause? I had an idea of what it was (recipe returning null), but I couldn't figure out why it was doing that. If you haven't had time to work on it don't worry, I'm not really in a time rush. Quote
Luis_ST Posted November 17, 2023 Posted November 17, 2023 Sorry, I completely forgot about it. First of all, there is a problem in your recipes. You load a property "result" from your recipes in the Serialiser, but in the recipe you specify "ouput". (Read your logs!) Secondly, you have two ItemStackHandlers in your BlockEntity, you should use the one from the Capability. Remove the ItemStackHandler named 'itemHandler' and the problem should be fixed. It worked for me. Quote
BlueFFlame Posted November 19, 2023 Author Posted November 19, 2023 On 11/17/2023 at 9:35 PM, Luis_ST said: Sorry, I completely forgot about it. First of all, there is a problem in your recipes. You load a property "result" from your recipes in the Serialiser, but in the recipe you specify "ouput". (Read your logs!) Secondly, you have two ItemStackHandlers in your BlockEntity, you should use the one from the Capability. Remove the ItemStackHandler named 'itemHandler' and the problem should be fixed. It worked for me. Expand Oh my god, thank you so much! It works perfectly now. Of course it was a typo. Was there anything else I should change in my code, to keep up with conventions and make the game run better? Again, I'm new to modding, so I don't know a lot about conventions so I'd like to learn. Quote
Luis_ST Posted November 19, 2023 Posted November 19, 2023 The only thing I noticed when debugging is that you use System.out for logging. I would recommend you to use the logger from the mdk because you get information like time, thread or the file directly to the output. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.