Jump to content

Recommended Posts

Posted

Hey guys,

 

I am wondering how would I go about making a item not get destroyed or infused with a crafting recipe?

 

For example

 

When making a diamond pickaxe, the diamonds and the sticks are destroyed or 'infused' with each other to make the pickaxe.

 

I want to use hell souls and a purity gem to make a pure soul but I dont want the purity gem destroyed when crafted.

 

This is used in DivineRPG with the dream powder.

 

Thanks :)

STOP CRUCIFYING NEW MODDERS!!!!

Posted

in Item.class there is something like

public ItemStack getContainerItemForItemStack(ItemStack i)

use this to return what you want

I think its my java of the variables.

Posted

in Item.class there is something like

public ItemStack getContainerItemForItemStack(ItemStack i)

use this to return what you want

 

Thanks, I will try it :)

STOP CRUCIFYING NEW MODDERS!!!!

Posted

in Item.class there is something like

public ItemStack getContainerItemForItemStack(ItemStack i)

use this to return what you want

 

what would i return?

STOP CRUCIFYING NEW MODDERS!!!!

Posted

lets say you want to return a glass bottle:

@Override
public ItemStack getContainerItemStack(ItemStack i){
return new ItemStack(Item.glassBottle);
}

I think its my java of the variables.

Posted

lets say you want to return a glass bottle:

@Override
public ItemStack getContainerItemStack(ItemStack i){
return new ItemStack(Item.glassBottle);
}

 

It didnt work :(

package assassinhero.parallelworlds.common.items;

import assassinhero.parallelworlds.ParallelWorldsMain;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class ItemPurityGemItem extends Item{

public ItemPurityGemItem(int par1) {
	super(par1);
	setCreativeTab(CreativeTabs.tabMaterials);

}

public ItemStack getContainerItemForItemStack(ItemStack i){
	return new ItemStack(ParallelWorldsMain.PurityGem);
}

public void updateIcons(IconRegister par1iconregister){
	this.iconIndex = par1iconregister.registerIcon("ParallelWorlds:PurityGem");

}


}

 

Thats my code

 

When i use @Override I get an error

STOP CRUCIFYING NEW MODDERS!!!!

Posted

You could use a crafthandler for it.

 

here is an example:

 

https://github.com/Rikmuld/Camping-Mod/blob/master/common/rikmuld/core/handlers/CraftHandler.java

 

and this would make an item never get destroyed when used in a crafting recipie:

 


        @Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory inv) 

         for(int i=0; i < inv.getSizeInventory(); i++)
        {  		
            if(inv.getStackInSlot(i) != null)
            {
                ItemStack j = inv.getStackInSlot(i);
                if(j.getItem() != null&&j.getItem()==The Item That Shouldn't get destroyed)
                {
                     inv.setInventorySlotContents(i, j);
                }
             }      
        }

 

the itemstack in the method is the item you are crafting, so you also could specify the recipe for when it should not get destroyed.

 

Ps. don't forget to register the crafting handler in you init for if you don't already have an craftHandler.

GameRegistry.registerCraftingHandler(new CraftHandler());

Posted

If all you want to do is return the item without making it take damage add this to the super constructor

 

this.maxStackSize = 1;
this.setContainerItem(this);

 

otherwise if you seek to make it take damage, you will need a crafting handler

Posted

If all you want to do is return the item without making it take damage add this to the super constructor

 

this.maxStackSize = 1;
this.setContainerItem(this);

 

otherwise if you seek to make it take damage, you will need a crafting handler

Works if you don't have subtypes.... which I should have asked if you do in the first place,

If it's your own Item you can do that without having a crafting listener being passed data constantly:

public ItemStack getContainerItemStack(ItemStack i){
	i.setItemDamage(i.getItemDamage()--);
return i;
}

I also forgot to mention that you need to return true in

public boolean hasContainerItem(){}

I think its my java of the variables.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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