Jump to content

[1.7.10] NetBeans not recognizing "player.capabilities.allowFlight" [Solved]


Recommended Posts

Posted

I've got an enchantment that is supposed to allow a player to have creative flight. I've got the program to register the enchantment already, got it specified for what it can be applied to and all that.

 

All that works, and what's below is the bits that are supposed to check the armor for the enchantment and allow the player to have flight. Problem is, NetBeans refuses to realize the "player" part of "player.capabilities.allowFlight" as a package. I've got the proper import for this (I believe, I spent a lot of time looking at similar code), and this statement should be legal, so I have no idea what's going on here. Is this actually the correct way to do this? This statement is the only way I've seen it done.

 

And a secondary question: Overall, is this code structure an efficient way to do this? I didn't see any "onEquip" events in the lists I've read.

 

package com.exo594.tutorial.enchantment;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.entity.player.EntityPlayer;      //<<<NetBeans claims this import is unused<<<

public class ModEnchantments {

    public static Enchantment addFlight;
    public static int ADDFLIGHT_ID = 100;
    public static boolean hasAddFlight = false;
    

    public static void init() {

        addFlight = new EnchantmentAddFlight();
        Enchantment.addToBookList(addFlight);
    }

    @SubscribeEvent
    private void tickEvent(PlayerTickEvent evt) {
        Item chestplate = null;
        ItemStack stackChestplate = evt.player.inventory.armorItemInSlot(2);
        if (stackChestplate != null) {
            chestplate = stackChestplate.getItem();
        }

        if (stackChestplate.stackTagCompound != null) {
            if (stackChestplate.stackTagCompound.getTag("ench") != null) {
                NBTTagList enchants = (NBTTagList) stackChestplate.stackTagCompound.getTag("ench");
                for (int i = 0; i < enchants.tagCount(); i++) {
                    NBTTagCompound enchant = ((NBTTagList) enchants)
                            .getCompoundTagAt(i);
                    if (enchant.getInteger("id") == 100) {
                        hasAddFlight = true;
                        player.capabilities.allowFlying = true;     //<<<NetBeans does't like this line here, tooltip says "package player does not exist" <<<
                        break;
                    }
                }
            }
        }
    }
}

 

And yes, I am aware I need a tick handler in my proxies.

Posted

Thank you. After swapping the "tickEvent" for onArmorTick, it's working properly and appropriately. Now, I just need to remove creative flight with the removal of armor, but I can certainly handle that.

 

I'm back using tickEvents, but I passed "EntityPlayer player" inside the "private void tickEvent(PlayerTickEvent evt)", which seems to have solved the original issue. Using onArmorTick wasn't working properly, I ran into a few issues shortly after posting.

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.