Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12] Event onDrawBlockHighlightEvent crash when I aim on an Entity


Fifou_BE
 Share

Recommended Posts

Hi everyone, I'm trying to make something for my block, briefly I try to add the render of the item that is in the block ! It works very well, you can see on this gif, so the problems is not the render or anything it crashes when my cursor is pointing on an entity (like cow/sheep/etc):170807072231367186.gif

 

But I can't find why it crashes. Actually I found that in my code it's the worldIn.getBlockState that return a NPE but I can't manage to find a fix ... Here is my code

 

@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onDrawBlockHighlightEvent(DrawBlockHighlightEvent event)
	{	
		EntityPlayer playerIn = event.getPlayer();
		World worldIn = playerIn.world;
		
		if(worldIn != null)
		{
			if(worldIn.getBlockState(event.getTarget().getBlockPos()).getBlock() == BlocksRegistery.BLOCK_SELLER)
			{
				 TileEntityBlockSeller te = (TileEntityBlockSeller)worldIn.getTileEntity(event.getTarget().getBlockPos());
					if(te != null)
					{
						if(te.getCreated())
						{
							int x = event.getTarget().getBlockPos().getX();
							int y = event.getTarget().getBlockPos().getY();
							int z = event.getTarget().getBlockPos().getZ();
							float i = 0f;
							float j = 0.0F;
							RenderManager renderM = Minecraft.getMinecraft().getRenderManager();
							GL11.glPushMatrix();
							GlStateManager.enableRescaleNormal();
							RenderHelper.enableStandardItemLighting();
							if(te.getStackInSlot(0).getUnlocalizedName().substring(0, 4).equals("tile"))
							{
								i = 0.1F;
							}
							if(te.getFacing().substring(0, 4).equals("west"))
							{
								j = 94F;
							}
							else if(te.getFacing().substring(0, 4).equals("east"))
							{
								j = 31.5F;
							}
							else if(te.getFacing().equals("north"))
							{
								j = 188F;
							}
							ItemStack stack = new ItemStack(te.getStackInSlot(0).getItem(), 1, te.getStackInSlot(0).getMetadata());
							EntityItem entItem = new EntityItem(worldIn, x + 0.5, y + i, z + 0.5, stack);
							entItem.hoverStart = 0.0F;
							renderM.renderEntityStatic(entItem, 1.0F * j, false);
							RenderHelper.disableStandardItemLighting();
							GlStateManager.disableRescaleNormal();
							GL11.glPopMatrix();		
						}
					}
			}
		}
	}

 

And here is the crash report :/

 

---- Minecraft Crash Report ----
// I let you down. Sorry :(

Time: 8/7/17 7:01 PM
Description: Unexpected error

java.lang.NullPointerException: Unexpected error
	at net.minecraft.world.World.isOutsideBuildHeight(World.java:268)
	at net.minecraft.world.World.getBlockState(World.java:984)
	at fr.fifou.economy.events.EventClassClient.onDrawBlockHighlightEvent(EventClassClient.java:37)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_EventClassClient_onDrawBlockHighlightEvent_DrawBlockHighlightEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.client.ForgeHooksClient.onDrawBlockHighlight(ForgeHooksClient.java:155)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1403)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1303)
	at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1106)
	at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1192)
	at net.minecraft.client.Minecraft.run(Minecraft.java:436)
	at net.minecraft.client.main.Main.main(Main.java:118)
	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:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)


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

-- Head --
Thread: Client thread
Stacktrace:
	at net.minecraft.world.World.isOutsideBuildHeight(World.java:268)
	at net.minecraft.world.World.getBlockState(World.java:984)
	at fr.fifou.economy.events.EventClassClient.onDrawBlockHighlightEvent(EventClassClient.java:37)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_11_EventClassClient_onDrawBlockHighlightEvent_DrawBlockHighlightEvent.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:179)
	at net.minecraftforge.client.ForgeHooksClient.onDrawBlockHighlight(ForgeHooksClient.java:155)
	at net.minecraft.client.renderer.EntityRenderer.renderWorldPass(EntityRenderer.java:1403)
	at net.minecraft.client.renderer.EntityRenderer.renderWorld(EntityRenderer.java:1303)

