Jump to content

Run code on item in hand?


robertcars

Recommended Posts

Two ways that *I* know (there is probably more)

 

Items have an onUpdate method (currently vanilla maps use this)

 

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World,
		Entity par3Entity, int par4, boolean par5) {
	// TODO Auto-generated method stub
	super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);

	if (par3Entity instanceof EntityPlayer) 
	{
		EntityPlayer player = (EntityPlayer)par3Entity;
		if (player.getHeldItem().equals(par1ItemStack) && player.inventory.getStackInSlot(2).equals(par1ItemStack))
		{
			//Do stuff
		}
	}
}

Hotbar slots in the players inventory is 0-8 (1 to 9 left to right) now this way it runs like every tick, I normally build my own cool down system but that gets glitchy if you have many of the same item (including other players having the item)

 

Second would be to make your own event that checks the livingUpdateEvent or a event that fits better.

Link to comment
Share on other sites

When ever I put the item in the hot bar it crashes. I did try changing one thing because I want it to run that code everytime the item is pulled out not just in slot 2.

 

     @Override
	public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
		super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);

		if (par3Entity instanceof EntityPlayer)  {
			EntityPlayer player = (EntityPlayer)par3Entity;
			if (player.getHeldItem().equals(par1ItemStack)) {
				System.out.println("Test");
			}
		}
	}

Link to comment
Share on other sites

net.minecraft.util.ReportedException: Ticking entity
at net.minecraft.world.World.updateEntities(World.java:2102) ~[World.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2096) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
Caused by: java.lang.NullPointerException
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:64) ~[ModAxe.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624) ~[EntityPlayer.class:?]
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299) ~[EntityPlayerSP.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.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100) ~[EntityClientPlayerMP.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277) ~[World.class:?]
at net.minecraft.world.World.updateEntity(World.java:2237) ~[World.class:?]
at net.minecraft.world.World.updateEntities(World.java:2087) ~[World.class:?]
... 10 more
---- Minecraft Crash Report ----
// But it works on my machine.

Time: 8/16/14 2:56 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:64)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277)
at net.minecraft.world.World.updateEntity(World.java:2237)
at net.minecraft.world.World.updateEntities(World.java:2087)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2096)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038)
at net.minecraft.client.Minecraft.run(Minecraft.java:961)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:64)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277)
at net.minecraft.world.World.updateEntity(World.java:2237)

