Jump to content

1.16.4 Crafting with vanilla items


arturkr

Recommended Posts

Dieseben07 already told you what to do..if you want a more specific suggestion, some classes you may find helpful to look at are the SpecialRecipe class and its subclasses. In particular you can see how vanilla uses the getRemainingItems method in BannerDuplicateRecipe and BookCloningRecipe classes

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

10 minutes ago, Beethoven92 said:

Dieseben07 already told you what to do..if you want a more specific suggestion, some classes you may find helpful to look at are the SpecialRecipe class and its subclasses. In particular you can see how vanilla uses the getRemainingItems method in BannerDuplicateRecipe and BookCloningRecipe classes

I don't know where to define getRemainingItems and how to make it "work" later

Link to comment
Share on other sites

5 hours ago, diesieben07 said:

You need a custom crafting recipe implementation and override getRemainingItems.

You override the method getRemainingItems in your custom recipe class.. if you looked at the classes i suggested you you would see exactly how vanilla does that

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

1 hour ago, Beethoven92 said:

You override the method getRemainingItems in your custom recipe class.. if you looked at the classes i suggested you you would see exactly how vanilla does that

Will I need to add a recipe using code and not a json file?

Link to comment
Share on other sites

1 hour ago, Beethoven92 said:

You override the method getRemainingItems in your custom recipe class.. if you looked at the classes i suggested you you would see exactly how vanilla does that

God, how difficult. Why is there no documentation?

public class White_dust extends SpecialRecipe{
	public White_dust(ResourceLocation idIn) {
	      super(idIn);
	   }

	public boolean matches(CraftingInventory inv, World worldIn) {
	      DyeColor dyecolor = null;
	      ItemStack itemstack = null;
	      ItemStack itemstack1 = null;

	      for(int i = 0; i < inv.getSizeInventory(); ++i) {
	         ItemStack itemstack2 = inv.getStackInSlot(i);
	         Item item = itemstack2.getItem();
	         if (item instanceof BannerItem) {
	            BannerItem banneritem = (BannerItem)item;
	            if (dyecolor == null) {
	               dyecolor = banneritem.getColor();
	            } else if (dyecolor != banneritem.getColor()) {
	               return false;
	            }

	            int j = BannerTileEntity.getPatterns(itemstack2);
	            if (j > 6) {
	               return false;
	            }

	            if (j > 0) {
	               if (itemstack != null) {
	                  return false;
	               }

	               itemstack = itemstack2;
	            } else {
	               if (itemstack1 != null) {
	                  return false;
	               }

	               itemstack1 = itemstack2;
	            }
	         }
	      }

	      return itemstack != null && itemstack1 != null;
	   }

	   /**
	    * Returns an Item that is the result of this recipe
	    */
	   public ItemStack getCraftingResult(CraftingInventory inv) {
	      for(int i = 0; i < inv.getSizeInventory(); ++i) {
	         ItemStack itemstack = inv.getStackInSlot(i);
	         if (!itemstack.isEmpty()) {
	            int j = BannerTileEntity.getPatterns(itemstack);
	            if (j > 0 && j <= 6) {
	               ItemStack itemstack1 = itemstack.copy();
	               itemstack1.setCount(1);
	               return itemstack1;
	            }
	         }
	      }

	      return ItemStack.EMPTY;
	   }

	   public NonNullList<ItemStack> getRemainingItems(CraftingInventory inv) {
	      NonNullList<ItemStack> nonnulllist = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

	      for(int i = 0; i < nonnulllist.size(); ++i) {
	         ItemStack itemstack = inv.getStackInSlot(i);
	         if (!itemstack.isEmpty()) {
	            if (itemstack.hasContainerItem()) {
	               nonnulllist.set(i, itemstack.getContainerItem());
	            } else if (itemstack.hasTag() && BannerTileEntity.getPatterns(itemstack) > 0) {
	               ItemStack itemstack1 = itemstack.copy();
	               itemstack1.setCount(1);
	               nonnulllist.set(i, itemstack1);
	            }
	         }
	      }

	      return nonnulllist;
	   }

	   public IRecipeSerializer<?> getSerializer() {
	      return IRecipeSerializer.CRAFTING_SPECIAL_BANNERDUPLICATE;
	   }

	   
	   public boolean canFit(int width, int height) {
	      return width * height >= 2;
	   }
	
}

I just look and do not understand what and why it causes? What are all these methods for? I only figured out "public IRecipeSerializer <?> GetSerializer ()", then it seems that I should return not CRAFTING_SPECIAL_BANNERDUPLICATE, but CRAFTING_SHAPELESS. But I'm not sure about that either

 

Link to comment
Share on other sites

15 minutes ago, arturkr said:

Will I need to add a recipe using code and not a json file?

Depends on the complexity of the recipe. If there is no requirement for dynamic manipulation, you can get away with making a custom recipe with serializer and building a json off of that.

2 minutes ago, arturkr said:

