Jump to content

Item not destroyed while crafting!


AssassinHero

Recommended Posts

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!!!!

Link to comment
Share on other sites

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!!!!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were intended to be used on tutorial posts so that people could easily find tutorials based on their skill level, but instead the tags were abused for unrelated things that made the original intent useless... for example, people often posted crash reports with the "beginner" tag, so instead of finding tutorials for beginners, you got crash reports showing up in searches.
    • The crash says: Exception caught when registering wandering trader java.lang.NullPointerException: Cannot invoke "net.minecraft.world.entity.Entity.m_9236_()" because "entity" is null at com.telepathicgrunt.repurposedstructures.misc.maptrades.StructureSpecificMaps$TreasureMapForEmeralds.m_213663_(StructureSpecificMaps.java:53) ~[repurposed_structures-7.1.15+1.20.1-forge.jar%23708!/:?] at jeresources.collection.TradeList.addMerchantRecipe(TradeList.java:58) ~[JustEnoughResources-1.20.1-1.4.0.247.jar%23630!/:1.4.0.247] JustEnoughResources is mentioned, too Does it work without one of these mods?
    • I have been trying to place a jigsaw structure for about a week now and cant get it to work. I have the template pool etc set up and working it does randomly generate now I just want to place it in the world using a coded trigger. I cant seem to find any useful information on the internet and am completely stuck I think I need to use : JigsawPlacement.generateJigsaw() But I cant get the Holder<StructureTemplatePool>
    • There are more - maybe   watut, whatdurability, playeranimator and vanillafix
    • cen you be a bit more specific pls there are many mods in the log mentioned by name does any error mention it or something couse when i search on   repurposed_structures i dont find anything helpfull cen you tell me which line you say that it might couse the problem?
  • Topics

×
×
  • Create New...

Important Information

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