I have created boots that allow the player to fly, and I want the flight to stop when the armor is taken off, but I'm having an issue where I can still fly with no armor on...
First of all, would I be right in assuming that you've declared your event handler somewhere? (it's just not in the main file, soooo...)
Anyway, why bother with the armor tick in the second part of the code? I'd suggest removing it entirely and seeing if that solves the problem (note that it is redundant, since the living update event takes care of the flying stuff). I wouldn't have thought it would be the problem, but you know; MC is funny and the armor tick could easily be doing something bizarre and firing the last armor tick after the armor has been removed, or something...
Anyway, because I'm OCD about things like this, there are a few tricks you can use in Java. First, null test isn't necessary with instanceof. Second, you can directly set a boolean value to the result of a logical test (redundant case switch).
//No need for null test => just use instanceof (since null isn't an instance of anything)
if (!(event.entityLiving instanceof EntityPlayer)) return;
EntityPlayer player = (EntityPlayer) event.entity;
//Now you can just set the flying in one line
player.capabilities.allowFlying = player.capabilities.isCreativeMode ||
(player.inventory.armorItemInSlot(3) != null
&& player.inventory.armorItemInSlot(3).getItem() == HoverBoots.hoverboots);
If you remove the armor tick stuff, and the player can still fly, then the problem lies somewhere else entirely.
Rollback Post to RevisionRollBack
I believe in the Invisible Pink Unicorn, bless her Invisible Pinkness.
First of all, would I be right in assuming that you've declared your event handler somewhere? (it's just not in the main file, soooo...)
Anyway, why bother with the armor tick in the second part of the code? I'd suggest removing it entirely and seeing if that solves the problem (note that it is redundant, since the living update event takes care of the flying stuff). I wouldn't have thought it would be the problem, but you know; MC is funny and the armor tick could easily be doing something bizarre and firing the last armor tick after the armor has been removed, or something...
Anyway, because I'm OCD about things like this, there are a few tricks you can use in Java. First, null test isn't necessary with instanceof. Second, you can directly set a boolean value to the result of a logical test (redundant case switch).
//No need for null test => just use instanceof (since null isn't an instance of anything)
if (!(event.entityLiving instanceof EntityPlayer)) return;
EntityPlayer player = (EntityPlayer) event.entity;
//Now you can just set the flying in one line
player.capabilities.allowFlying = player.capabilities.isCreativeMode ||
(player.inventory.armorItemInSlot(3) != null
&& player.inventory.armorItemInSlot(3).getItem() == HoverBoots.hoverboots);
If you remove the armor tick stuff, and the player can still fly, then the problem lies somewhere else entirely.
Every time I add a TickHandler it crashes Here is my code
e com.jonessc6.hoverboots.core.proxys;import net.minecraft.client.Minecraft;
import com.jonessc6.hoverboots.core.handler.HoverEventHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
public class ClientProxy extends CommonProxy{
public int addArmor(String armor){
Where's the tick handler? Usually when something crashes and you don't know why, you share the crash log and the code relevant to where it crashed - dumping your whole mod code and making us slog through it is painful.
Where's the tick handler? Usually when something crashes and you don't know why, you share the crash log and the code relevant to where it crashed - dumping your whole mod code and making us slog through it is painful.
One thing I'm asking is to use a EventHandler or TickHandler im using and EventHandler now and this is my crash log
java.lang.NullPointerException: Ticking player
at com.jonessc6.hoverboots.core.handler.HoverEventHandler.onLivingUpdateEvent(HoverEventHandler.java:20)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_5_HoverEventHandler_onLivingUpdateEvent_LivingUpdateEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:276)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1775)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:334)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at com.jonessc6.hoverboots.core.handler.HoverEventHandler.onLivingUpdateEvent(HoverEventHandler.java:20)
at cpw.mods.fml.common.eventhandler.ASMEventHandler_5_HoverEventHandler_onLivingUpdateEvent_LivingUpdateEvent.invoke(.dynamic)
at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51)
at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122)
at net.minecraftforge.common.ForgeHooks.onLivingUpdate(ForgeHooks.java:276)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1775)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
-- Player being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 83
Entity Name: ForgeDevName
Entity's Exact location: -121.52, 64.00, -55.48
Entity's Block location: World: (-122,64,-56), Chunk: (at 6,4,8 in -8,-4; contains blocks -128,0,-64 to -113,255,-49), Region: (-1,-1; contains chunks -32,-32 to -1,-1, blocks -512,0,-512 to -1,255,-1)
Entity's Momentum: 0.00, -0.08, 0.00
Stacktrace:
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:334)
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329)
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37)
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247)
-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@3c55e637
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8 (amd64) version 6.2
Java Version: 1.7.0_51, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 949755760 bytes (905 MB) / 1056309248 bytes (1007 MB) up to 1056309248 bytes (1007 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.05 FML v7.10.18.1180 Minecraft Forge 10.13.0.1180 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.18.1180} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.0.1180} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1180.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
hoverboots{0.1.0.0} [Hover Boots] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['ForgeDevName'/83, l='New World', x=-121.52, y=64.00, z=-55.48]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
player.inventory.armorItemInSlot(3) may be null, in which case you crash when you try to call (null).getItem(). The solution is, of course, to check for null before you try to call any methods on it.
player.inventory.armorItemInSlot(3) may be null, in which case you crash when you try to call (null).getItem(). The solution is, of course, to check for null before you try to call any methods on it.
Have you tried searching for 'armor fly' or 'flight' and such things here in the Modification Development section? There are already several topics that discuss the solution in a fair amount of detail, and you'll probably even find full code solutions.
Here is my source
Main File:
Armor File
Anyway, why bother with the armor tick in the second part of the code? I'd suggest removing it entirely and seeing if that solves the problem (note that it is redundant, since the living update event takes care of the flying stuff). I wouldn't have thought it would be the problem, but you know; MC is funny and the armor tick could easily be doing something bizarre and firing the last armor tick after the armor has been removed, or something...
Anyway, because I'm OCD about things like this, there are a few tricks you can use in Java. First, null test isn't necessary with instanceof. Second, you can directly set a boolean value to the result of a logical test (redundant case switch).
If you remove the armor tick stuff, and the player can still fly, then the problem lies somewhere else entirely.
I believe in the Invisible Pink Unicorn, bless her Invisible Pinkness.
Every time I add a TickHandler it crashes Here is my code
Main:
Item Class:
EventHandler:
CommonProxy:
ClientProxy:
One thing I'm asking is to use a EventHandler or TickHandler im using and EventHandler now and this is my crash log
This is my line 20
Well I don't crash now, but I can't fly....