Jump to content

hasContainerItem and getContainerItem


SuperRuper1209

Recommended Posts

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
Link to comment
Share on other sites

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);

 

Link to comment
Share on other sites

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"))); }

Link to comment
Share on other sites

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
Link to comment
Share on other sites

11 hours ago, SuperRuper1209 said:

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"))); }

"tds" is way too short of a mod ID. Do not use abbreviations.

  • Thanks 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

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