Jump to content

Recommended Posts

Posted (edited)

I need to replace vanilla water bottle with empty bottle after craft, how can I do this?  I will give code if you will advice me something and error occurs.

EDIT: Version is 1.16.5

Edited by SuperRuper1209
Posted

it depends on wether you want the vanilla water bottle always return en empty water bottle (for any recipe that uses a water bottle), or if there is some specific recipes from your mod that you want that behaviour on

for the latter, the solution is using Special Recipes, you can look at the Book or Map cloning recipes for some example. you'll need to override the getRemainingItems method, and perform such logic there

  • Thanks 1
Posted

Parsing error loading recipe tds:marshmallow
com.google.gson.JsonSyntaxException: Invalid or unsupported recipe type 'tds:crafting_special_marshmallow'

Spoiler

public static class MarshmallowRecipe extends SpecialRecipe { public static final IRecipeSerializer<MarshmallowRecipe> SERIALIZER = new SpecialRecipeSerializer<>(MarshmallowRecipe::new); public MarshmallowRecipe(ResourceLocation p_i48169_1_) { super(p_i48169_1_); } @Override public boolean matches(CraftingInventory p_77569_1_, World p_77569_2_) { boolean foundSeeds = false; boolean foundBottle = false; boolean foundPotato = false; boolean foundSugar = false; boolean notRight = false; for (int j = 0; j < p_77569_1_.getContainerSize(); ++j) { ItemStack itemStack = p_77569_1_.getItem(j); if (!itemStack.isEmpty()) { if (itemStack.sameItem(new ItemStack(Items.POTATO)) && !foundPotato) { foundPotato = true; } else if (foundPotato && itemStack.sameItem(new ItemStack(Items.POTATO))) { notRight = true; } if (itemStack.sameItem(new ItemStack(Items.SUGAR)) && !foundSugar) { foundSugar = true; } else if (foundSugar && itemStack.sameItem(new ItemStack(Items.SUGAR))) { notRight = true; } if (PotionUtils.getPotion(itemStack) != null && PotionUtils.getPotion(itemStack) == Potions.WATER && !foundBottle) { foundBottle = true; } else if (foundBottle && PotionUtils.getPotion(itemStack) != null && PotionUtils.getPotion(itemStack) == Potions.WATER) { notRight = true; } if (Tags.Items.SEEDS.getValues().contains(itemStack.getItem()) && !foundSeeds) { foundSeeds = true; } else if (foundSeeds && Tags.Items.SEEDS.getValues().contains(itemStack.getItem())) { notRight = true; } } } if (foundSeeds && foundBottle && foundPotato && foundSugar && !notRight) { return true; } return false; } @Override public ItemStack assemble(CraftingInventory p_77572_1_) { ItemStack stack = new ItemStack(SimpleItems.MARSHALLOW); stack.setCount(1); return stack; } @Override public boolean canCraftInDimensions(int p_194133_1_, int p_194133_2_) { return true; } @Override public NonNullList<ItemStack> getRemainingItems(CraftingInventory p_179532_1_) { NonNullList<ItemStack> list = NonNullList.withSize(0, ItemStack.EMPTY); list.set(0, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.EMPTY)); return list; } @Override public IRecipeSerializer<?> getSerializer() { return SERIALIZER; } }

Spoiler

{ "type": "tds:crafting_special_marshmallow" }

Spoiler

Registry.register(Registry.RECIPE_SERIALIZER, new ResourceLocation("tds", "crafting_special_marshmallow"), Marshmallow.MarshmallowRecipe.SERIALIZER);

 

Posted

Ok I got it, use this event to register if anyone has the same problem:

public void specialRecipesRegister(final RegistryEvent.Register<IRecipeSerializer<?>> event) { event.getRegistry().register(Marshmallow.MarshmallowRecipe.SERIALIZER.setRegistryName(new ResourceLocation("tds", "crafting_special_marshmallow"))); }

Posted
58 minutes ago, SuperRuper1209 said:

Parsing error loading recipe tds:marshmallow
com.google.gson.JsonSyntaxException: Invalid or unsupported recipe type 'tds:crafting_special_marshmallow'

  Reveal hidden contents

public static class MarshmallowRecipe extends SpecialRecipe { public static final IRecipeSerializer<MarshmallowRecipe> SERIALIZER = new SpecialRecipeSerializer<>(MarshmallowRecipe::new); public MarshmallowRecipe(ResourceLocation p_i48169_1_) { super(p_i48169_1_); } @Override public boolean matches(CraftingInventory p_77569_1_, World p_77569_2_) { boolean foundSeeds = false; boolean foundBottle = false; boolean foundPotato = false; boolean foundSugar = false; boolean notRight = false; for (int j = 0; j < p_77569_1_.getContainerSize(); ++j) { ItemStack itemStack = p_77569_1_.getItem(j); if (!itemStack.isEmpty()) { if (itemStack.sameItem(new ItemStack(Items.POTATO)) && !foundPotato) { foundPotato = true; } else if (foundPotato && itemStack.sameItem(new ItemStack(Items.POTATO))) { notRight = true; } if (itemStack.sameItem(new ItemStack(Items.SUGAR)) && !foundSugar) { foundSugar = true; } else if (foundSugar && itemStack.sameItem(new ItemStack(Items.SUGAR))) { notRight = true; } if (PotionUtils.getPotion(itemStack) != null && PotionUtils.getPotion(itemStack) == Potions.WATER && !foundBottle) { foundBottle = true; } else if (foundBottle && PotionUtils.getPotion(itemStack) != null && PotionUtils.getPotion(itemStack) == Potions.WATER) { notRight = true; } if (Tags.Items.SEEDS.getValues().contains(itemStack.getItem()) && !foundSeeds) { foundSeeds = true; } else if (foundSeeds && Tags.Items.SEEDS.getValues().contains(itemStack.getItem())) { notRight = true; } } } if (foundSeeds && foundBottle && foundPotato && foundSugar && !notRight) { return true; } return false; } @Override public ItemStack assemble(CraftingInventory p_77572_1_) { ItemStack stack = new ItemStack(SimpleItems.MARSHALLOW); stack.setCount(1); return stack; } @Override public boolean canCraftInDimensions(int p_194133_1_, int p_194133_2_) { return true; } @Override public NonNullList<ItemStack> getRemainingItems(CraftingInventory p_179532_1_) { NonNullList<ItemStack> list = NonNullList.withSize(0, ItemStack.EMPTY); list.set(0, PotionUtils.setPotion(new ItemStack(Items.POTION), Potions.EMPTY)); return list; } @Override public IRecipeSerializer<?> getSerializer() { return SERIALIZER; } }

  Reveal hidden contents

{ "type": "tds:crafting_special_marshmallow" }

  Reveal hidden contents

Registry.register(Registry.RECIPE_SERIALIZER, new ResourceLocation("tds", "crafting_special_marshmallow"), Marshmallow.MarshmallowRecipe.SERIALIZER);

 

it seems your problem is solved, but just a tip: when posting code to the forums, use the code block instead of the spoiler, it provides indendation and monospaced fonts which make the code actually readable

  • Thanks 1

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.