NerdyPuzzle / Just-enough-recipes-MCreator

GNU Lesser General Public License v2.1
3 stars 1 forks source link

compilation error #2

Closed JusteKal closed 7 months ago

JusteKal commented 7 months ago

Hello ! When i try to compile my mod, i get an error :

MCreatorWorkspaces\Mynthos_Juice\src\main\java\be\justekal\mynthosjuice\jei_recipes\MynthosJuiceJEI2Recipe.java:88: error: cannot find symbol public MynthosJuiceJEI2Recipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) { ^ symbol: class JsonObject location: class Serializer MCreatorWorkspaces\Mynthos_Juice\src\main\java\be\justekal\mynthosjuice\jei_recipes\MynthosJuiceJEI2Recipe.java:90: error: cannot find symbol JsonArray ingredients = GsonHelper.getAsJsonArray(pSerializedRecipe, "ingredients"); ^ symbol: class JsonArray location: class Serializer 2 errors FAILURE: Build failed with an exception.

Plugin version: Just enough recipes v1.8.1 (2024.1 ONLY) MCreator version: 2024.1.15821 Minecraft Version 1.20.1

JusteKal commented 7 months ago

and here is the code

package be.justekal.mynthosjuice.jei_recipes;

import net.minecraft.world.level.storage.loot.Serializer;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.SimpleContainer;
import net.minecraft.util.GsonHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.NonNullList;

import javax.annotation.Nullable;

public class MynthosJuiceJEI2Recipe implements Recipe<SimpleContainer> {
    private final ResourceLocation id;
    private final ItemStack output;
    private final NonNullList<Ingredient> recipeItems;

    public MynthosJuiceJEI2Recipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems) {
        this.id = id;
        this.output = output;
        this.recipeItems = recipeItems;
    }

    @Override
    public boolean matches(SimpleContainer pContainer, Level pLevel) {
        if (pLevel.isClientSide()) {
            return false;
        }
        return false;
        //return recipeItems.get(0).test(pContainer.getItem(1));
    }

    @Override
    public NonNullList<Ingredient> getIngredients() {
        return recipeItems;
    }

    @Override
    public ItemStack assemble(SimpleContainer pContainer, RegistryAccess access) {
        return output;
    }

    @Override
    public boolean canCraftInDimensions(int pWidth, int pHeight) {
        return true;
    }

    @Override
    public ItemStack getResultItem(RegistryAccess access) {
        return output.copy();
    }

    @Override
    public ResourceLocation getId() {
        return id;
    }

    @Override
    public RecipeType<?> getType() {
        return Type.INSTANCE;
    }

    @Override
    public RecipeSerializer<?> getSerializer() {
        return Serializer.INSTANCE;
    }

    public static class Type implements RecipeType<MynthosJuiceJEI2Recipe> {
        private Type() {
        }

        public static final Type INSTANCE = new Type();
        public static final String ID = "mynthos_juice_jei_2";
    }

    public static class Serializer implements RecipeSerializer<MynthosJuiceJEI2Recipe> {
        public static final Serializer INSTANCE = new Serializer();
        public static final ResourceLocation ID = new ResourceLocation("mynthos_juice", "mynthos_juice_jei_2");

        @Override
        public MynthosJuiceJEI2Recipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) {
            ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(pSerializedRecipe, "output"));
            JsonArray ingredients = GsonHelper.getAsJsonArray(pSerializedRecipe, "ingredients");
            NonNullList<Ingredient> inputs = NonNullList.withSize(2, Ingredient.EMPTY);
            for (int i = 0; i < inputs.size(); i++) {
                inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
            }
            return new MynthosJuiceJEI2Recipe(pRecipeId, output, inputs);
        }

        @Override
        public @Nullable MynthosJuiceJEI2Recipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
            NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
            for (int i = 0; i < inputs.size(); i++) {
                inputs.set(i, Ingredient.fromNetwork(buf));
            }
            ItemStack output = buf.readItem();
            return new MynthosJuiceJEI2Recipe(id, output, inputs);
        }

        @Override
        public void toNetwork(FriendlyByteBuf buf, MynthosJuiceJEI2Recipe recipe) {
            buf.writeInt(recipe.getIngredients().size());
            for (Ingredient ing : recipe.getIngredients()) {
                ing.toNetwork(buf);
            }
            buf.writeItemStack(recipe.getResultItem(null), false);
        }
    }
}
Fenris42 commented 7 months ago

I to am getting compile errors after updating from MCreator version 2023.4 to 2024.1.

MCreator version: 2024.1.15821 JER version: 1.8.1 Forge version: forge-1.19.2 Note: I am using the 1.19.2 Generator

I have tried to delete and recreate the recipe type thinking it might be a stale file but even a fresh one gets the same error.

Build Error: Fails to compile on recipe type I have made for a machine Capture

Build

Build log:

Executing Gradle task: runClient 
Build info: MCreator 2024.1.15821, forge-1.19.2, 64-bit, 32692 MB, Windows 10, JVM 17.0.10, JAVA_HOME: C:\Program Files\MCreator\jdk, started on: 2024-04-13-14:27:19 
Loaded APIs: use_compiled_mods, jei 

