Jump to content

[SOLVED]Armor detecting entities within a radius crashing


The_Fireplace

Recommended Posts

Ok, so I'm working on armor that can detect players within a variable radius(which is set earlier in the void), then interacting with them. Here is my code for it:

 

package the_fireplace.unlogic.armor;

import java.util.List;

import the_fireplace.unlogic.unbase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class IceArmor extends ItemArmor {

public IceArmor(ArmorMaterial p_i45325_1_, int p_i45325_2_, int p_i45325_3_) {
	super(p_i45325_1_, p_i45325_2_, p_i45325_3_);
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
	if(stack.getItem() == unbase.FireHelmet || stack.getItem() == unbase.FireChestplate || stack.getItem() == unbase.FireBoots) {
		return "unlogic:textures/models/armor/ice1.png";
	}
	if(stack.getItem() == unbase.FireLeggings) {
		return "unlogic:textures/models/armor/ice2.png";
	}
	return null;
}
private static int expansionLevel = 0;
@Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
	ItemStack helmet = player.getCurrentArmor(3);
	ItemStack plate = player.getCurrentArmor(2);
	ItemStack legs = player.getCurrentArmor(1);
	ItemStack boots = player.getCurrentArmor(0); 
	boolean helmetworn = false; 
	boolean plateworn = false; 
	boolean legsworn = false; 
	boolean bootsworn = false;
	if(helmet != null){
		if(helmet.getItem() == unbase.IceHelmet){
			helmetworn = true;
		}
	}
	if(plate != null){
		if(plate.getItem() == unbase.IceChestplate){
			plateworn = true;
		}
	}
	if(legs != null){
		if(legs.getItem() == unbase.IceLeggings){
			legsworn = true;
		}
	}
	if(boots != null){
		if(boots.getItem() == unbase.IceBoots){
			bootsworn = true;
		}
	}
	if((helmetworn || plateworn || legsworn || bootsworn) == true){
		expansionLevel = 2;
		if(((helmetworn || plateworn || legsworn || bootsworn) && (helmetworn || plateworn || legsworn || bootsworn)) == true){//May not work, because if 2 of the same boolean are true, it may not be smart enough to know otherwise
			expansionLevel = 3;
			if(((helmetworn || plateworn || legsworn || bootsworn) && (helmetworn || plateworn || legsworn || bootsworn) && (helmetworn || plateworn || legsworn || bootsworn)) == true){//May not work, because if 2 of the same boolean are true, it may not be smart enough to know otherwise
				expansionLevel = 4;
				if(helmetworn && plateworn && legsworn && bootsworn){
					expansionLevel = 5;
				}
			}
		}
	}
	List players = world.getEntitiesWithinAABB(EntityPlayer.class, player.getBoundingBox().expand(expansionLevel, expansionLevel, expansionLevel));
	System.out.println("These are within range:" + players);
}
}

 

Upon equipping a piece of the armor, it crashes, and the report points me to the following line of code:

List players = world.getEntitiesWithinAABB(EntityPlayer.class, player.getBoundingBox().expand(expansionLevel, expansionLevel, expansionLevel));

How do I fix this?

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

It crashes but with what error? And also you can use List because it's just a List waiting to be declared, and getEntitiesWithinAABB returns a list of the target type.

 

is the error a null pointer? index out of bounds? cannot cast the list? (like memcallen suggested, and I blindly said no worries) was gonna say the expansionLevel would cause an issue, but I think the only issue is when 2 or more players wear it that value will be flying all over the place. Best to make it a method scope variable, than a class one.

 

Link to comment
Share on other sites

Here is the crash report

 

 