I just look and do not understand what and why it causes? What are all these methods for? I only figured out "public IRecipeSerializer <?> GetSerializer ()", then it seems that I should return not CRAFTING_SPECIAL_BANNERDUPLICATE, but CRAFTING_SHAPELESS. But I'm not sure about that either

You haven't created the recipe serializer. Take a look at ShapedRecipe for that.

Also, every method within IRecipe except for basically two (I'm not counting the getters) has documentation associated with it. The other two gets the items that are supposed to be left over in the inventory using container items while the other gets the recipe ingredients.

Link to comment
Share on other sites

1 minute ago, ChampionAsh5357 said:

Depends on the complexity of the recipe. If there is no requirement for dynamic manipulation, you can get away with making a custom recipe with serializer and building a json off of that.

What is a complex recipe? I have a simple craft on the workbench

Link to comment
Share on other sites

7 minutes ago, arturkr said:

What is a complex recipe? I have a simple craft on the workbench

You have to answer that question yourself. What are you attempting to do in a generic form? I see you trying to keep a specific item in the crafting table and not be used. Is that the only case or does this expand to any item for a specific recipe? These are questions that need to be answered.

Link to comment
Share on other sites

36 minutes ago, ChampionAsh5357 said:

You have to answer that question yourself. What are you attempting to do in a generic form? I see you trying to keep a specific item in the crafting table and not be used. Is that the only case or does this expand to any item for a specific recipe? These are questions that need to be answered.

I'll tell you in detail:

I added three items to the game -

1.pounder

2.Ore

3.milled ore

 

I also made a recipe:

1.bowl

2.Ore

3.pounder

Result:

1.milled ore

The recipe is shapeless.

 

I have implemented functions so that when crafting the pestle is not wasted, but -1 damage. It remains to make sure that the bowl does not disappear.

 

1357791503_.png.3130b0f177e58019d4d74a3fb4709ef8.png

 

382355769_.png.5b33d459e1133ff9ef090d08b85a058f.png

 

 

Link to comment
Share on other sites

13 hours ago, diesieben07 said:

You need an IRecipeSerializer. This is a normal registry entry. Refer to the documentation as for how to register them.

Then in your recipe json file you need to set the type property to the resource location of your serializer. Your serializer will then be called with the JSON of your recipe and needs to return an ICraftingRecipe instance.

WHERE? IN WHICH PLACE? Where does this documentation refer to the IRecipeSerializer? Maybe I'm blind, but I haven't read the worse documentation yet

Link to comment
Share on other sites

1351843699_.thumb.png.7ed05e1df81ea947d8dec01431159cf8.png

Is it real? Only three Google pages? 99.9% of the results are not about what is needed, but 0.1% is the CLICK, and they did not help him...

Really worst help. How are they recruited into the forum team?
It's the same as if you ask "How to put the door?" And I answer "Put the door"

 

 

Edited by arturkr
Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

Dude.

You asked "how to register IRecipeSerializer"? I linked you the documentation that explains you how to register any registry entry.

Yes, but I don't even know where and how to build the "register IRecipeSerializer" correctly

Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

I don't know what you mean by that. Have you even tried following the documentation?

Yes, but the only thing I came up with is this:

public static final RegistryObject<IRecipeSerializer<IRecipe<?>>> WHITE_DUST = IRecipeSerializer.CRAFTING_SHAPELESS.IDK(((;

 

But I understand that this is nonsense

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

You need to start out by making a DeferredRegister instance for it. It works exactly the same as for blocks and items, which you have already done.

This is why I am having a hard time understanding your struggle.

public static final DeferredRegister<IRecipeSerializer<?>> RECIPE = DeferredRegister.create(ForgeRegistries.RECIPE_SERIALIZERS,
            Main.MOD_ID);

public static final RegistryObject<IRecipeSerializer<IRecipe<?>>> WHITE_DUST_RECIPE = RECIPE.register("white_dust_recipe",
            () -> new NEXT IDK

 

Link to comment
Share on other sites

8 minutes ago, diesieben07 said:

You need to implement IRecipeSerializer.

Then?

public class Mortar implements IRecipeSerializer<IRecipe<?>>{

			@Override
			public IRecipeSerializer<?> setRegistryName(ResourceLocation name) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public ResourceLocation getRegistryName() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public Class<IRecipeSerializer<?>> getRegistryType() {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public IRecipe<?> read(ResourceLocation recipeId, JsonObject json) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public IRecipe<?> read(ResourceLocation recipeId, PacketBuffer buffer) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public void write(PacketBuffer buffer, IRecipe<?> recipe) {
				// TODO Auto-generated method stub
				
			}
	
}

 

Link to comment
Share on other sites

Start by making the stubs not-stubs.
You can look at the other recipe implementations for help. Heck, you may even want to extend one of them to make your life easier.

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.

Link to comment
Share on other sites

23 minutes ago, Draco18s said:

Start by making the stubs not-stubs.
You can look at the other recipe implementations for help. Heck, you may even want to extend one of them to make your life easier.

I still don't know what to do (

You speak as if it is very easy.
So if it's easy, just show where and what to write. I will understand how IRecipeSerializer works faster

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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