Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.2][Solved] Can still fly when gravity chestplate is off


skullcrusher1005
 Share

Recommended Posts

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

oops remove .getItem() from the first System.out so

System.out.println("Equipment Stack "+getEquipmentInSlot(3));
if (event.player.getEquipmentInSlot(3) != null) System.out.println("Item "+event.player.getEquipmentInSlot(3).getItem());
System.out.println("Target Item"+BetterThings.GravityChestplate);
if (event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == BetterThings.GravityChestplate)

and make sure you are wearing the chestplate it crashed because it tried to get the item from the stack in your chestplate slot but that stack was null.

Heres the code for the armor event handler

 

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 "+getEquipmentInSlot(3).getItem());

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

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

        if (event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == 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)

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

String ownerName = event.player.getDisplayName();

playersWithFlight.put(event.player, true);

event.player.capabilities.allowFlying = true;

 

} else {

String ownerName = event.player.getDisplayName();

 

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();

}

}

}

}

 

 

}

 

 

Link to comment
Share on other sites

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();
            }
         }
      }
   }


}

 

I am the author of Draconic Evolution

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

i think i see the problem can you please show me your moditems class (where you have you instance of GravityChestplate)

This is the whole gravity armor class

 

 

package com.skullcrusher.BetterThings.Armor;

 

import java.util.List;

import java.util.Map;

import java.util.WeakHashMap;

 

import net.minecraft.entity.Entity;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemArmor;

import net.minecraft.item.ItemStack;

import net.minecraft.potion.Potion;

import net.minecraft.potion.PotionEffect;

import net.minecraft.util.DamageSource;

import net.minecraft.util.EnumChatFormatting;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

import net.minecraftforge.common.ISpecialArmor.ArmorProperties;

 

import com.skullcrusher.BetterThings.BetterThings;

 

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

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

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

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

 

public class GravityArmor extends ItemArmor

{

public GravityArmor(ArmorMaterial armormaterial, int renderID, int partID)

{

super(armormaterial, renderID, partID);

}

 

public String getArmorTexture(ItemStack itemstack, Entity entity, int slot, String layer)

{

if((itemstack.getItem() == BetterThings.GravityChestplate))

{

return "betterthings:textures/models/armor/8_layer_1.png";

}

else return null;

}

 

@SideOnly(Side.CLIENT)

public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4)

{

list.add(EnumChatFormatting.DARK_BLUE + "Indestructible");

}

}

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

            }

        }

      }

  }

 

 

}

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.