Jump to content

[1.7.10] NullPointerException during harvest event


flamedragonX2

Recommended Posts

So I created a pickaxe that when mining stone drops my custom block, and has a 25% chance to set the player on fire when mining a block. Code for harvest event below:

 

(Note: some of it is obfuscated with xxxx to keep names a secret)

 

@SubscribeEvent
public void xxxxPick(HarvestDropsEvent event)
{
	ItemStack theTool = event.harvester.getCurrentEquippedItem(); //[b]THIS[/b] is line 38, which was mentioned in the crash report
	if(theTool != null)
	{
		if(theTool.getItem() == ToolManager.xxxxPickaxe)
		{	
			if(random.nextInt(4) == 0)
			{
				event.harvester.setFire(5);
			}

			if(event.block != null)
			{
				if(event.block == Blocks.stone)
				{
					event.drops.clear();
					event.drops.add(new ItemStack(Item.getItemFromBlock(myBlocksClass.myCustomStone)));
				}
			}				
		}
	}

 

However, occasionally I get a crash report, stating a NullPointerException has occured doing my custom pick event. This really confuses me since I checked to see if both the block and the ItemStack for the tool are not null before using them. Example below:

 

 

// Hi. I'm Minecraft, and I'm a crashaholic.

 

Time: 3/21/16 7:12 PM

Description: Exception ticking world

 

java.lang.NullPointerException: Exception ticking world

at net.xxxxxx.events.HarvestingEvents.xxxxPick(HarvestingEvents.java:38)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_HarvestingEvents_xxxxPick_HarvestDropsEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)

at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:162)

at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806)

at net.minecraft.block.Block.dropBlockAsItem(Block.java:795)

at net.minecraft.block.BlockBush.checkAndDropBlock(BlockBush.java:74)

at net.minecraft.block.BlockBush.updateTick(BlockBush.java:64)

at net.minecraft.world.WorldServer.func_147456_g(WorldServer.java:408)

at net.minecraft.world.WorldServer.tick(WorldServer.java:191)

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:692)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

 

 

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

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at net.xxxxxxx.events.HarvestingEvents.xxxxPick(HarvestingEvents.java:38)

at cpw.mods.fml.common.eventhandler.ASMEventHandler_6_HarvestingEvents_xxxxPick_HarvestDropsEvent.invoke(.dynamic)

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:54)

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:140)

at net.minecraftforge.event.ForgeEventFactory.fireBlockHarvesting(ForgeEventFactory.java:162)

at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:806)

at net.minecraft.block.Block.dropBlockAsItem(Block.java:795)

at net.minecraft.block.BlockBush.checkAndDropBlock(BlockBush.java:74)

at net.minecraft.block.BlockBush.updateTick(BlockBush.java:64)

at net.minecraft.world.WorldServer.func_147456_g(WorldServer.java:408)

at net.minecraft.world.WorldServer.tick(WorldServer.java:191)

 

-- Affected level --

Details:

Level name: New Worldwq346g344v632v2453v

All players: 1 total; [EntityPlayerMP['Player189'/19119, l='New Worldwq346g344v632v2453v', x=-73.43, y=72.00, z=185.88]]

Chunk stats: ServerChunkCache: 647 Drop: 0

Level seed: -2949494732709534244

Level generator: ID 00 - default, ver 1. Features enabled: true

Level generator options:

Level spawn location: World: (-69,64,258), Chunk: (at 11,4,2 in -5,16; contains blocks -80,0,256 to -65,255,271), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 25685 game time, 25685 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 117553 (now: false), thunder time: 9149 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true

Stacktrace:

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:692)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 10 (amd64) version 10.0

Java Version: 1.8.0_73, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 626505336 bytes (597 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 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: 12, tallocated: 94

FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 4 mods loaded, 4 mods active

States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored

UCHIJAAAAAAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)

UCHIJAAAAAAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)

UCHIJAAAAAAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)

UCHIJAAAAAAAAA xxxxxxxx{0.1} [xxxxxxxx] (bin)

GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.

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['Player189'/19119, l='New Worldwq346g344v632v2453v', x=-73.43, y=72.00, z=185.88]]

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge'

 

 

Any idea what could be causing it? It says "BlockBush" in the crash report somewhere but the crash tends to occur half a minute after breaking a dead bush, if I broke one.

Link to comment
Share on other sites

Thanks. Unfortunately I don't know how to trigger the crash (it happens randomly quite occasionally), but I will try this.

It happens when a non-player causes blocks to drop, such as water flowing over crops or a creeper exploding (maybe the creeper counts as a harvester? it's been months since I've looked at the code).

Link to comment
Share on other sites

Maybe put a torch next to a mushroom, or spread water through crops or carpets. Those actions may trigger the event without setting a "harvester".

 

If all else fails, try some TNT. It may not solve your problem, but it will make you feel better.

 

You may also temporarily wrap your danger zone in a try-catch frame. Catch the next NPE and output everything you can see. Try to figure out what was being harvested and how. Then you'll have a better idea how to replicate the NPE as needed during testing.

 

Looking at your call stack, it appears that something was acting upon a BlockBush.

 

Or you can simply accept CoolAlias's advice to check harvester for null.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.