[15:56:12] [server thread/ERROR]: Encountered an unexpected exception
net.minecraft.util.ReportedException: Ticking player
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:198) ~[NetworkSystem.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:736) ~[MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624) ~[MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?]
Caused by: java.lang.NullPointerException
at the_fireplace.unlogic.armor.IceArmor.onArmorTick(IceArmor.java:70) ~[iceArmor.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624) ~[EntityPlayer.class:?]
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826) ~[EntityLivingBase.class:?]
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341) ~[EntityPlayer.class:?]
at net.minecraft.entity.player.EntityPlayerMP.onUpdateEntity(EntityPlayerMP.java:334) ~[EntityPlayerMP.class:?]
at net.minecraft.network.NetHandlerPlayServer.processPlayer(NetHandlerPlayServer.java:329) ~[NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer.processPacket(C03PacketPlayer.java:37) ~[C03PacketPlayer.class:?]
at net.minecraft.network.play.client.C03PacketPlayer$C06PacketPlayerPosLook.processPacket(C03PacketPlayer.java:271) ~[C03PacketPlayer$C06PacketPlayerPosLook.class:?]
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) ~[NetworkManager.class:?]
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182) ~[NetworkSystem.class:?]
... 5 more
[15:56:12] [server thread/ERROR]: This crash report has been saved to: B:\Users\Lance\Documents\unlogic\eclipse\.\crash-reports\crash-2014-09-30_15.56.12-server.txt
[15:56:12] [server thread/INFO]: Stopping server
[15:56:12] [server thread/INFO]: Saving players
[15:56:12] [server thread/INFO]: Saving worlds
[15:56:12] [server thread/INFO]: Saving chunks for level 'New Test World'/Overworld
[15:56:12] [server thread/INFO]: Saving chunks for level 'New Test World'/Nether
[15:56:12] [server thread/INFO]: Saving chunks for level 'New Test World'/The End
---- Minecraft Crash Report ----
// Would you like a cupcake?

Time: 9/30/14 3:56 PM
Description: Ticking player

java.lang.NullPointerException: Ticking player
at the_fireplace.unlogic.armor.IceArmor.onArmorTick(IceArmor.java:70)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
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 the_fireplace.unlogic.armor.IceArmor.onArmorTick(IceArmor.java:70)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)

-- Player being ticked --
Details:
Entity Type: null (net.minecraft.entity.player.EntityPlayerMP)
Entity ID: 696
Entity Name: ForgeDevName
Entity's Exact location: -521.62, 4.00, 621.60
Entity's Block location: World: (-522,4,621), Chunk: (at 6,0,13 in -33,38; contains blocks -528,0,608 to -513,255,623), Region: (-2,1; contains chunks -64,32 to -33,63, blocks -1024,0,512 to -513,255,1023)
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@d8f8ec
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 7 (x86) version 6.1
Java Version: 1.7.0_67, Oracle Corporation
Java VM Version: Java HotSpot(TM) Client VM (mixed mode), Oracle Corporation
Memory: 979761704 bytes (934 MB) / 1060372480 bytes (1011 MB) up to 1060372480 bytes (1011 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: 0, tallocated: 0
FML: MCP v9.05 FML v7.10.25.1188 Minecraft Forge 10.13.0.1188 5 mods loaded, 5 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
FML{7.10.25.1188} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.0.1188.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
Forge{10.13.0.1188} [Minecraft Forge] (forgeSrc-1.7.10-10.13.0.1188.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
fireplacecore{1.2.0} [Fireplace Core] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->Available->Available->Available->Available
unlogic{pre1.4 b1} [unLogic] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available->Available->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'/696, l='New Test World', x=-521.62, y=4.00, z=621.60]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
#@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2014-09-30_15.56.12-server.txt

 

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

so what is null?

expansionLevel?

player?

world?

 

what if you make expansion level start at 1? use some System.out.println() for each variable that goes into that line (before it is called) should help you see what is null. if they all check out fine it could be that somewhere that method is returning null or getting something that is null.

Link to comment
Share on other sites

so what is null?

expansionLevel?

player?

world?

 

what if you make expansion level start at 1? use some System.out.println() for each variable that goes into that line (before it is called) should help you see what is null. if they all check out fine it could be that somewhere that method is returning null or getting something that is null.

I've done more testing and using System.out.println(""), and expansionLevel isn't being changed like it is supposed to. However, that isn't the issue. I tried replacing the expansionLevel variable in getEntitiesWithinAABB with 3, and it still crashed. Meaning expansionLevel isn't causing it to crash. That leaves player and world. Seeing as player is the player wearing the armor and world is the world the player is in, I doubt either of them are returning null, either.

If I helped please press the Thank You button.

 

Check out my mods at http://www.curse.com/users/The_Fireplace/projects

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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