Jump to content

Recommended Posts

Posted (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 by BlueFFlame
Clarification
Posted (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 by Luis_ST
Posted
On 11/4/2023 at 6:33 AM, BlueFFlame said:

Ah, ok. What forum should I post in for next time?

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?

Posted

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. 

Posted
46 minutes ago, 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?

Quoting this becuase I realized I wasn’t quoting before.

Posted
5 hours ago, 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. 

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?

Posted
2 hours ago, 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?

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.

Posted
12 hours ago, 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?

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

Posted

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.

Posted
27 minutes ago, 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.

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.

Posted

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.

Posted
On 11/8/2023 at 4: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.

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.

Posted
5 hours ago, 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?

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.

Posted
8 minutes ago, 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.

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.

Posted
On 11/10/2023 at 10: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.

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.

Posted

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.

Posted
On 11/17/2023 at 10: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.

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.

Posted

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.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • This is the last line before the crash: [ebwizardry]: Synchronising spell emitters for PixelTraveler But I have no idea what this means
    • What in particular? I barely used that mod this time around, and it's never been a problem in the past.
    • Im trying to build my mod using shade since i use the luaj library however i keep getting this error Reason: Task ':reobfJar' uses this output of task ':shadowJar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. So i try adding reobfJar.dependsOn shadowJar  Could not get unknown property 'reobfJar' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. my gradle file plugins { id 'eclipse' id 'idea' id 'maven-publish' id 'net.minecraftforge.gradle' version '[6.0,6.2)' id 'com.github.johnrengelman.shadow' version '7.1.2' id 'org.spongepowered.mixin' version '0.7.+' } apply plugin: 'net.minecraftforge.gradle' apply plugin: 'org.spongepowered.mixin' apply plugin: 'com.github.johnrengelman.shadow' version = mod_version group = mod_group_id base { archivesName = mod_id } // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) //jarJar.enable() println "Java: ${System.getProperty 'java.version'}, JVM: ${System.getProperty 'java.vm.version'} (${System.getProperty 'java.vendor'}), Arch: ${System.getProperty 'os.arch'}" minecraft { mappings channel: mapping_channel, version: mapping_version copyIdeResources = true runs { configureEach { workingDirectory project.file('run') property 'forge.logging.markers', 'REGISTRIES' property 'forge.logging.console.level', 'debug' arg "-mixin.config=derp.mixin.json" mods { "${mod_id}" { source sourceSets.main } } } client { // Comma-separated list of namespaces to load gametests from. Empty = all namespaces. property 'forge.enabledGameTestNamespaces', mod_id } server { property 'forge.enabledGameTestNamespaces', mod_id args '--nogui' } gameTestServer { property 'forge.enabledGameTestNamespaces', mod_id } data { workingDirectory project.file('run-data') args '--mod', mod_id, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/') } } } sourceSets.main.resources { srcDir 'src/generated/resources' } repositories { flatDir { dirs './libs' } maven { url = "https://jitpack.io" } } configurations { shade implementation.extendsFrom shade } dependencies { minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" implementation 'org.luaj:luaj-jse-3.0.2' implementation fg.deobf("com.github.Virtuoel:Pehkui:${pehkui_version}") annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' minecraftLibrary 'luaj:luaj-jse:3.0.2' shade 'luaj:luaj-jse:3.0.2' } // Example for how to get properties into the manifest for reading at runtime. tasks.named('jar', Jar).configure { manifest { attributes([ 'Specification-Title' : mod_id, 'Specification-Vendor' : mod_authors, 'Specification-Version' : '1', // We are version 1 of ourselves 'Implementation-Title' : project.name, 'Implementation-Version' : project.jar.archiveVersion, 'Implementation-Vendor' : mod_authors, 'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"), "TweakClass" : "org.spongepowered.asm.launch.MixinTweaker", "TweakOrder" : 0, "MixinConfigs" : "derp.mixin.json" ]) } rename 'mixin.refmap.json', 'derp.mixin-refmap.json' } shadowJar { archiveClassifier = '' configurations = [project.configurations.shade] finalizedBy 'reobfShadowJar' } assemble.dependsOn shadowJar reobf { re shadowJar {} } publishing { publications { mavenJava(MavenPublication) { artifact jar } } repositories { maven { url "file://${project.projectDir}/mcmodsrepo" } } } my entire project:https://github.com/kevin051606/DERP-Mod/tree/Derp-1.0-1.20
    • All versions of Minecraft Forge suddenly black screen even without mods (tried reinstalling original Minecraft, Java, updating drivers doesn't work)
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.