I'm trying to make an item that allows the player to fly if it's in their inventory. So far, it works. But flight doesn't disable if the item leave their inventory.
Here's the code:
package com.jeshan.item;
import java.util.List;
import java.util.Random;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityEnderPearl;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
public class JewelofQuetzalcoatl extends Item {
public JewelofQuetzalcoatl()
{
this.maxStackSize = 1;
this.setCreativeTab(CreativeTabs.tabMisc);
this.bFull3D = true;
this.setMaxStackSize(1);
}
@Override
public boolean hasEffect(ItemStack par1ItemStack){
return true;}
@Override
public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
{
par3List.add( "\u00A7b" + "Passive Ability:" + "\u00A7a" + " Ehecatl");
par3List.add("\u00A7a" + "Allows flight while in inventory.");
;
}
@Override
public void onUpdate(ItemStack itemstack, World world, Entity entity, int par4, boolean par5) {
super.onUpdate(itemstack, world, entity, par4, par5);
if (entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) entity;
InventoryPlayer inventory = player.inventory;
if (inventory.hasItem(MainItemClass.JewelofQuetzalcoatl)) {
player.capabilities.allowFlying = true;
}
else if (!inventory.hasItem(MainItemClass.JewelofQuetzalcoatl)) {
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
}
}
}
}
I tried to make an Event in Event Handler that checks if a player has this item, if false (or if they're not in creative mode) , they cannot fly.
This worked, the problem is if you have another mod that adds a flight ring item, this completely overrides that item and makes it useless.
I'm pretty sure the only way would be to make an event handler. What do you mean by "this completely overrides that item and makes it useless"? What is the problem?
the event handler would allow flight only if that item is in their inventory, or if their in creative mode.
Basically, even if you have an Angel Ring from Extra Utilities, you still cant fly if you dont have a jewel.
So you're saying that your event handler is preventing other mods' flight items from functioning? You must find a way to not constantly disable flight for your player on every tick.
I'm trying to make an item that allows the player to fly if it's in their inventory. So far, it works. But flight doesn't disable if the item leave their inventory.
Here's the code:
I tried to make an Event in Event Handler that checks if a player has this item, if false (or if they're not in creative mode) , they cannot fly.
This worked, the problem is if you have another mod that adds a flight ring item, this completely overrides that item and makes it useless.
How can i make this item work properly?
Unity, Individuality, Structure, Order
I'm pretty sure the only way would be to make an event handler. What do you mean by "this completely overrides that item and makes it useless"? What is the problem?
the event handler would allow flight only if that item is in their inventory, or if their in creative mode.
Basically, even if you have an Angel Ring from Extra Utilities, you still cant fly if you dont have a jewel.
Unity, Individuality, Structure, Order
So you're saying that your event handler is preventing other mods' flight items from functioning? You must find a way to not constantly disable flight for your player on every tick.