-- Entity being ticked --
Details:
Entity Type: null (net.minecraft.client.entity.EntityClientPlayerMP)
Entity ID: 275
Entity Name: Player250
Entity's Exact location: 238.10, 73.62, 265.17
Entity's Block location: World: (238,73,265), Chunk: (at 14,4,9 in 14,16; contains blocks 224,0,256 to 239,255,271), 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.world.World.updateEntities(World.java:2087)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player250'/275, l='MpServer', x=238.10, y=73.62, z=265.17]]
Chunk stats: MultiplayerChunkCache: 110, 110
Level seed: 0
Level generator: ID 00 - default, ver 1. Features enabled: false
Level generator options: 
Level spawn location: World: (200,64,248), Chunk: (at 8,4,8 in 12,15; contains blocks 192,0,240 to 207,255,255), Region: (0,0; contains chunks 0,0 to 31,31, blocks 0,0,0 to 511,255,511)
Level time: 1344 game time, 1344 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 52 total; [EntityChicken['Chicken'/143, l='MpServer', x=160.50, y=68.00, z=253.50], EntityChicken['Chicken'/142, l='MpServer', x=161.50, y=69.00, z=249.50], EntityChicken['Chicken'/152, l='MpServer', x=175.46, y=69.00, z=216.54], EntityItem['item.item.seeds'/153, l='MpServer', x=182.22, y=68.13, z=236.31], EntityChicken['Chicken'/154, l='MpServer', x=188.44, y=66.00, z=252.56], EntityChicken['Chicken'/155, l='MpServer', x=176.53, y=65.00, z=255.47], EntityChicken['Chicken'/156, l='MpServer', x=185.53, y=65.00, z=264.41], EntityBat['Bat'/157, l='MpServer', x=204.62, y=33.72, z=219.20], EntityBat['Bat'/158, l='MpServer', x=200.86, y=33.01, z=221.79], EntityChicken['Chicken'/159, l='MpServer', x=200.44, y=70.00, z=319.59], EntityChicken['Chicken'/144, l='MpServer', x=171.41, y=67.00, z=251.66], EntityChicken['Chicken'/149, l='MpServer', x=181.50, y=70.00, z=211.50], EntityChicken['Chicken'/150, l='MpServer', x=181.50, y=70.00, z=213.50], EntityChicken['Chicken'/151, l='MpServer', x=187.47, y=70.00, z=216.47], EntityChicken['Chicken'/170, l='MpServer', x=211.56, y=69.00, z=324.47], EntityChicken['Chicken'/169, l='MpServer', x=209.53, y=69.00, z=323.53], EntityBat['Bat'/168, l='MpServer', x=213.14, y=18.04, z=327.59], EntityChicken['Chicken'/160, l='MpServer', x=194.56, y=69.00, z=321.59], EntityChicken['Chicken'/167, l='MpServer', x=222.44, y=66.00, z=279.47], EntityChicken['Chicken'/166, l='MpServer', x=222.34, y=65.00, z=278.38], EntityChicken['Chicken'/165, l='MpServer', x=211.56, y=65.00, z=279.47], EntityChicken['Chicken'/186, l='MpServer', x=236.88, y=64.00, z=279.81], EntityBat['Bat'/187, l='MpServer', x=240.70, y=30.00, z=334.12], EntityCow['Cow'/185, l='MpServer', x=239.63, y=60.00, z=287.38], EntityClientPlayerMP['Player250'/275, l='MpServer', x=238.10, y=73.62, z=265.17], EntityBat['Bat'/205, l='MpServer', x=246.54, y=26.81, z=298.92], EntityCow['Cow'/204, l='MpServer', x=247.47, y=68.00, z=277.47], EntityBat['Bat'/207, l='MpServer', x=248.92, y=21.00, z=314.43], EntityBat['Bat'/206, l='MpServer', x=246.42, y=27.12, z=300.01], EntityCow['Cow'/201, l='MpServer', x=252.47, y=63.00, z=245.75], EntityCow['Cow'/200, l='MpServer', x=246.53, y=63.00, z=247.50], EntityCow['Cow'/203, l='MpServer', x=242.50, y=67.00, z=276.38], EntityCow['Cow'/202, l='MpServer', x=250.69, y=64.00, z=285.53], EntityChicken['Chicken'/197, l='MpServer', x=246.50, y=64.00, z=233.50], EntityChicken['Chicken'/196, l='MpServer', x=255.59, y=65.00, z=232.53], EntityCow['Cow'/199, l='MpServer', x=246.53, y=63.00, z=247.50], EntityCow['Cow'/198, l='MpServer', x=245.47, y=63.00, z=247.50], EntityChicken['Chicken'/195, l='MpServer', x=246.50, y=64.00, z=234.19], EntityChicken['Chicken'/194, l='MpServer', x=245.50, y=64.00, z=233.50], EntityBat['Bat'/223, l='MpServer', x=281.75, y=22.10, z=231.25], EntityBat['Bat'/216, l='MpServer', x=274.01, y=51.66, z=312.15], EntityBat['Bat'/212, l='MpServer', x=265.21, y=37.30, z=299.28], EntityBat['Bat'/213, l='MpServer', x=266.52, y=56.24, z=314.18], EntityBat['Bat'/214, l='MpServer', x=264.56, y=60.10, z=306.38], EntityBat['Bat'/215, l='MpServer', x=268.92, y=56.67, z=315.09], EntityBat['Bat'/211, l='MpServer', x=269.50, y=48.10, z=267.25], EntityBat['Bat'/227, l='MpServer', x=286.47, y=39.05, z=281.83], EntityBat['Bat'/226, l='MpServer', x=277.38, y=47.10, z=272.50], EntityChicken['Chicken'/225, l='MpServer', x=276.47, y=62.23, z=262.53], EntityChicken['Chicken'/224, l='MpServer', x=276.41, y=62.30, z=267.41], EntityBat['Bat'/248, l='MpServer', x=297.25, y=47.45, z=294.33], EntityItem['item.tile.mushroom'/247, l='MpServer', x=296.13, y=22.13, z=241.88]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567)
at net.minecraft.client.Minecraft.run(Minecraft.java:983)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Link to comment
Share on other sites

