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.

Featured Replies

  • Replies 59
  • Views 19.5k
  • Created
  • Last Reply

Top Posters In This Topic

Ok thats a bit of a mess... Try this i think i fixed the null pointer and may have figured out why it isnt working.

 

package com.skullcrusher.BetterThings.eventhandlers;

import java.util.Map;
import java.util.WeakHashMap;

import com.skullcrusher.BetterThings.BetterThings;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class ArmorEventHandler {
   public static Map<EntityPlayer, Boolean> playersWithFlight = new WeakHashMap<EntityPlayer, Boolean>();

   @SubscribeEvent
   public void onEntityUpdate(PlayerTickEvent event) {
           if (event.phase != TickEvent.Phase.START || event.player.worldObj.isRemote) return;
         
            System.out.println("Equipment Stack "+event.player.getEquipmentInSlot(3));
           if (event.player.getEquipmentInSlot(3) != null) System.out.println("Item "+event.player.getEquipmentInSlot(3).getItem());
           System.out.println("Target Item "+BetterThings.GravityChestplate);

           System.out.println(event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == BetterThings.GravityChestplate);


           if (event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == BetterThings.GravityChestplate) {
         
         playersWithFlight.put(event.player, true);
         event.player.capabilities.allowFlying = true;

      } else {

         if (!playersWithFlight.containsKey(event.player)) {
            playersWithFlight.put(event.player, false);
              }

         if (playersWithFlight.get(event.player)) {
            playersWithFlight.put(event.player, false);

            if (!event.player.capabilities.isCreativeMode) {
               event.player.capabilities.allowFlying = false;
               event.player.capabilities.isFlying = false;
               event.player.sendPlayerAbilities();
            }
         }
      }
   }


}

 

Ok it worked as we planned

When it was on:

Equipment Stack 1xitem.GravityChestplate@0

Item com.skullcrusher.BetterThings.Armor.GravityArmor@4aa33ead

Target Item com.skullcrusher.BetterThings.Armor.GravityArmor@4aa33ead

true

When it was off:

Equipment Stack null

Target Item com.skullcrusher.BetterThings.Armor.GravityArmor@4aa33ead

false

 

did you copy just the changes or the entire class?

I am the author of Draconic Evolution

OOOh change

if (event.phase != TickEvent.Phase.START || event.player.worldObj.isRemote) return;

to

if (event.phase != TickEvent.Phase.START || !event.player.worldObj.isRemote) return;

and that should do the trick.

 

Edit infact remove the isRemote altogether

if (event.phase != TickEvent.Phase.START) return;

I am the author of Draconic Evolution

  • Author

Hmmm.... try putting printlns in both sides of the main if statement (the one that sets weather or not the player can fly) and see which one is called

When I was wearing it, It printed "Play is allowed to fly" but when I wasn't it wasn't printing anything but "Equipment Stack null

Target Item com.skullcrusher.BetterThings.Armor.GravityArmor@68303e5

false"

 

Code If I put the last print statement in the wrong spot

 

package com.skullcrusher.BetterThings.eventhandlers;

 

import java.util.Map;

import java.util.WeakHashMap;

 

import com.skullcrusher.BetterThings.BetterThings;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;

import cpw.mods.fml.common.gameevent.TickEvent;

import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

 

public class ArmorEventHandler {

  public static Map<EntityPlayer, Boolean> playersWithFlight = new WeakHashMap<EntityPlayer, Boolean>();

 

  @SubscribeEvent

  public void onEntityUpdate(PlayerTickEvent event) {

          if (event.phase != TickEvent.Phase.START || event.player.worldObj.isRemote) return;

       

            System.out.println("Equipment Stack "+event.player.getEquipmentInSlot(3));

          if (event.player.getEquipmentInSlot(3) != null) System.out.println("Item "+event.player.getEquipmentInSlot(3).getItem());

          System.out.println("Target Item "+BetterThings.GravityChestplate);

 

          System.out.println(event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == BetterThings.GravityChestplate);

 

 

          if (event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == BetterThings.GravityChestplate) {

       

        playersWithFlight.put(event.player, true);

        event.player.capabilities.allowFlying = true;

        System.out.println("Allowed Player to fly.");

      } else {

 

        if (!playersWithFlight.containsKey(event.player)) {

            playersWithFlight.put(event.player, false);

              }

 

        if (playersWithFlight.get(event.player)) {

            playersWithFlight.put(event.player, false);

 

            if (!event.player.capabilities.isCreativeMode) {

              event.player.capabilities.allowFlying = false;

              event.player.capabilities.isFlying = false;

              event.player.sendPlayerAbilities();

              System.out.println("Player is not allowed to fly.");

            }

        }

      }

  }

 

 

}

 

  • Author

OOOh change

if (event.phase != TickEvent.Phase.START || event.player.worldObj.isRemote) return;

to

if (event.phase != TickEvent.Phase.START || !event.player.worldObj.isRemote) return;

and that should do the trick.

Yes! it worked! :D Thank you so much!!!!! Putting you in the credits of my mod. Also 1+ karma to you :D

  • Author

Your most welcome!

Infact i think you should remove the isRemote altogether

I removed it and it didn't calculate fall damage after I took the gravity chestplate off midair. So I left it there and it calculates fall damage just fine :)

Oh i see its in the wrong spot it should be here

if (playersWithFlight.get(player) && !player.worldObj.isRemote) { //<---
playersWithFlight.put(player, false);

if (!player.capabilities.isCreativeMode) {
	player.capabilities.allowFlying = false;
	player.capabilities.isFlying = false;
	player.sendPlayerAbilities();
}
}

But if its working for you it probably dosnt matter.

I am the author of Draconic Evolution

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.