Jump to content

[1.7.2]Calling Item causes crash


PlatonCraft

Recommended Posts

I have a real trouble. If I trying this

par2EntityLivingBase.getCurrentItemOrArmor(1).getItem()

I getting MC crashed with

 

Description: Ticking memory connection

java.lang.NullPointerException: Ticking memory connection
at platon.mods.flintstonetools.ItemFlintSword.hitEntity(ItemFlintSword.java:40)
at net.minecraft.item.ItemStack.hitEntity(ItemStack.java:318)
at net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(EntityPlayer.java:1323)
at net.minecraft.network.NetHandlerPlayServer.func_147340_a(NetHandlerPlayServer.java:813)
at net.minecraft.network.play.client.C02PacketUseEntity.func_148833_a(C02PacketUseEntity.java:55)
at net.minecraft.network.play.client.C02PacketUseEntity.func_148833_a(C02PacketUseEntity.java:10)
at net.minecraft.network.NetworkManager.processReadPackets(NetworkManager.java:198)
at net.minecraft.network.NetworkSystem.func_151269_c(NetworkSystem.java:165)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:680)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:568)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:114)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:452)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:705)

 

I guess why this happens. How can I get Item if Item is null. But even if I calling this to armored horse with saddle too, game crashes anyway. Why? How can I fix this?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

par2EntityLivingBase.getCurrentItemOrArmor(1)

 

If that slot is empty, what will it return?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

par2EntityLivingBase.getCurrentItemOrArmor(1)

 

If that slot is empty, what will it return?

Yes, but slot is NOT empty.

How can I check that slot is not or empty empty? I don't know

And != null or ==null or !(.equal(null)) or .equal(null) not act at all

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

par2EntityLivingBase.getCurrentItemOrArmor(1)

 

If that slot is empty, what will it return?

Yes, but slot is NOT empty.

How can I check that slot is not or empty empty? I don't know

And != null or ==null or !(.equal(null)) or .equal(null) not act at all

 

You have to check for the thing that actually IS null, not the thing after it:

 

if(par2EntityLivingBase.getCurrentItemOrArmor(1) != null) {

    par2EntityLivingBase.getCurrentItemOrArmor(1).getItem() <-- now you can do things.

}

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I already said that tried this.

And != null or ==null or !(.equal(null)) or .equal(null) not act at all

Now I tried this once again

    	if(par2EntityLivingBase.getCurrentItemOrArmor(1) != null) {
    	    System.out.println(par2EntityLivingBase.getCurrentItemOrArmor(1).getItem().toString());
    	}

And game not crash but nothing happens.

Also I tried ==null (Crash), if (!par2EntityLivingBase.getCurrentItemOrArmor(1).equals(null)) (Crash), par2EntityLivingBase.getCurrentItemOrArmor(1).equals(null) (Crash).

 

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

==null (Crash)

 

Duh.  If it equals null you can't then go accessing its child fields and methods.

 

If "nothing happens" when you do it like I said, are you sure the slot is not empty?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

==null (Crash)

 

Duh.  If it equals null you can't then go accessing its child fields and methods.

 

If "nothing happens" when you do it like I said, are you sure the slot is not empty?

 

I got horse with saddle and iron armor. Also I tried slot numbers 0,2,3,4 But nothing happend.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Oh, you're dealing with a horse.

 

Welcome to Mojang Code.  only the player equipment can be referenced that way.  Almost every other entity uses its own inventory management system.

 

Looking through EntityHorse, it does not appear to be possible to reference its equipment. 

private AnimalChest horseChest; //yes, Mojang actually didn't use EntityLivingBase.equipment

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Now I made it not crash if it horse or any another entity

b = ((par1EntityLivingBase.getCurrentItemOrArmor(3) != null && par1EntityLivingBase.getCurrentItemOrArmor(3).getItem() == armorarray[i])|(par1EntityLivingBase.getCurrentItemOrArmor(4) != null && par1EntityLivingBase.getCurrentItemOrArmor(4).getItem() == armorarray[i]))? true:false;

But how can I check horse's armor? I don't understand.

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Now I made it not crash if it horse or any another entity

b = ((par1EntityLivingBase.getCurrentItemOrArmor(3) != null && par1EntityLivingBase.getCurrentItemOrArmor(3).getItem() == armorarray[i])|(par1EntityLivingBase.getCurrentItemOrArmor(4) != null && par1EntityLivingBase.getCurrentItemOrArmor(4).getItem() == armorarray[i]))? true:false;

But how can I check horse's armor? I don't understand.

 

It's stored in a private variable.

 

You can't.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Now I made it not crash if it horse or any another entity

b = ((par1EntityLivingBase.getCurrentItemOrArmor(3) != null && par1EntityLivingBase.getCurrentItemOrArmor(3).getItem() == armorarray[i])|(par1EntityLivingBase.getCurrentItemOrArmor(4) != null && par1EntityLivingBase.getCurrentItemOrArmor(4).getItem() == armorarray[i]))? true:false;

But how can I check horse's armor? I don't understand.

 

It's stored in a private variable.

 

You can't.

 

It's a pity

But I invented my own method =)

If TryCatch catches exception and getTotalArmorValue == 5 (this is when Horse iron armored)

then command work. =)

Thank you for help

 

 

P.S. Why can't I paste some code? I trying to paste smile, clicking it, and nothing happens. Also I can't paste spoilers, quotes, codes. I can't paste anything!! And I need to use spoiler /spoiler with [] It's very uncomfortable!! How can I fix it?

[spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler][spoiler=Spoiler]LOL,Its nothing interesting here

[spoiler=Spoiler]And here too

[spoiler=Spoiler]But that image is pretty good

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Works for me.

I tend to type BBCode tags anyway.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.



×
×
  • Create New...

Important Information

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