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

    • Slot Gacor >> Mudah Maxwin Bersama Djarum4D   Slot gacor adalah salah satu jenis permainan judi online yang sangat populer di Indonesia. Bermain slot gacor berarti bermain permainan slot dengan kemungkinan keluaran yang lebih tinggi daripada slot tradisional. Dalam artikel ini, kami akan membahas secara lengkap tentang slot gacor, mulai dari pengertian dasar, cara bermain, strategi pemain, serta aspek keamanan dan etika dalam bermain.
    • DAFTAR & LOGIN TAYO4D   Slot gacor online adalah permainan yang menarik dan menghasilkan keuntungan untuk banyak pemain di seluruh dunia. Dalam artikel ini, kita akan membahas tentang cara memilih dan memainkan slot gacor online terbaik.
    • Tayo4D : Bandar Online Togel Dan Slot Terbesar Di Indonesia     Pemain taruhan Tayo4D yang berkualitas memerlukan platform yang aman, terpercaya, dan mudah digunakan. Dalam era teknologi ini, banyak situs online yang menawarkan layanan taruhan togel 4D, tetapi memilih yang tepat menjadi tuntas. Berikut adalah cara untuk membuat artikel yang membahas tentang situs online terpercaya untuk permainan taruhan togel 4D.  
    • OLXTOTO: Platform Maxwin dan Gacor Terbesar Sepanjang Masa OLXTOTO telah menetapkan standar baru dalam dunia perjudian dengan menjadi platform terbesar untuk pengalaman gaming yang penuh kemenangan dan kegacoran, sepanjang masa. Dengan fokus yang kuat pada menyediakan permainan yang menghadirkan kesenangan tanpa batas dan peluang kemenangan besar, OLXTOTO telah menjadi pilihan utama bagi para pencinta judi berani di Indonesia. Maxwin: Mengejar Kemenangan Terbesar Maxwin bukan sekadar kata-kata kosong di OLXTOTO. Ini adalah konsep yang ditanamkan dalam setiap aspek permainan yang mereka tawarkan. Dari permainan slot yang menghadirkan jackpot besar hingga berbagai opsi permainan togel dengan hadiah fantastis, para pemain dapat memperoleh peluang nyata untuk mencapai kemenangan terbesar dalam setiap taruhan yang mereka lakukan. OLXTOTO tidak hanya menawarkan kesempatan untuk menang, tetapi juga menjadi wadah bagi para pemain untuk meraih impian mereka dalam perjudian yang berani. Gacor: Keberuntungan yang Tak Tertandingi Keberuntungan seringkali menjadi faktor penting dalam perjudian, dan OLXTOTO memahami betul akan hal ini. Dengan berbagai strategi dan analisis yang disediakan, pemain dapat menemukan peluang gacor yang tidak tertandingi dalam setiap taruhan. Dari hasil togel yang tepat hingga putaran slot yang menguntungkan, OLXTOTO memastikan bahwa setiap taruhan memiliki potensi untuk menjadi momen yang mengubah hidup. Inovasi dan Kualitas Tanpa Batas Tidak puas dengan prestasi masa lalu, OLXTOTO terus berinovasi untuk memberikan pengalaman gaming terbaik kepada para pengguna. Dengan menggabungkan teknologi terbaru dengan desain yang ramah pengguna, platform ini menyajikan antarmuka yang mudah digunakan tanpa mengorbankan kualitas. Setiap pembaruan dan peningkatan dilakukan dengan tujuan tunggal: memberikan pengalaman gaming yang tanpa kompromi kepada setiap pengguna. Komitmen Terhadap Kepuasan Pelanggan Di balik kesuksesan OLXTOTO adalah komitmen mereka terhadap kepuasan pelanggan. Tim dukungan pelanggan yang profesional siap membantu para pemain dalam setiap langkah perjalanan gaming mereka. Dari pertanyaan teknis hingga bantuan dengan transaksi keuangan, OLXTOTO selalu siap memberikan pelayanan terbaik kepada para pengguna mereka. Penutup: Mengukir Sejarah dalam Dunia Perjudian Daring OLXTOTO bukan sekadar platform perjudian berani biasa. Ini adalah ikon dalam dunia perjudian daring Indonesia, sebuah destinasi yang menyatukan kemenangan dan keberuntungan dalam satu tempat yang mengasyikkan. Dengan komitmen mereka terhadap kualitas, inovasi, dan kepuasan pelanggan, OLXTOTO terus mengukir sejarah dalam perjudian dunia berani, menjadi nama yang tak terpisahkan dari pengalaman gaming terbaik. Bersiaplah untuk mengalami sensasi kemenangan terbesar dan keberuntungan tak terduga di OLXTOTO - platform maxwin dan gacor terbesar sepanjang masa.
    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
  • Topics

×
×
  • Create New...

Important Information

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