-- Affected level --
Details:
	Level name: MpServer
	All players: 1 total; [EntityPlayerSP['Fifou_BE'/198, l='MpServer', x=-310.54, y=71.00, z=61.83]]
	Chunk stats: MultiplayerChunkCache: 583, 583
	Level seed: 0
	Level generator: ID 00 - default, ver 1. Features enabled: false
	Level generator options: 
	Level spawn location: World: (-334,64,60), Chunk: (at 2,4,12 in -21,3; contains blocks -336,0,48 to -321,255,63), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)
	Level time: 3429 game time, 3429 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: 99 total; [EntityCow['Cow'/13, l='MpServer', x=-387.79, y=63.00, z=-0.48], EntityZombie['Zombie'/18, l='MpServer', x=-388.51, y=27.00, z=109.19], EntitySkeleton['Skeleton'/21, l='MpServer', x=-374.50, y=20.00, z=73.50], EntityZombie['Zombie'/22, l='MpServer', x=-380.50, y=18.00, z=81.50], EntitySpider['Spider'/23, l='MpServer', x=-379.08, y=16.00, z=96.02], EntitySquid['Squid'/24, l='MpServer', x=-367.35, y=57.11, z=101.37], EntitySkeleton['Skeleton'/26, l='MpServer', x=-383.45, y=20.00, z=132.28], EntityZombie['Zombie'/27, l='MpServer', x=-381.97, y=20.00, z=141.57], EntityCreeper['Creeper'/29, l='MpServer', x=-382.57, y=20.00, z=140.84], EntitySquid['Squid'/30, l='MpServer', x=-355.92, y=54.66, z=68.16], EntitySkeleton['Skeleton'/33, l='MpServer', x=-340.77, y=44.01, z=-12.33], EntitySkeleton['Skeleton'/34, l='MpServer', x=-340.56, y=44.00, z=-14.10], EntitySquid['Squid'/35, l='MpServer', x=-346.95, y=55.92, z=74.85], EntitySquid['Squid'/36, l='MpServer', x=-345.94, y=60.53, z=85.85], EntitySquid['Squid'/37, l='MpServer', x=-346.50, y=55.54, z=106.25], EntitySquid['Squid'/38, l='MpServer', x=-347.08, y=60.50, z=96.32], EntityCreeper['Creeper'/39, l='MpServer', x=-339.50, y=36.00, z=113.50], EntityZombie['Zombie'/40, l='MpServer', x=-334.50, y=15.00, z=-14.50], EntityZombie['Zombie'/41, l='MpServer', x=-333.54, y=16.00, z=-12.00], EntityCow['Cow'/42, l='MpServer', x=-333.01, y=64.00, z=26.51], EntityCow['Cow'/43, l='MpServer', x=-326.79, y=64.00, z=42.24], EntitySquid['Squid'/44, l='MpServer', x=-331.61, y=48.00, z=119.38], EntityCow['Cow'/49, l='MpServer', x=-305.50, y=76.00, z=12.50], EntityCow['Cow'/50, l='MpServer', x=-311.53, y=69.00, z=5.85], EntityCreeper['Creeper'/51, l='MpServer', x=-306.50, y=16.00, z=24.50], EntityCow['Cow'/52, l='MpServer', x=-306.24, y=76.00, z=26.58], EntityCow['Cow'/53, l='MpServer', x=-314.68, y=64.00, z=24.77], EntityCow['Cow'/54, l='MpServer', x=-305.61, y=72.00, z=30.45], EntityCow['Cow'/55, l='MpServer', x=-306.68, y=76.00, z=23.36], EntityCreeper['Creeper'/56, l='MpServer', x=-317.50, y=16.00, z=37.22], EntityCow['Cow'/57, l='MpServer', x=-316.57, y=68.00, z=49.40], EntityCow['Cow'/58, l='MpServer', x=-314.42, y=68.00, z=62.45], EntityCow['Cow'/59, l='MpServer', x=-319.49, y=66.00, z=64.23], EntityBat['Bat'/60, l='MpServer', x=-296.76, y=72.32, z=3.14], EntitySkeleton['Skeleton'/61, l='MpServer', x=-302.50, y=55.00, z=0.73], EntityBat['Bat'/62, l='MpServer', x=-292.41, y=49.14, z=15.84], EntityCreeper['Creeper'/63, l='MpServer', x=-301.50, y=15.00, z=21.50], EntitySkeleton['Skeleton'/64, l='MpServer', x=-296.50, y=25.00, z=31.50], EntitySkeleton['Skeleton'/65, l='MpServer', x=-294.53, y=26.00, z=31.69], EntityBat['Bat'/66, l='MpServer', x=-289.70, y=46.78, z=20.61], EntityCow['Cow'/67, l='MpServer', x=-301.47, y=76.00, z=22.14], EntityZombie['Zombie'/68, l='MpServer', x=-297.48, y=25.00, z=33.76], EntityZombie['Zombie'/69, l='MpServer', x=-296.50, y=25.00, z=118.50], EntityCreeper['Creeper'/70, l='MpServer', x=-293.50, y=17.00, z=127.50], EntityZombie['Zombie'/71, l='MpServer', x=-293.50, y=17.00, z=127.50], EntitySkeleton['Skeleton'/72, l='MpServer', x=-291.50, y=24.00, z=123.17], EntitySkeleton['Skeleton'/73, l='MpServer', x=-306.12, y=17.00, z=130.30], EntitySkeleton['Skeleton'/74, l='MpServer', x=-295.73, y=16.00, z=131.54], EntitySkeleton['Skeleton'/75, l='MpServer', x=-292.23, y=17.00, z=127.94], EntityZombie['Zombie'/79, l='MpServer', x=-282.89, y=60.00, z=-2.49], EntityCreeper['Creeper'/80, l='MpServer', x=-286.50, y=61.00, z=-3.50], EntityCreeper['Creeper'/81, l='MpServer', x=-284.42, y=31.00, z=11.19], EntityCow['Cow'/82, l='MpServer', x=-272.84, y=73.00, z=1.50], EntityCow['Cow'/83, l='MpServer', x=-277.20, y=84.00, z=7.40], EntityCow['Cow'/84, l='MpServer', x=-277.49, y=85.00, z=10.80], EntityCow['Cow'/85, l='MpServer', x=-282.47, y=68.00, z=22.95], EntityCow['Cow'/86, l='MpServer', x=-270.52, y=70.34, z=22.54], EntityCow['Cow'/87, l='MpServer', x=-284.56, y=67.00, z=26.83], EntitySpider['Spider'/88, l='MpServer', x=-276.36, y=46.00, z=47.50], EntitySpider['Spider'/89, l='MpServer', x=-277.89, y=46.00, z=47.29], EntitySkeleton['Skeleton'/90, l='MpServer', x=-279.50, y=45.00, z=38.50], EntityCow['Cow'/91, l='MpServer', x=-273.90, y=67.00, z=35.29], EntitySpider['Spider'/92, l='MpServer', x=-275.12, y=45.00, z=53.53], EntitySkeleton['Skeleton'/93, l='MpServer', x=-272.50, y=23.00, z=110.50], EntitySkeleton['Skeleton'/94, l='MpServer', x=-273.50, y=23.00, z=108.50], EntitySpider['Spider'/95, l='MpServer', x=-274.50, y=23.00, z=110.50], EntityBat['Bat'/96, l='MpServer', x=-276.25, y=21.10, z=127.25], EntityBat['Bat'/97, l='MpServer', x=-272.25, y=25.10, z=125.53], EntitySkeleton['Skeleton'/98, l='MpServer', x=-289.14, y=16.00, z=128.04], EntityZombie['Zombie'/99, l='MpServer', x=-281.50, y=24.00, z=129.50], EntitySpider['Spider'/100, l='MpServer', x=-275.07, y=26.00, z=135.64], EntityZombie['Zombie'/101, l='MpServer', x=-276.65, y=24.00, z=131.76], EntityZombie['Zombie'/102, l='MpServer', x=-280.50, y=24.00, z=130.50], EntityZombie['Zombie'/103, l='MpServer', x=-282.50, y=24.00, z=132.50], EntityCow['Cow'/104, l='MpServer', x=-267.19, y=73.00, z=13.53], EntityCow['Cow'/105, l='MpServer', x=-259.35, y=70.00, z=12.81], EntityCow['Cow'/106, l='MpServer', x=-271.43, y=84.00, z=6.19], EntitySkeleton['Skeleton'/107, l='MpServer', x=-269.33, y=47.00, z=47.66], EntityBat['Bat'/108, l='MpServer', x=-259.32, y=44.45, z=57.19], EntityCreeper['Creeper'/109, l='MpServer', x=-259.50, y=13.00, z=105.50], EntitySkeleton['Skeleton'/110, l='MpServer', x=-267.50, y=22.00, z=105.50], EntityEnderman['Enderman'/111, l='MpServer', x=-267.50, y=22.00, z=108.50], EntityItem['item.item.slimeball'/112, l='MpServer', x=-267.13, y=11.00, z=125.13], EntityCreeper['Creeper'/113, l='MpServer', x=-260.50, y=22.00, z=119.50], EntityCreeper['Creeper'/114, l='MpServer', x=-260.76, y=22.00, z=117.41], EntityBat['Bat'/115, l='MpServer', x=-269.70, y=23.10, z=126.07], EntityBat['Bat'/116, l='MpServer', x=-256.45, y=16.29, z=115.33], EntityBat['Bat'/117, l='MpServer', x=-267.25, y=22.10, z=128.75], EntityBat['Bat'/118, l='MpServer', x=-256.46, y=22.03, z=122.62], EntityCreeper['Creeper'/119, l='MpServer', x=-264.54, y=26.00, z=131.27], EntityZombie['Zombie'/124, l='MpServer', x=-242.57, y=19.00, z=15.50], EntityZombie['Zombie'/125, l='MpServer', x=-241.50, y=20.00, z=15.50], EntityCow['Cow'/126, l='MpServer', x=-249.42, y=69.00, z=17.50], EntityCow['Cow'/127, l='MpServer', x=-246.17, y=68.00, z=29.27], EntityBat['Bat'/128, l='MpServer', x=-254.25, y=16.10, z=53.75], EntityBat['Bat'/129, l='MpServer', x=-239.25, y=48.89, z=56.83], EntityCow['Cow'/145, l='MpServer', x=-230.86, y=68.00, z=14.99], EntityCreeper['Creeper'/147, l='MpServer', x=-232.50, y=21.00, z=53.50], EntityPlayerSP['Fifou_BE'/198, l='MpServer', x=-310.54, y=71.00, z=61.83]]
	Retry entities: 0 total; []
	Server brand: fml,forge
	Server type: Integrated singleplayer server
