Jump to content

Recommended Posts

  • Replies 59
  • Created
  • Last Reply

Top Posters In This Topic

Posted

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

Posted

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

Posted

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.");

            }

        }

      }

  }

 

 

}

 

Posted

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

Posted

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 :)

Posted

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

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