Jump to content

Minecraft Forge 1.7.2 ITickHandler


ProfitOrange

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server like ranking-up, voting, opening crates, event participation, trading with other players, vote party, or mining on the public mining area. - Black Market: A hidden store for trading that operates outside our traditional stores. Here you can find unique trades![/p] Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. 📈 Skills: RPG-style skill system that enhances your gaming experience! 🎮 Leaderboards: Compete and shine! Top players are rewarded weekly! 🏆 Random Teleporter: Travel instantly across different worlds with a click! 🌐 Custom World Generation: Beautifully generated world. 🌍 Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. 🏰 Kits: Unlock ranks and gain access to various kits. 🛠️ Fishing Tournament: Compete in a friendly fishing tournament! 🎣 Chat Games: Enjoy games right within the chat! 🎲 Minions: Get some help from your loyal minions. 👥 Piñata Party: Enjoy a festive party with Piñatas! 🎉 Quests: Over 1000 quests that you can complete! 📜 Bounty Hunter: Set a bounty on a player's head. 💰 Tags: Displayed on nametags, in the tab list, and in chat. 🏷️ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! 🟢 Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. 🔲✨[ Player Warp: Set your own warp points for other players to teleport to. 🌟 Display Shop: Create your own shop and sell to other players! 🛒 Item Skins: Customize your items with unique skins. 🎨 Pets: Your cute loyal companion to follow you wherever you go! 🐾 Cosmetics: Enhance the look of your character with beautiful cosmetics! 💄 XP-Bottle: Store your exp safely in a bottle for later use! 🍶 Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! 📦 Glowing: Stand out from other players with a colorful glow! ✨ Player Particles: Over 100 unique particle effects to show off. 🎇 Portable Inventories: Over virtual inventories with ease. 🧳 And a lot more! Become part of our growing community today! Discord: https://cubehaven.net/discord
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working   I am not familiar with Linux - check for similar/related issues  
    • Create a new instance and start with Embeddium/Oculus and Valkyrien Skies Try different builds of Embeddium/Valkyrien Skies until you find a working combination - then add the rest of your mods one by one or in groups
    • There are some mods missing Missing or unsupported mandatory dependencies: Mod ID: 'octolib', Requested by: 'ramcompat', Expected range: '[0.1,)', Actual version: '[MISSING]' Mod ID: 'forge', Requested by: 'tfc', Expected range: '[47.1.3,47.1.6),[47.1.81,47.2.0),[47.2.6,)', Actual version: '47.2.0' Mod ID: 'relics', Requested by: 'ramcompat', Expected range: '[0.6.5,)', Actual version: '[MISSING]' Add octolib and relics and update tfc to build 47.2.6
    • Make a test with adding LMFT https://www.curseforge.com/minecraft/mc-mods/lmft
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.