Jump to content

Custom IRecipe eats items?


drok0920

Recommended Posts

Hello i have tried to use IRecipe to add NBT to an item when it is crafted.  However the output item is never shown and the items i put in as components disappear when i take them out.  Why is this happening?  Am i doing something wrong?

 

package net.drok.poverhaul.recipe;

import net.drok.poverhaul.ModRegistry;
import net.drok.poverhaul.item.ItemRock;
import net.drok.poverhaul.item.ItemStoneCelt;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

public class RecipeStoneCelt extends net.minecraftforge.fml.common.registry.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe {
	
	@Override
	public boolean matches(InventoryCrafting inv, World worldIn) {
		int rocks = 0;
		int sticks = 0;
		int other = 0;
		
		for(int i = 0; i < inv.getSizeInventory(); i++) {
			
			ItemStack stack = inv.getStackInSlot(i);
			int[] ids = OreDictionary.getOreIDs(stack);
			for (int o = 0; o < ids.length; o++) {
				String ore = OreDictionary.getOreName(ids[o]);
				if(stack.getItem() == ModRegistry.items.get("rock")) {
					rocks++;
				}else if(ore.equals("stick")) {
					sticks++;
				} else {
					other++;
				}
			}
		}
		
		if(rocks == 1 && sticks == 1 && other == 0) return true;
		return false;
	}

	@Override
	public ItemStack getCraftingResult(InventoryCrafting inv) {
		ItemStack rockStack = ItemStack.EMPTY;
		
		for(int i = 0; i < inv.getSizeInventory(); i++) {
			if(inv.getStackInSlot(i).getItem() == ModRegistry.items.get("stonecelt")) {
				rockStack = inv.getStackInSlot(i);
				break;
			}
		}
		
		ItemStack celtStack = new ItemStack(ModRegistry.items.get("stonecelt"));
		ItemStoneCelt celt = (ItemStoneCelt) ModRegistry.items.get("stonecelt");
		ItemRock rock = (ItemRock) ModRegistry.items.get("rock");
		
		celt.setQuality(celtStack, rock.getQuality(rockStack));
		
		return celtStack;
	}

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

	@Override
	public ItemStack getRecipeOutput() {
		return new ItemStack(ModRegistry.items.get("stonecelt"));
	}

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

        for (int i = 0; i < nonnulllist.size(); ++i)
        {
            ItemStack itemstack = inv.getStackInSlot(i);

            nonnulllist.set(i, net.minecraftforge.common.ForgeHooks.getContainerItem(itemstack));
        }

        return nonnulllist;
	}
}

 

Link to comment
Share on other sites

Ok, one, your recipes does dick with NBT data. What you've shown here is that the output stack has the same stack size as one of the input stacks.

Two, ModRegistry.items.get() is not a good way to reference your items, it makes your code very stringly typed.

Three, if you're overriding a method do to the same thing as the parent class, don't override (cough, canFit(), cough).

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

First i am dicking with the nbt when i call 

celt.setQuality(celtStack, rock.getQuality(rockStack));

When I do this i am setting an nbt tag called Quality.  Second I dont see why it is bad to use ModRegistry.items.get() as i can get the item based on the registry name and i can register all of the items in one line of code.

Link to comment
Share on other sites

On 2017. 8. 7. at 3:01 AM, drok0920 said:

