i know i know.... sad right? a level 48 modder and asking for help. shameful. but i have been working on this for a little while and i am totally stumped. i have gotten another item to work like bonemeal, but i am trying to make it unlimited. like, one of the items works for an infinite number of times. thanks in advance! this is the code that i already have.
PS. it already works like bonemeal
solved!
thanks!
Click to reveal
package net.minecraft.item;
import net.minecraft.block.Block;
import net.minecraft.block.BlockCocoa;
import net.minecraft.block.BlockCrops;
import net.minecraft.block.BlockDirectional;
import net.minecraft.block.BlockLog;
import net.minecraft.block.BlockMushroom;
import net.minecraft.block.BlockSapling;
import net.minecraft.block.BlockStem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.FakePlayerFactory;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event.Result;
import net.minecraftforge.event.entity.player.BonemealEvent;
public class ItemEarthCrystal extends Item
{
public ItemEarthCrystal(int par1)
{
super(par1);
}
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
if (!par2EntityPlayer.canPlayerEdit(par4, par5, par6, par7, par1ItemStack))
{
return false;
}
else
{
if (par1ItemStack.getItemDamage() == 0)
{
if (applyBonemeal(par1ItemStack, par3World, par4, par5, par6, par2EntityPlayer))
{
if (!par3World.isRemote)
{
par3World.playAuxSFX(2005, par4, par5, par6, 0);
}
return true;
}
}
else if (par1ItemStack.getItemDamage() == 3)
{
int i1 = par3World.getBlockId(par4, par5, par6);
int j1 = par3World.getBlockMetadata(par4, par5, par6);
if (i1 == Block.wood.blockID && BlockLog.limitToValidMetadata(j1) == 3)
{
if (par7 == 0)
{
return true;
}
if (par7 == 1)
{
return false;
}
if (par7 == 2)
{
return true;
}
if (par7 == 3)
{
return true;
}
if (par7 == 4)
{
return true;
}
if (par7 == 5)
{
return true;
}
if (par3World.isAirBlock(par4, par5, par6))
{
int k1 = Block.blocksList[Block.cocoaPlant.blockID].onBlockPlaced(par3World, par4, par5, par6, par7, par8, par9, par10, 0);
par3World.setBlock(par4, par5, par6, Block.cocoaPlant.blockID, k1, 2);
}
return true;
}
}
return false;
}
}
public static boolean applyBonemeal(ItemStack par0ItemStack, World par1World, int par2, int par3, int par4, EntityPlayer player)
{
int l = par1World.getBlockId(par2, par3, par4);
BonemealEvent event = new BonemealEvent(player, par1World, l, par2, par3, par4);
if (MinecraftForge.EVENT_BUS.post(event))
{
return false;
}
if (event.getResult() == Result.ALLOW)
{
if (!par1World.isRemote)
{
par0ItemStack.stackSize--;
}
return true;
}
if (l == Block.sapling.blockID)
{
if (!par1World.isRemote)
{
if ((double)par1World.rand.nextFloat() < 100D)
{
((BlockSapling)Block.sapling).markOrGrowMarked(par1World, par2, par3, par4, par1World.rand);
}
--par0ItemStack.stackSize;
}
return true;
}
else if (l != Block.mushroomBrown.blockID && l != Block.mushroomRed.blockID)
{
if (l != Block.melonStem.blockID && l != Block.pumpkinStem.blockID)
{
if (l > 0 && Block.blocksList[l] instanceof BlockCrops)
{
if (par1World.getBlockMetadata(par2, par3, par4) == 7)
{
return false;
}
else
{
if (!par1World.isRemote)
{
((BlockCrops)Block.blocksList[l]).fertilize(par1World, par2, par3, par4);
--par0ItemStack.stackSize;
}
return true;
}
}
else
{
int i1;
int j1;
int k1;
if (l == Block.cocoaPlant.blockID)
{
i1 = par1World.getBlockMetadata(par2, par3, par4);
j1 = BlockDirectional.getDirection(i1);
k1 = BlockCocoa.func_72219_c(i1);
if (k1 >= 2)
{
return false;
}
else
{
if (!par1World.isRemote)
{
++k1;
par1World.setBlockMetadataWithNotify(par2, par3, par4, k1 << 2 | j1, 2);
--par0ItemStack.stackSize;
}
return true;
}
}
else if (l != Block.grass.blockID)
{
return false;
}
else
{
if (!par1World.isRemote)
{
--par0ItemStack.stackSize;
label102:
for (i1 = 0; i1 <128 ; ++i1)
{
j1 = par2;
k1 = par3 + 1;
int l1 = par4;
for (int i2 = 0; i2 < i1 / 16; ++i2)
{
j1 += itemRand.nextInt(3) - 1;
k1 += (itemRand.nextInt(3) - 1) * itemRand.nextInt(3) / 2;
l1 += itemRand.nextInt(3) - 1;
if (par1World.getBlockId(j1, k1 - 1, l1) != Block.grass.blockID || par1World.isBlockNormalCube(j1, k1, l1))
{
continue label102;
}
}
if (par1World.getBlockId(j1, k1, l1) == 0)
{
if (itemRand.nextInt(10) != 0)
{
if (Block.tallGrass.canBlockStay(par1World, j1, k1, l1))
{
par1World.setBlock(j1, k1, l1, Block.tallGrass.blockID, 1, 3);
}
}
else
{
ForgeHooks.plantGrass(par1World, j1, k1, l1);
}
}
}
}
return true;
}
}
}
else if (par1World.getBlockMetadata(par2, par3, par4) == 7)
{
return false;
}
else
{
if (!par1World.isRemote)
{
((BlockStem)Block.blocksList[l]).fertilizeStem(par1World, par2, par3, par4);
--par0ItemStack.stackSize;
}
return true;
}
}
else
{
if (!par1World.isRemote)
{
if ((double)par1World.rand.nextFloat() < 0.4D)
{
((BlockMushroom)Block.blocksList[l]).fertilizeMushroom(par1World, par2, par3, par4, par1World.rand);
}
--par0ItemStack.stackSize;
}
return true;
}
}
public boolean isItemTool(ItemStack par1ItemStack)
{
return par1ItemStack.stackSize == 1;
}
}
PS. it already works like bonemeal
solved!
thanks!
17
just go into some sort of file where it consumes the item and add a boolean for the item
like if there is a universal file for consumption of items, or whatnot
no there isnt..........
im trying to make an item like bonemeal, but never goes away or gets damage
ahh that sucks
anyone?
I made armor that applies bone meal every tick when you're wearing it, so I went through something similar to this. I figured out that all you have to have is this inside your onItemUse():
This should work like you want it to(sorry for the bad formatting/indentation), but I can't be 100% sure. I hate it when you spend hours trying to figure code out and the solution is as simple as this...
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
ItemDye.applyBonemeal(par1ItemStack, par3World, par4, par5, par6, par3EntityPlayer);
return true;
}
This should work like you want it to(sorry for the bad formatting/indentation), but I can't be 100% sure. I hate it when you spend hours trying to figure code out and the solution is as simple as this...
lol bro now it takes 2 of the item away, i want it to take 0 away
wait.... what the heck? it takes two away unless i only have one. thanks bro it works perfectly! now i can move along with the mod!
but it dissapears when i hit an enemy with it?
Hmm. If the method I gave you is the only thing you have for onItemUse() (but I made a typo, replace par3EntityPlayer in the ItemDye.applyBoneMeal with par2EntityPlayer), then It should work... I just tried it with one of my items.
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
ItemDye.applyBonemeal(par1ItemStack, par3World, par4, par5, par6, par2EntityPlayer);
return true;
}ok thats the only thing i have in there but it still takes one away D:
i got it! yeay!!!
Because nobody else really seems to be able to help, here's technically what you asked for.
These two lines are the ones that are removing 1 from the stack in your held item:
par0ItemStack is the first parameter of the function, and is a reference to an ItemStack (in the case of using the item, it's the item in your hand generally) - stackSize is, as its namesake implies, the size of the stack. The -- operator removes one (it is equivilent to n = n - 1); it can be applied on either side of a variable, however, to either apply the operation after or before others (postfix operator, for instance, would remove one before returning it down the chain).
They both do the same thing (remove one), although they used two different methods of performing the same task in a place where it wouldn't matter. Removing those lines would effectively make it never take any away.
-P
These two lines are the ones that are removing 1 from the stack in your held item:
par0ItemStack.stackSize--;
--par0ItemStack.stackSize;
par0ItemStack is the first parameter of the function, and is a reference to an ItemStack (in the case of using the item, it's the item in your hand generally) - stackSize is, as its namesake implies, the size of the stack. The -- operator removes one (it is equivilent to n = n - 1); it can be applied on either side of a variable, however, to either apply the operation after or before others (postfix operator, for instance, would remove one before returning it down the chain).
They both do the same thing (remove one), although they used two different methods of performing the same task in a place where it wouldn't matter. Removing those lines would effectively make it never take any away.
-P
ParilBecause nobody else really seems to be able to help, here's technically what you asked for.
These two lines are the ones that are removing 1 from the stack in your held item:par0ItemStack.stackSize--;--par0ItemStack.stackSize;
par0ItemStack is the first parameter of the function, and is a reference to an ItemStack (in the case of using the item, it's the item in your hand generally) - stackSize is, as its namesake implies, the size of the stack. The -- operator removes one (it is equivilent to n = n - 1); it can be applied on either side of a variable, however, to either apply the operation after or before others (postfix operator, for instance, would remove one before returning it down the chain).
They both do the same thing (remove one), although they used two different methods of performing the same task in a place where it wouldn't matter. Removing those lines would effectively make it never take any away.
-P
thanks a ton P. and everyone else that tried to help
My mind doesnt understand code but i do have one suggestion. Google it
It can be hard to Google stuff when you don't know where the error is - especially when you have 100s of lines of code.
