Jump to content

Recommended Posts

Posted (edited)

In a custom recipe use a Water Bucket as ingredient to create another fluid bucket. The recipe work except for an empty bucket left on the crafting matrix.
To remove the empty bucket I was trying to use the ItemCraftedEvent, because I suppose is an event that trigger when an item is crafted. The problem is that the event don't run.
The code just contain some println to check what the methods of the event return to me.

 

REMOVED

Edited by Slexom
Changed title

My mod:

Earth2Java - Mobs [1.15.2]

 

Posted

You can’t modify the crafting matrix in that event.

Create a custom IRecipe instead.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted (edited)

Created a recipe extending a ShapelessRecipe but the getRemainingItems is not triggered. I think is in that function where I can exclude the empty bucket, no?


Recipe

Spoiler

 



public class MudBucketRecipe extends ShapelessRecipe {

    public MudBucketRecipe(ResourceLocation idIn, String groupIn, ItemStack recipeOutputIn, NonNullList<Ingredient> recipeItemsIn) {
        super(idIn, groupIn, recipeOutputIn, recipeItemsIn);
    }

    @Override
    public NonNullList<ItemStack> getRemainingItems(final CraftingInventory inv) {
        System.out.println("HERE");
        final NonNullList<ItemStack> remainingItems = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);
        for (int i = 0; i < remainingItems.size(); ++i) {
            ItemStack itemstack = inv.getStackInSlot(i);
            if (itemstack.hasContainerItem() && itemstack.getItem() != Items.BUCKET) {
                remainingItems.set(i, itemstack.getContainerItem());
            }
        }
        return remainingItems;
    }
    public IRecipeSerializer<?> getSerializer() {
        return RecipesInit.MUD_BUCKET_RECIPE.get();
    }

    public static class Serializer extends ForgeRegistryEntry<IRecipeSerializer<?>> implements IRecipeSerializer<MudBucketRecipe> {
        @Override
        public MudBucketRecipe read(final ResourceLocation recipeID, final JsonObject json) {
            final String group = JSONUtils.getString(json, "group", "");
            final NonNullList<Ingredient> ingredients = NonNullList.create();
            for (final JsonElement element : JSONUtils.getJsonArray(json, "ingredients")) {
                ingredients.add(CraftingHelper.getIngredient(element));
            }
            if (ingredients.isEmpty()) {
                throw new JsonParseException("No ingredients for shapeless recipe");
            }
            final ItemStack result = CraftingHelper.getItemStack(JSONUtils.getJsonObject(json, "result"), true);
            return new MudBucketRecipe(recipeID, group, result, ingredients);
        }

        @Override
        public MudBucketRecipe read(final ResourceLocation recipeID, final PacketBuffer buffer) {
            final String group = buffer.readString(Short.MAX_VALUE);
            final int numIngredients = buffer.readVarInt();
            final NonNullList<Ingredient> ingredients = NonNullList.withSize(numIngredients, Ingredient.EMPTY);
            for (int j = 0; j < ingredients.size(); ++j) {
                ingredients.set(j, Ingredient.read(buffer));
            }
            final ItemStack result = buffer.readItemStack();
            return new MudBucketRecipe(recipeID, group, result, ingredients);
        }

        @Override
        public void write(final PacketBuffer buffer, final MudBucketRecipe recipe) {
            buffer.writeString(recipe.getGroup());
            buffer.writeVarInt(recipe.getIngredients().size());
            for (final Ingredient ingredient : recipe.getIngredients()) {
                ingredient.write(buffer);
            }
            buffer.writeItemStack(recipe.getRecipeOutput());
        }
    }
}

 

 

 

 

Registration

Spoiler



public class RecipesInit {

    public static final DeferredRegister<IRecipeSerializer<?>> RECIPES = new DeferredRegister<>(ForgeRegistries.RECIPE_SERIALIZERS, EarthtojavamobsMod.MOD_ID);

    public static final RegistryObject<MudBucketRecipe.Serializer> MUD_BUCKET_RECIPE = RECIPES.register("mud_bucket", MudBucketRecipe.Serializer::new);

}


 


JSON

Spoiler

 


{
  "type": "minecraft:crafting_shapeless",
  "ingredients": [
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:water_bucket"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    },
    {
      "item": "minecraft:dirt"
    }
  ],
  "result": {
    "item": "earthtojavamobs:mud_fluid_bucket"
  }
}

 

 

 

 

Edited by Slexom

My mod:

Earth2Java - Mobs [1.15.2]

 

Posted
7 minutes ago, Slexom said:

"type": "minecraft:crafting_shapeless",

You aren't using your own IRecipe type.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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



×
×
  • Create New...

Important Information

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