Jump to content

Implementing flying chestplate


Caffe1ne

Recommended Posts

I want to make a chestplate which grants the player an ability to fly upon equip.

@Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack){

        ItemStack tmp;
        boolean chestplateWorn = !(tmp = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST)).isEmpty() && tmp.getItem() == TEST_CHESTPLATE;

        if(chestplateWorn) {
            player.capabilities.allowFlying = true;
        }
        if(!chestplateWorn) {
                player.capabilities.allowFlying = false;
                player.capabilities.isFlying = false;
        }
    }

The adding flight part is fine, but removal is a bit messy. So if i have more than 1 armor piece in this class, player has to have another piece equipped for flight removal upon taking the chestplate off. And having any other setpieces but chestplate equipped disables the flight for items in other mods. If i move all other pieces apart from the chestplate to a different class, the flight removal stops working.But if i add any of the nonchestplace pieces back, it removes the flight. The best thing i can think of is just hardcoding all the equip variants for each piece into removal, but it doesnt seem like the right way.

 

I've tried to adjust the removal check, but sadly it has no effect

boolean helmetWorn = (tmp = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD)).isEmpty() || tmp.getItem() != TEST_HELMET || tmp.getItem() == TEST_HELMET;
boolean leggingsWorn = (tmp = player.getItemStackFromSlot(EntityEquipmentSlot.LEGS)).isEmpty() || tmp.getItem() != TEST_LEGGINGS || tmp.getItem() == TEST_LEGGINGS;
boolean bootstWorn = (tmp = player.getItemStackFromSlot(EntityEquipmentSlot.FEET)).isEmpty() || tmp.getItem() != TEST_BOOTS || tmp.getItem() == TEST_BOOTS;

boolean remove = !chestplateWorn && helmetWorn && leggingsWorn && bootstWorn;

if(remove){
                player.capabilities.allowFlying = false;
                player.capabilities.isFlying = false;
}

 

 

Edited by Caffe1ne
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.