I'm new to the forum, so just putting this out here, I have experience with Java (and other similar languages), however I'm very new to modding Minecraft, so much so I'm still largely following any tutorials I can find.
However I've hit a block, and I can't seem to figure this out. I'm just trying to get what the player is holding upon right-clicking a block, and then doing something if that item the player is holding matches a specific item.
Here's the method I'm working with as it is now:
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(!worldIn.isRemote)
{
TileEntity tileEntity = worldIn.getTileEntity(pos);
if(tileEntity instanceof TileEntityJar)
{
TileEntityJar jar = (TileEntityJar) tileEntity;
if(playerIn.getActiveItemStack() != null)
{
if(playerIn.getActiveItemStack() == new ItemStack(ModItems.cracker))
{
if(jar.addCracker())
{
int count = playerIn.getActiveItemStack().getCount();
playerIn.getActiveItemStack().setCount(count--);
return true;
}
}
}
jar.removeCracker();
}
}
return true;
}
Alternatively, the tutorial I'm following originally was using this:
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
if(!worldIn.isRemote)
{
TileEntity tileEntity = worldIn.getTileEntity(pos);
if(tileEntity instanceof TileEntityJar)
{
TileEntityJar jar = (TileEntityJar) tileEntity;
if(heldItem != null)
{
if(heldItem.getItem() == ModItems.cracker)
{
if(jar.addCracker())
{
heldItem.stackSize--;
return true;
}
}
}
jar.removeCracker();
}
}
return true;
}
the "heldItem" keyword was something this person put in and it just worked, but for me I only get an error and I can't find any possible thing I did wrong. I don't know if there's an import I'm missing or what. Some help would really be appreciated.