Stacktrace:
	at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:456)
	at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2879)
	at net.minecraft.client.Minecraft.run(Minecraft.java:465)
	at net.minecraft.client.main.Main.main(Main.java:118)
	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:135)
	at net.minecraft.launchwrapper.Launch.main(Launch.java:28)
	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.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:26)

-- System Details --
Details:
	Minecraft Version: 1.12
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_131, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 608282752 bytes (580 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
	IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
	FML: MCP 9.40 Powered by Forge 14.21.1.2443 5 mods loaded, 5 mods active
	States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
	UCHIJAAAA	minecraft{1.12} [Minecraft] (minecraft.jar) 
	UCHIJAAAA	mcp{9.19} [Minecraft Coder Pack] (minecraft.jar) 
	UCHIJAAAA	FML{8.0.99.99} [Forge Mod Loader] (forgeSrc-1.12-14.21.1.2443.jar) 
	UCHIJAAAA	forge{14.21.1.2443} [Minecraft Forge] (forgeSrc-1.12-14.21.1.2443.jar) 
	UCHIJAAAA	economy{1.2} [Mod Economy] (bin) 
	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'NVIDIA Corporation' Version: '4.5.0 NVIDIA 384.94' Renderer: 'GeForce GTX 1060 6GB/PCIe/SSE2'
	Launched Version: 1.12
	LWJGL: 2.9.4
	OpenGL: GeForce GTX 1060 6GB/PCIe/SSE2 GL version 4.5.0 NVIDIA 384.94, NVIDIA Corporation
	GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because OpenGL 3.0 is supported and separate blending is supported.
Shaders are available because OpenGL 2.1 is supported.
VBOs are available because OpenGL 1.5 is supported.

	Using VBOs: Yes
	Is Modded: Definitely; Client brand changed to 'fml,forge'
	Type: Client (map_client.txt)
	Resource Packs: 
	Current Language: English (US)
	Profiler Position: N/A (disabled)
	CPU: 8x Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz

 

I've searched many fix to counter this crash but I can't, and it's the problems, I understand that BlockState is null bu when I try some "!= null" it's not working /:

 

Thank you :/

Edited by Fifou_BE
Link to comment
Share on other sites

You don't need to check it when you're seeing an entity, right? Then before the getBlockState call, check if the target is on entity and if it is, don't do anything there( put return or similar).

Edited by Abastro
  • Like 1

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

7 minutes ago, Abastro said:

You don't need to check it when you're seeing an entity, right? Then before the getBlockState call, check if the target is on entity and if it is, don't do anything there( put return or similar).

OMG. Literraly I tried this by doing this but in one line and it was not working, It works perfectly :( I feel stupid but thx you so much !!

 

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.

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.