Posted June 25, 201411 yr In 1.6.4 I used the ITickHandler to add potion effects, only if the player is currently wearing all the armor. Here is my code that I have tried to implement, yet it throws up an out of bounds array error: public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack){ int hellfire1=0,hellfire2=0,hellfire3=0,hellfire4=0; if (player.getCurrentArmor(4)!=null){ ItemStack helmet=player.getCurrentArmor(4); if(helmet.getItem()==MoShizArmor.HellfireHelmet){ hellfire1=1; } else{ hellfire1=0; } } if (player.getCurrentArmor(3)!=null){ ItemStack chestplate=player.getCurrentArmor(3); if(chestplate.getItem()==MoShizArmor.HellfireChest){ hellfire2=1; } else{ hellfire2=0; } } if (player.getCurrentArmor(2)!=null){ ItemStack leggings=player.getCurrentArmor(2); if(leggings.getItem()==MoShizArmor.HellfireLegs){ hellfire3=1; } else{ hellfire3=0; } } if (player.getCurrentArmor(1)!=null){ ItemStack boots=player.getCurrentArmor(1); if(boots.getItem()==MoShizArmor.HellfireBoots){ hellfire4=1; } else{ hellfire4=0; } } if(hellfire1==1&&hellfire2==1&&hellfire3==1&&hellfire4==1){ player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(),5,0)); } }
June 25, 201411 yr 1. ITickHandler was replaced by TickEvent. Register the events in the FMLCommonHandler.instance().bus(). 2. Why are you using integers as booleans? Also, you could get away with just 1 boolean anyways. 3. Can't help you with the out of bounds array error, you need to post the full class and the crash log. Kain
June 25, 201411 yr Author package com.ProfitOrange.armor; import com.ProfitOrange.moshiz.MoShizArmor; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import net.minecraft.entity.Entity; 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.world.World; public class HellfireArmor extends ItemArmor { public HellfireArmor(ArmorMaterial par2EnumArmorMaterial, int par3, int par4) { super(par2EnumArmorMaterial, par3, par4); } public String getArmorTexture(ItemStack itemstack, Entity entity, int slot, String type) { if (itemstack.getItem() == MoShizArmor.HellfireHelmet || itemstack.getItem() == MoShizArmor.HellfireChest || itemstack.getItem() == MoShizArmor.HellfireBoots) { return "moshiz:textures/model/armor/hellfire_layer_1.png"; }else if (itemstack.getItem() == MoShizArmor.HellfireLegs) { return "moshiz:textures/model/armor/hellfire_layer_2.png"; }else{ return null; } } public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack){ int hellfire1=0,hellfire2=0,hellfire3=0,hellfire4=0; if (player.getCurrentArmor(4)!=null){ ItemStack helmet=player.getCurrentArmor(4); if(helmet.getItem()==MoShizArmor.HellfireHelmet){ hellfire1=1; } else{ hellfire1=0; } } if (player.getCurrentArmor(3)!=null){ ItemStack chestplate=player.getCurrentArmor(3); if(chestplate.getItem()==MoShizArmor.HellfireChest){ hellfire2=1; } else{ hellfire2=0; } } if (player.getCurrentArmor(2)!=null){ ItemStack leggings=player.getCurrentArmor(2); if(leggings.getItem()==MoShizArmor.HellfireLegs){ hellfire3=1; } else{ hellfire3=0; } } if (player.getCurrentArmor(1)!=null){ ItemStack boots=player.getCurrentArmor(1); if(boots.getItem()==MoShizArmor.HellfireBoots){ hellfire4=1; } else{ hellfire4=0; } } if(hellfire1==1&&hellfire2==1&&hellfire3==1&&hellfire4==1){ player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(),5,0)); } } } Sorry for the confusion, I put the method in the armor class, as I saw other people doing it that way. And for the int thing, the code in there I wrote quite awhile ago and I'm not sure what I was thinking then. Here is the crash log: ---- Minecraft Crash Report ---- // I let you down. Sorry Time: 6/25/14 10:52 AM Description: Ticking player java.lang.ArrayIndexOutOfBoundsException: 4 at net.minecraft.entity.player.InventoryPlayer.armorItemInSlot(InventoryPlayer.java:693) at net.minecraft.entity.player.EntityPlayer.getCurrentArmor(EntityPlayer.java:2092) at com.ProfitOrange.armor.HellfireArmor.onArmorTick(HellfireArmor.java:32) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:625) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342) at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:326) 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:232) at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:720) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:608) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at net.minecraft.entity.player.InventoryPlayer.armorItemInSlot(InventoryPlayer.java:693) at net.minecraft.entity.player.EntityPlayer.getCurrentArmor(EntityPlayer.java:2092) at com.ProfitOrange.armor.HellfireArmor.onArmorTick(HellfireArmor.java:32) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:625) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342) -- Player being ticked -- Details: Entity Type: null (net.minecraft.entity.player.EntityPlayerMP) Entity ID: 242 Entity Name: Player733 Entity's Exact location: 104.44, 70.00, 276.30 Entity's Block location: World: (104,70,276), Chunk: (at 8,4,4 in 6,17; contains blocks 96,0,272 to 111,255,287), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511) Entity's Momentum: 0.00, -0.08, 0.00 Stacktrace: at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:341) at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:326) 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:232) -- Ticking connection -- Details: Connection: net.minecraft.network.NetworkManager@7812db78 Stacktrace: at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:720) at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:608) at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:746) -- System Details -- Details: Minecraft Version: 1.7.2 Operating System: Windows 7 (amd64) version 6.1 Java Version: 1.8.0_05, Oracle Corporation Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation Memory: 922030232 bytes (879 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB) JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M AABB Pool Size: 3122 (174832 bytes; 0 MB) allocated, 2863 (160328 bytes; 0 MB) used IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95 FML: MCP v9.03 FML v7.2.211.1121 Minecraft Forge 10.12.2.1121 4 mods loaded, 4 mods active mcp{9.03} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available FML{7.2.211.1121} [Forge Mod Loader] (forgeSrc-1.7.2-10.12.2.1121.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Forge{10.12.2.1121} [Minecraft Forge] (forgeSrc-1.7.2-10.12.2.1121.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Mo' Shiz{1.50} [Mo' Shiz] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available Profiler Position: N/A (disabled) Vec3 Pool Size: 1201 (67256 bytes; 0 MB) allocated, 1187 (66472 bytes; 0 MB) used Player Count: 1 / 8; [EntityPlayerMP['Player733'/242, l='Modded World', x=104.44, y=70.00, z=276.30]] Type: Integrated Server (map_client.txt) Is Modded: Definitely; Client brand changed to 'fml,forge'
June 25, 201411 yr You do NOT need a tick handler to do things while the player is wearing armor. Explore your armor's superclass, it has a method onWornTick.
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.