Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

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.

  • Author

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.