Task :compileJava FAILED 
[E:\Projects\Minecraft\Recycle\MC_Recycle\src\main\java\net\mcreator\recycle\jei_recipes\PoweredComposterTypeRecipe.java:87](file:///E:/Projects/Minecraft/Recycle/MC_Recycle/src/main/java/net/mcreator/recycle/jei_recipes/PoweredComposterTypeRecipe.java:87): error: cannot find symbol 
        public PoweredComposterTypeRecipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) { 
                                                                               ^ 
  symbol:   class JsonObject 
  location: class Serializer 
[E:\Projects\Minecraft\Recycle\MC_Recycle\src\main\java\net\mcreator\recycle\jei_recipes\PoweredComposterTypeRecipe.java:89](file:///E:/Projects/Minecraft/Recycle/MC_Recycle/src/main/java/net/mcreator/recycle/jei_recipes/PoweredComposterTypeRecipe.java:89): error: cannot find symbol 
            JsonArray ingredients = GsonHelper.getAsJsonArray(pSerializedRecipe, "ingredients"); 
            ^ 
  symbol:   class JsonArray 
  location: class Serializer 
2 errors 
FAILURE: Build failed with an exception. 
* What went wrong: 
Execution failed for task ':compileJava'. 
> Compilation failed; see the compiler error output for details. 
* Try: 
> Run with --info option to get more log output. 
> Run with --scan to get full insights. 
BUILD FAILED in 4s 
1 actionable task: 1 executed 

BUILD FAILED 
Task completed in 36 seconds

PoweredComposterTypeRecipe.java

package net.mcreator.recycle.jei_recipes;

import net.minecraft.world.level.storage.loot.Serializer;
import net.minecraft.world.level.Level;
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.SimpleContainer;
import net.minecraft.util.GsonHelper;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.core.NonNullList;

import javax.annotation.Nullable;

public class PoweredComposterTypeRecipe implements Recipe<SimpleContainer> {
    private final ResourceLocation id;
    private final ItemStack output;
    private final NonNullList<Ingredient> recipeItems;

    public PoweredComposterTypeRecipe(ResourceLocation id, ItemStack output, NonNullList<Ingredient> recipeItems) {
        this.id = id;
        this.output = output;
        this.recipeItems = recipeItems;
    }

    @Override
    public boolean matches(SimpleContainer pContainer, Level pLevel) {
        if (pLevel.isClientSide()) {
            return false;
        }
        return false;
        //return recipeItems.get(0).test(pContainer.getItem(1));
    }

    @Override
    public NonNullList<Ingredient> getIngredients() {
        return recipeItems;
    }

    @Override
    public ItemStack assemble(SimpleContainer pContainer) {
        return output;
    }

    @Override
    public boolean canCraftInDimensions(int pWidth, int pHeight) {
        return true;
    }

    @Override
    public ItemStack getResultItem() {
        return output.copy();
    }

    @Override
    public ResourceLocation getId() {
        return id;
    }

    @Override
    public RecipeType<?> getType() {
        return Type.INSTANCE;
    }

    @Override
    public RecipeSerializer<?> getSerializer() {
        return Serializer.INSTANCE;
    }

    public static class Type implements RecipeType<PoweredComposterTypeRecipe> {
        private Type() {
        }

        public static final Type INSTANCE = new Type();
        public static final String ID = "powered_composter_type";
    }

    public static class Serializer implements RecipeSerializer<PoweredComposterTypeRecipe> {
        public static final Serializer INSTANCE = new Serializer();
        public static final ResourceLocation ID = new ResourceLocation("recycle", "powered_composter_type");

        @Override
        public PoweredComposterTypeRecipe fromJson(ResourceLocation pRecipeId, JsonObject pSerializedRecipe) {
            ItemStack output = ShapedRecipe.itemStackFromJson(GsonHelper.getAsJsonObject(pSerializedRecipe, "output"));
            JsonArray ingredients = GsonHelper.getAsJsonArray(pSerializedRecipe, "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 PoweredComposterTypeRecipe(pRecipeId, output, inputs);
        }

        @Override
        public @Nullable PoweredComposterTypeRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
            NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
            for (int i = 0; i < inputs.size(); i++) {
                inputs.set(i, Ingredient.fromNetwork(buf));
            }
            ItemStack output = buf.readItem();
            return new PoweredComposterTypeRecipe(id, output, inputs);
        }

        @Override
        public void toNetwork(FriendlyByteBuf buf, PoweredComposterTypeRecipe recipe) {
            buf.writeInt(recipe.getIngredients().size());
            for (Ingredient ing : recipe.getIngredients()) {
                ing.toNetwork(buf);
            }
            buf.writeItemStack(recipe.getResultItem(), false);
        }
    }
}
NerdyPuzzle commented 7 months ago

Seems the import formatter is acting up again. Will fix this by including the imports in the template.

NerdyPuzzle commented 7 months ago

Thanks for the bug report, releasing a fix now.

Fenris42 commented 7 months ago

Thanks for the quick turn around. I updated the plugin on my end and the recipe type was still failing to compile. After deleting it and recreating it successfully compiled and ran without issue.

NerdyPuzzle commented 7 months ago

You could have regenerated the code but that works too

Fenris42 commented 7 months ago

oh, the more you know. Thanks for the tip.