Yes line 64 is the if statement but the extra check didnt work it still crashed. It crashes as soon as the item goes into the hot bar.

 

net.minecraft.util.ReportedException: Ticking entity
at net.minecraft.world.World.updateEntities(World.java:2102) ~[World.class:?]
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2096) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038) ~[Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_45]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_45]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_45]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?]
Caused by: java.lang.NullPointerException
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:62) ~[ModAxe.class:?]
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478) ~[itemStack.class:?]
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349) ~[inventoryPlayer.class:?]
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624) ~[EntityPlayer.class:?]
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299) ~[EntityPlayerSP.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.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100) ~[EntityClientPlayerMP.class:?]
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277) ~[World.class:?]
at net.minecraft.world.World.updateEntity(World.java:2237) ~[World.class:?]
at net.minecraft.world.World.updateEntities(World.java:2087) ~[World.class:?]
... 10 more
---- Minecraft Crash Report ----
// There are four lights!

Time: 8/16/14 3:05 PM
Description: Ticking entity

java.lang.NullPointerException: Ticking entity
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:62)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277)
at net.minecraft.world.World.updateEntity(World.java:2237)
at net.minecraft.world.World.updateEntities(World.java:2087)
at net.minecraft.client.Minecraft.runTick(Minecraft.java:2096)
at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1038)
at net.minecraft.client.Minecraft.run(Minecraft.java:961)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Stacktrace:
at com.robert.modulartools.items.ModAxe.onUpdate(ModAxe.java:62)
at net.minecraft.item.ItemStack.updateAnimation(ItemStack.java:478)
at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:349)
at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:624)
at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299)
at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1826)
at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:341)
at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100)
at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2277)
at net.minecraft.world.World.updateEntity(World.java:2237)

-- Entity being ticked --
Details:
Entity Type: null (net.minecraft.client.entity.EntityClientPlayerMP)
Entity ID: 224
Entity Name: Player937
Entity's Exact location: -247.50, 63.62, 214.50
Entity's Block location: World: (-248,63,214), Chunk: (at 8,3,6 in -16,13; contains blocks -256,0,208 to -241,255,223), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Entity's Momentum: 0.00, -0.02, 0.00
Stacktrace:
at net.minecraft.world.World.updateEntities(World.java:2087)

