Jump to content

Make one item consume another while in the inventory?


opum2

Recommended Posts

Hi there! So, I've been at this for 6-7 hours now. It's driving me crazy! I am trying to figure out a way for one piece of fuel to be consumed by the ring every 5 seconds (In ticks, it's 100 I think) - I've gotten it to consume one at every use, but that's pointless. Then, no one would ever turn it off, as there's no fuel requirement. So I keep changing it and toying with it. Any ideas?

 

Here is my flight ring class:

 

public class FlightRing extends Item implements IFlight {

public IIcon[] icons = new IIcon[2];

public FlightRing()
{

	this.setUnlocalizedName("flightRing");
	this.setTextureName("opumsdongles:flightRing");
	this.setHasSubtypes(true);
	this.setMaxStackSize(1);
	this.setCreativeTab(OpumsDongles.tabOpum);
}

@Override
public boolean onDroppedByPlayer(ItemStack itemStack, EntityPlayer player) 
{
	deactivateRing(itemStack, player);
	return super.onDroppedByPlayer(itemStack, player);
}

@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) 
{
	int ticksInUse = getMaxItemUseDuration(itemStack) - count;

	if (ticksInUse % 120 == 0) 
	{
		if(player.inventory.hasItem(ModItems.opumFuel))
		{
			player.inventory.consumeInventoryItem(ModItems.opumFuel);
		}
	}
}

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) 
{
	if (itemStack.getItemDamage() == 0)
	{
		activateRing(itemStack, player);
		onUsingTick(itemStack, player, /*I have 2 here in the main code, but I don't think that's right*/);
	}
	else
	{
		deactivateRing(itemStack, player);
	}
	return itemStack;
}

@Override
public void activateRing(ItemStack itemStack, EntityPlayer player) 
{
	itemStack.setItemDamage(1);
	player.capabilities.allowFlying = true;
	player.capabilities.isFlying = true;
	player.fallDistance = 0;

	player.sendPlayerAbilities();
}

@Override
public void deactivateRing(ItemStack itemStack, EntityPlayer player) 
{
	itemStack.setItemDamage(0);
	player.capabilities.allowFlying = false;
	player.capabilities.isFlying = false;

	player.sendPlayerAbilities();
}

@Override
public void registerIcons(IIconRegister reg) 
{
    for (int i = 0; i < 2; i ++) 
    {
        this.icons[i] = reg.registerIcon(Info.modID + ":flightRing_" + i);
    }
}

@Override
public IIcon getIconFromDamage(int meta) 
{
    if (meta > 2)
        meta = 0;

    return this.icons[meta];
}

@Override
public void getSubItems(Item item, CreativeTabs tab, List list) 
{
    for (int i = 0; i < 2; i ++) 
    {
        list.add(new ItemStack(item, 1, i));
    }
}

@Override
public String getUnlocalizedName(ItemStack itemStack) 
{
    return this.getUnlocalizedName() + "_" + itemStack.getItemDamage();
}

@Override
public boolean isActive(ItemStack itemStack) 
{
	return itemStack.getItemDamage()==1;
}
}

Link to comment
Share on other sites

You never call onUsingTick from a method that actually gets called every tick.  Like

updateTick()

 

Also, update.  1.7.10 is 2 years old and no longer supported on this forum.  Every 1.7.10 thread is getting locked by diesieben07 or other moderators when found.  We tell you to update because we can only support so many versions. If you want help for a really old version of Minecraft, you aren't going to find it here.

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

Just saw your signature. You're not supporting 1.7?! I'm going to the Minecraft forums... BYYE!

See you later (or not)!

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

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.