for (int o = 0; o < ids.length; o++) {

So for every ore ids, you check for the rocks. So it won't work if the rock has no ore id or more than 2 ids.

Also I guess empty itemstack is thought as 'others'...

Plus, when getting the result you look for the last rock slot, while take all of them later. Moreover, I think you remove the result item as well in ::getRemainingItems, but I'm not sure about this part.

Besides, you can use @ObjectHolder.

https://mcforge.readthedocs.io/en/latest/concepts/registries/

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

10 minutes ago, Abastro said:

So for every ore ids, you check for the rocks. So it won't work if the rock has no ore id or more than 2 ids.

Also I guess empty itemstack is thought as 'others'...

Plus, when getting the result you look for the last rock slot, while take all of them later. Moreover, I think you remove the result item as well in ::getRemainingItems, but I'm not sure about this part.

Besides, you can use @ObjectHolder.

https://mcforge.readthedocs.io/en/latest/concepts/registries/

First I only check if the itemstack's item is the same as a rock so the oredictionary for that should not be a problem.  Second I didnt think that an empty itemstack would be a problem but now that you mention it i see that it is.  And third i knew that @ObjectHolder was a thing but doesn't it still need to be registered individually?  I am using the Map because i can just convert it's values to an Array and register them all at once.

Link to comment
Share on other sites

1 minute ago, drok0920 said:

And third i knew that @ObjectHolder was a thing but doesn't it still need to be registered individually?

No, it's annotation magic. All you do is annotate the field (correctly) and everything else happens automagically.

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

4 minutes ago, Draco18s said:

No, it's annotation magic. All you do is annotate the field (correctly) and everything else happens automagically.

So if i just created a public static final field then set it to my item it will automatically registered so long as I annotate it?

Edited by drok0920
Link to comment
Share on other sites

2 minutes ago, drok0920 said:

So if i just created a public static final field then set it to my item it will automatically registered so long as I annotate it?

No.

 

You create a field, you annotate it, you register the item normally.

Then forge sets the value of the field for you.

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

2 minutes ago, Draco18s said:

No.

 

You create a field, you annotate it, you register the item normally.

Then forge sets the value of the field for you.

Ok then i misunderstood.  If you recommended this instead of the Map that i am currently using then it does not fit what i am looking for.  I am looking for a method where i dont have to manually register each Item via

 

 event.getRegistry().register(value);

 

Is there a better way of doing that or is the only proper way to do each one manually.

Link to comment
Share on other sites

2 hours ago, drok0920 said:

Is there a better way of doing that or is the only proper way to do each one manually.

Oh you can use a map or list for that, that's fine. You're just iterating over the entries and registering them. But that isn't what I was saying not to do.

 

I was saying, don't do this: if(stack.getItem() == ModRegistry.items.get("rock")) { ... }

 

THAT is what you shouldn't do. It makes your code rely on strings that if you change ("dur, 'rock' such a dumb name I'm going to change that to 'stone_gniess' instead"), well now you have to search your code manually for every instance of the string "rock" and change it by hand. You can't refactor it by using Source -> Refactor -> Rename.

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

You're already doing it:

stack.getItem() == someItem

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

Use the debugger to find out why.

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

9 minutes ago, drok0920 said:

I figured it out, if the item stack doesnt have an ore dictionary id it never gets to the code that checks if it is a rock.

 

Mm, you don't say.

 

5 hours ago, Abastro said:

So for every ore ids, you check for the rocks. So it won't work if the rock has no ore id

 

  • Like 2

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

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • i need help making a block generate an explosion im new to modding so i dont know how to do it.
    • okay.. ';D i did my good old technique of troubleshooting modpack (disabling ALL the mods and gradually in parts enabbling them and lauching game, enabling more mods, launching e.t.c) and managed to narrow it down to one mod.... it was "better smithing table" causing all the errors and making several mods to spit errors.. Same way by FIRSTLY turning on "better smithing tables" and seeing which mods it clashed with was: "Doggy Tallents Next" "bartering station" "Curios API" And further i wasn't able to check what mods conflicted b'cuz it was like: it was working with X mods, enabled 10 more mods, crashed. procedurally disabled all of them and still was crashing, disabled some more mods, worked. enabled back mods with which it was crashing and now it wasn't  i can't understand why and what mods are bad but i'm happy i somehow got the main error causer which again was "better smithing table". Without that mod everything works just fine. SOLVED (?)
    • So I'm creating yet another minecraft modpack and stumbled upon error I've never encoutered.. I tried to troubleshoot it myself and it always worked but this time I didn't manage.. Here is minecraft crash report: https://pastebin.com/EVqzdDKg I can't find how or from where to post debug.log  I'm sorry, can someone help me? (as a disclaimer - i've tried already reinstalling minecraft and java)
    • It works without mods, I've ran it through the launcher by itself and runs perfectly fine, when I open it through Forge I can get through to the launcher but when I go to open the world it loads then gives me the error code 1. Is there anymore info that could help diagnose it?
    • Also had the issue. GLAD TO TELL YOU I HAVE THE FIX! Create: Applied Kinetic literally says "Replace all inscriber recipes with Create's sequenced assembly recipe". When I turned off this mod it worked fine. I also didn't use that mod of the pack i played so it didn't matter for me.
  • Topics

×
×
  • Create New...

Important Information

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