-- Affected level --
Details:
Level name: MpServer
All players: 1 total; [EntityClientPlayerMP['Player937'/224, l='MpServer', x=-247.50, y=63.62, z=214.50]]
Chunk stats: MultiplayerChunkCache: 265, 265
Level seed: 0
Level generator: ID 00 - default, ver 1. Features enabled: false
Level generator options: 
Level spawn location: World: (-256,64,224), Chunk: (at 0,4,0 in -16,14; contains blocks -256,0,224 to -241,255,239), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
Level time: 61 game time, 61 day time
Level dimension: 0
Level storage version: 0x00000 - Unknown?
Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false)
Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false
Forced entities: 74 total; [EntityFallingBlock['Falling Block'/1363, l='MpServer', x=-333.50, y=26.49, z=322.50], EntityFallingBlock['Falling Block'/1479, l='MpServer', x=-303.50, y=60.38, z=126.50], EntityFallingBlock['Falling Block'/1478, l='MpServer', x=-311.50, y=3.38, z=118.50], EntityFallingBlock['Falling Block'/1477, l='MpServer', x=-308.50, y=4.38, z=121.50], EntityFallingBlock['Falling Block'/1476, l='MpServer', x=-309.50, y=3.38, z=121.50], EntityFallingBlock['Falling Block'/1475, l='MpServer', x=-307.50, y=4.38, z=121.50], EntityFallingBlock['Falling Block'/1474, l='MpServer', x=-311.50, y=65.38, z=100.50], EntityFallingBlock['Falling Block'/1473, l='MpServer', x=-309.50, y=65.38, z=99.50], EntityFallingBlock['Falling Block'/1472, l='MpServer', x=-310.50, y=65.38, z=100.50], EntityFallingBlock['Falling Block'/1484, l='MpServer', x=-304.50, y=60.38, z=126.50], EntityFallingBlock['Falling Block'/1483, l='MpServer', x=-305.50, y=61.38, z=125.50], EntityBat['Bat'/1346, l='MpServer', x=-208.78, y=37.28, z=181.46], EntityFallingBlock['Falling Block'/1482, l='MpServer', x=-305.50, y=61.38, z=124.50], EntityFallingBlock['Falling Block'/1481, l='MpServer', x=-306.50, y=61.38, z=124.50], EntityFallingBlock['Falling Block'/1480, l='MpServer', x=-304.50, y=60.38, z=124.50], EntityBat['Bat'/1345, l='MpServer', x=-201.66, y=37.10, z=178.93], EntitySquid['Squid'/305, l='MpServer', x=-299.69, y=59.13, z=228.92], EntitySquid['Squid'/304, l='MpServer', x=-299.73, y=58.22, z=230.01], EntitySquid['Squid'/307, l='MpServer', x=-292.50, y=57.85, z=235.50], EntitySquid['Squid'/306, l='MpServer', x=-300.54, y=59.38, z=232.28], EntitySquid['Squid'/308, l='MpServer', x=-295.59, y=59.28, z=232.80], EntityBat['Bat'/1264, l='MpServer', x=-265.06, y=23.14, z=243.76], EntityFallingBlock['Falling Block'/1513, l='MpServer', x=-304.50, y=61.50, z=124.50], EntityChicken['Chicken'/63, l='MpServer', x=-307.50, y=63.00, z=161.50], EntityFallingBlock['Falling Block'/1512, l='MpServer', x=-304.50, y=61.50, z=123.50], EntityChicken['Chicken'/62, l='MpServer', x=-310.50, y=63.00, z=161.50], EntityBat['Bat'/897, l='MpServer', x=-210.50, y=54.90, z=240.34], EntityFallingBlock['Falling Block'/1514, l='MpServer', x=-304.50, y=61.50, z=125.50], EntitySquid['Squid'/303, l='MpServer', x=-297.66, y=57.31, z=229.85], EntityChicken['Chicken'/68, l='MpServer', x=-303.50, y=68.00, z=208.50], EntityChicken['Chicken'/69, l='MpServer', x=-302.50, y=68.00, z=209.50], EntityChicken['Chicken'/70, l='MpServer', x=-291.50, y=64.00, z=142.50], EntityChicken['Chicken'/71, l='MpServer', x=-293.50, y=68.00, z=146.50], EntityChicken['Chicken'/64, l='MpServer', x=-306.50, y=63.00, z=158.50], EntityChicken['Chicken'/65, l='MpServer', x=-306.50, y=63.00, z=158.50], EntityChicken['Chicken'/66, l='MpServer', x=-306.50, y=65.00, z=212.50], EntityChicken['Chicken'/67, l='MpServer', x=-305.50, y=67.00, z=209.50], EntityChicken['Chicken'/76, l='MpServer', x=-282.50, y=66.00, z=201.50], EntityChicken['Chicken'/77, l='MpServer', x=-281.50, y=66.00, z=201.50], EntityChicken['Chicken'/72, l='MpServer', x=-293.50, y=63.00, z=145.50], EntityBat['Bat'/893, l='MpServer', x=-211.72, y=55.25, z=243.09], EntityChicken['Chicken'/73, l='MpServer', x=-290.50, y=63.00, z=148.50], EntityChicken['Chicken'/74, l='MpServer', x=-281.79, y=67.00, z=204.16], EntityChicken['Chicken'/75, l='MpServer', x=-282.50, y=66.00, z=203.50], EntityChicken['Chicken'/85, l='MpServer', x=-270.50, y=71.00, z=229.50], EntityChicken['Chicken'/84, l='MpServer', x=-270.50, y=71.00, z=229.50], EntityFallingBlock['Falling Block'/1288, l='MpServer', x=-362.50, y=16.49, z=178.50], EntityFallingBlock['Falling Block'/1289, l='MpServer', x=-362.50, y=17.49, z=179.50], EntityChicken['Chicken'/83, l='MpServer', x=-275.74, y=67.00, z=229.72], EntityChicken['Chicken'/82, l='MpServer', x=-270.50, y=70.00, z=227.50], EntityChicken['Chicken'/93, l='MpServer', x=-241.50, y=63.00, z=164.50], EntityChicken['Chicken'/95, l='MpServer', x=-245.50, y=64.00, z=158.50], EntityChicken['Chicken'/94, l='MpServer', x=-245.50, y=64.00, z=160.50], EntitySheep['Sheep'/102, l='MpServer', x=-208.35, y=72.00, z=231.55], EntitySheep['Sheep'/103, l='MpServer', x=-207.94, y=72.00, z=230.46], EntitySheep['Sheep'/101, l='MpServer', x=-209.44, y=72.00, z=231.50], EntityBat['Bat'/374, l='MpServer', x=-237.21, y=36.29, z=180.39], EntityFallingBlock['Falling Block'/1462, l='MpServer', x=-306.50, y=64.38, z=100.50], EntityChicken['Chicken'/96, l='MpServer', x=-244.50, y=64.00, z=158.50], EntityFallingBlock['Falling Block'/1463, l='MpServer', x=-307.50, y=64.38, z=100.50], EntityFallingBlock['Falling Block'/1464, l='MpServer', x=-307.50, y=64.38, z=101.50], EntityFallingBlock['Falling Block'/1465, l='MpServer', x=-306.50, y=64.38, z=99.50], EntityFallingBlock['Falling Block'/1466, l='MpServer', x=-306.50, y=64.38, z=101.50], EntityClientPlayerMP['Player937'/224, l='MpServer', x=-247.50, y=63.62, z=214.50], EntityFallingBlock['Falling Block'/1467, l='MpServer', x=-308.50, y=65.38, z=100.50], EntityFallingBlock['Falling Block'/1468, l='MpServer', x=-307.50, y=65.38, z=99.50], EntityFallingBlock['Falling Block'/1469, l='MpServer', x=-308.50, y=64.38, z=101.50], EntityFallingBlock['Falling Block'/1470, l='MpServer', x=-308.50, y=65.38, z=99.50], EntitySheep['Sheep'/104, l='MpServer', x=-205.69, y=72.00, z=230.41], EntityFallingBlock['Falling Block'/1471, l='MpServer', x=-309.50, y=65.38, z=100.50], EntitySheep['Sheep'/116, l='MpServer', x=-173.50, y=71.00, z=273.50], EntitySheep['Sheep'/115, l='MpServer', x=-170.50, y=71.00, z=273.97], EntitySheep['Sheep'/114, l='MpServer', x=-171.81, y=72.00, z=271.19], EntitySheep['Sheep'/113, l='MpServer', x=-170.22, y=72.00, z=272.47]]
Retry entities: 0 total; []
Server brand: fml,forge
Server type: Integrated singleplayer server
Stacktrace:
at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:417)
at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2567)
at net.minecraft.client.Minecraft.run(Minecraft.java:983)
at net.minecraft.client.main.Main.main(Main.java:164)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at net.minecraft.launchwrapper.Launch.launch(Launch.java:134)
at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

Link to comment
Share on other sites

hmm... works for me just fine.

 

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World,
		Entity par3Entity, int par4, boolean par5) {
	// TODO Auto-generated method stub
	super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);

	if (par3Entity instanceof EntityPlayer)
	{
		EntityPlayer player = (EntityPlayer)par3Entity;
		if (player.getHeldItem() != null)
		{
			if (player.getHeldItem().equals(par1ItemStack))
			{
				System.out.println("test");
			}
		}
	}
}

Link to comment
Share on other sites

Yup, the way hugo_the_dwarf suggested is the 'right' way to do it if you're using your own custom item.

 

If you needed to do this with a vanilla item, however, then you'd be using either the LivingUpdateEvent or the TickEvent.PlayerTick.

BEFORE ASKING FOR HELP READ THE EAQ!

 

I'll help if I can. Apologies if I do something obviously stupid. :D

 

If you don't know basic Java yet, go and follow these tutorials.

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



×
×
  • Create New...

Important Information

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