Jump to content

[1.10] Consuming Item On A Flight Ring


opum2

Recommended Posts

So I have the a flight ring, and I want it to consume an item, but I don't know much about NBT or what the equivalent to player.inventory.consumeInventoryItem(itemNameHere) is.

 

Here is my code so far, with nothing to consume or check for the item:

 

public class FlightDongle extends Item implements IFlight {

public FlightDongle(String unlocalizedName) 
{
	this.setUnlocalizedName(unlocalizedName);
	this.setCreativeTab(BamsMod.tabBams);
	this.setMaxStackSize(1);
}

@Override
public String getUnlocalizedName(ItemStack itemStack) 
{
	if (itemStack.getItemDamage() == 0) 
	{
		return this.getUnlocalizedName() + ".deactivated";
	}
	if (itemStack.getItemDamage() == 1) 
	{
		return this.getUnlocalizedName() + ".activated";
	}
	return "deactivated";
}

@Override
    public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean bool)
    {
    	list.add("\u00A7f" + "Hold Shift For Details");
    	if((Keyboard.isKeyDown(42)) || (Keyboard.isKeyDown(54)))
    	{
    		list.add("");
    		list.add("\u00A7e" + "Consumes 1 BamSalt Every 2 Minutes.");
    	}
    }

@Override
public void getSubItems(Item item, CreativeTabs tabs, List subItems) 
{
	subItems.add(new ItemStack(item, 1, 0));
	subItems.add(new ItemStack(item, 1, 1));
}

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

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStack, World world, EntityPlayer player, EnumHand hand) 
{
	if (itemStack.getItemDamage() == 0) 
	{
		activateDongle(itemStack, player);
	}
	else
	{
		deactivateDongle(itemStack, player);
	}
	return new ActionResult(EnumActionResult.PASS, itemStack);
}
@Override
public void activateDongle(ItemStack itemStack, EntityPlayer player) 
{
	itemStack.setItemDamage(1);
	player.capabilities.allowFlying = true;
	player.capabilities.isFlying = true;
	player.fallDistance = 0;

	player.sendPlayerAbilities();
}

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

	player.sendPlayerAbilities();
}

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

 

 

Link to comment
Share on other sites

Well...a couple things (all unrelated to your problem) first.

  • Why don't you set the unlocalized name to the registry name?
  • Why do you use "\u00A7f" instead of the EnumChatFormat (EnumTextFormat? I forget the current class name)
  • Why do you use Keyboard.isKeyDown(42)? I'm pretty sure the last bool parameter will do what you want.

 

Now, on to your question:

You don't have an onUpdate method anywhere to even handle the deduction over time.

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

Well...step 1:

You need a way to count time.

Step 2:

When the time reaches a certain value, consume an item from the player's inventory (if it exists)

Step 3:

Reset the timer

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

Would I use some sort of tick handler to count the ticks? Also, I don't know what the equivalent of player.inventory.consumeInventoryItem(itemHere); is in 1.10. I have the onUpdate method and I've casted Entity to EntityPlayer, but don't know what to do from there. As I said, not good at all with NBT, so I'm kinda stuck. Lol

 

I know it's nothing, but it's just to show an example of the variables and stuff. Here is what I have:

@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int i, boolean bool)
{
	EntityPlayer player = (EntityPlayer)entity;


}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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