Jump to content

Jetpack allows flying when it shouldn't


DtrollMC

Recommended Posts

Hey all anyway I have this armor set that when worn, would allow the player to creative fly. However, the armor does allow for such things, but when the armor is removed, the player can still fly(on survival). This shouldn't be happening and if any of you can point out to me why I would be grateful.

 

Anyways here is my code:

 

@Override
public void onArmorTickUpdate(World world, EntityPlayer player,
		ItemStack itemStack) {
	if (player.inventory.armorItemInSlot(2) != null) {
		ItemStack itemstack = player.inventory.armorItemInSlot(2);
		if (itemstack.itemID == FuturologyCore.grapheneSuitChest.itemID) {
			player.capabilities.allowFlying = true;
			player.sendPlayerAbilities();
		}else if(itemstack.itemID != FuturologyCore.grapheneSuitChest.itemID){
			player.capabilities.allowFlying = false;
			player.capabilities.isFlying = false;
		}
	}

Link to comment
Share on other sites

if (player.inventory.armorItemInSlot(2) != null) {
		ItemStack itemstack = player.inventory.armorItemInSlot(2);
		if (itemstack.itemID == FuturologyCore.grapheneSuitChest.itemID) {
			player.capabilities.allowFlying = true;
			player.sendPlayerAbilities();
		}else if(itemstack.itemID != FuturologyCore.grapheneSuitChest.itemID){
			player.capabilities.allowFlying = false;
			player.capabilities.isFlying = false;
		}
	}
else
{
//case where player doesn't have any armor
}

Link to comment
Share on other sites

Oops, seems like onArmorTickUpdate(args) is only called on client side when the item is in the slot.

Your code was really misleading.  :P

So, this else case would never be reached and your code would be better as:

 

@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
		if (itemStack.itemID == FuturologyCore.grapheneSuitChest.itemID) {
			player.capabilities.allowFlying = true;
			player.sendPlayerAbilities();
		}else if(itemStack.itemID != FuturologyCore.grapheneSuitChest.itemID){
			player.capabilities.allowFlying = false;
			player.capabilities.isFlying = false;
		}
	}

You'll need a TickHandler to reset the values.

Link to comment
Share on other sites

Okay could you perhaps elaborate a bit? What would i need in the methods of the TickHandler class(I assume it implements ITickHandler) and do I keep my onArmorTickUpdate in the Item class or the tick class, and how would I link these classes together?

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.