Jump to content

Minecraft crashes when I try to run code to summon a lightning bolt


Recommended Posts

Posted

I got some code from an old thread on how to summon a lightning bolt in Minecraft forge and adjusted it to where I had no errors because some functions were named different things but even after that my game still crashes.

 

Here is the code I am currently running: 

World world;
	EntityPlayer player;

	float f = 1.0f;

    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;

    double d = (double)f;

    double d1 = player.prevPosX + (player.posX - player.prevPosX) * d;
    double d2 = (player.prevPosY + (player.posY - player.prevPosY) * d + 1.6200000000000001d) - (double)player.getYOffset();
    double d3 = player.prevPosZ + (player.posZ - player.prevPosZ) * d;

    Vec3d vec1 = new Vec3d(d1, d2, d3);

    float f11 = MathHelper.cos(-f2 * 0.01745329f - 3.141593f);
    float f12 = MathHelper.sin(-f2 * 0.01745329f - 3.141593f);
    float f13 = -MathHelper.cos(-f1 * 0.01745329f);
    float f14 = MathHelper.sin(-f1 * 0.01745329f);

    float f15 = f12 * f13;
    float f16 = f14;
    float f17 = f11 * f13;

    double d11 = 5000d;

    Vec3d vec2 = vec1.addVector((double)f15 * d11, (double)f16 * d11, (double)f17 * d11);

    RayTraceResult position = world.rayTraceBlocks(vec1, vec2, false, true, true);


	public LightningBolt(String name, ToolMaterial material) 
	{
		super(material);
	
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(CreativeTabs.COMBAT);
		
		ModItems.ITEMS.add(this);
		
		if (position  != null)
		{
				if(Minecraft.getMinecraft().gameSettings.keyBindAttack.isPressed())
			{
			
			int x = position.getBlockPos().getX();
	        int y = position.getBlockPos().getY();
	        int z = position.getBlockPos().getZ();
	        
	        EntityLightningBolt lightning = new EntityLightningBolt(world, x, y, z, false);
			
			world.spawnEntity(lightning);
			
			}
		}
		
	}
	
	

	@Override
	public void registerModels() 
	{
	
		Main.proxy.registerItemRenderer(this, 0, "inventory");
		
	}

 

here is the error I am getting:

---- Minecraft Crash Report ----
// I feel sad now :(

Time: 8/14/19 9:28 PM
Description: Initializing game

java.lang.ExceptionInInitializerError
	at com.scream0228.FirstModTest.Blocks.BlockBase.<init>(BlockBase.java:25)
	at com.scream0228.FirstModTest.Blocks.RubyBlock.<init>(RubyBlock.java:12)
	at com.scream0228.FirstModTest.init.ModBlocks.<clinit>(ModBlocks.java:18)
	at com.scream0228.FirstModTest.util.handlers.RegistryHandler.onBlockRegister(RegistryHandler.java:30)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_RegistryHandler_onBlockRegister_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:777)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:628)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
	at net.minecraft.client.Minecraft.init(Minecraft.java:513)
	at net.minecraft.client.Minecraft.run(Minecraft.java:421)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)
Caused by: java.lang.NullPointerException
	at com.scream0228.FirstModTest.items.tools.LightningBolt.<init>(LightningBolt.java:38)
	at com.scream0228.FirstModTest.init.ModItems.<clinit>(ModItems.java:51)
	... 26 more


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

-- Head --
Thread: Client thread
Stacktrace:
	at com.scream0228.FirstModTest.Blocks.BlockBase.<init>(BlockBase.java:25)
	at com.scream0228.FirstModTest.Blocks.RubyBlock.<init>(RubyBlock.java:12)
	at com.scream0228.FirstModTest.init.ModBlocks.<clinit>(ModBlocks.java:18)
	at com.scream0228.FirstModTest.util.handlers.RegistryHandler.onBlockRegister(RegistryHandler.java:30)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_4_RegistryHandler_onBlockRegister_Register.invoke(.dynamic)
	at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
	at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
	at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
	at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:777)
	at net.minecraftforge.fml.common.Loader.preinitializeMods(Loader.java:628)
	at net.minecraftforge.fml.client.FMLClientHandler.beginMinecraftLoading(FMLClientHandler.java:252)
	at net.minecraft.client.Minecraft.init(Minecraft.java:513)

-- Initialization --
Details:
Stacktrace:
	at net.minecraft.client.Minecraft.run(Minecraft.java:421)
	at net.minecraft.client.main.Main.main(Main.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	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(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97)
	at GradleStart.main(GradleStart.java:25)

-- System Details --
Details:
	Minecraft Version: 1.12.2
	Operating System: Mac OS X (x86_64) version 10.14.5
	Java Version: 1.8.0_221, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 774035592 bytes (738 MB) / 1038876672 bytes (990 MB) up to 1038876672 bytes (990 MB)
	JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
	IntCache: cache: 0, tcache: 0, allocated: 0, tallocated: 0
	FML: MCP 9.42 Powered by Forge 14.23.5.2768 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

	| State | ID        | Version      | Source                           | Signature |
	|:----- |:--------- |:------------ |:-------------------------------- |:--------- |
	| UCH   | minecraft | 1.12.2       | minecraft.jar                    | None      |
	| UCH   | mcp       | 9.42         | minecraft.jar                    | None      |
	| UCH   | FML       | 8.0.99.99    | forgeSrc-1.12.2-14.23.5.2768.jar | None      |
	| UCH   | forge     | 14.23.5.2768 | forgeSrc-1.12.2-14.23.5.2768.jar | None      |
	| UCH   | fmt       | 1.0          | bin                              | None      |

	Loaded coremods (and transformers): 
	GL info: ' Vendor: 'Intel Inc.' Version: '2.1 INTEL-12.9.22' Renderer: 'Intel HD Graphics 4000 OpenGL Engine'
	Launched Version: 1.12.2
	LWJGL: 2.9.2
	OpenGL: Intel HD Graphics 4000 OpenGL Engine GL version 2.1 INTEL-12.9.22, Intel Inc.
	GL Caps: Using GL 1.3 multitexturing.
Using GL 1.3 texture combiners.
Using framebuffer objects because ARB_framebuffer_object 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: 4x Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz

 

I believe I have narrowed the error down to the top part of the code based on some commenting out some lines and trying to find the error but I have had no luck so far.

 

Here is where I believe the error is occurring:

World world;
	EntityPlayer player;
	
	float f = 1.0f;

    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;

    double d = (double)f;

    double d1 = player.prevPosX + (player.posX - player.prevPosX) * d;
    double d2 = (player.prevPosY + (player.posY - player.prevPosY) * d + 1.6200000000000001d) - (double)player.getYOffset();
    double d3 = player.prevPosZ + (player.posZ - player.prevPosZ) * d;

    Vec3d vec1 = new Vec3d(d1, d2, d3);

    float f11 = MathHelper.cos(-f2 * 0.01745329f - 3.141593f);
    float f12 = MathHelper.sin(-f2 * 0.01745329f - 3.141593f);
    float f13 = -MathHelper.cos(-f1 * 0.01745329f);
    float f14 = MathHelper.sin(-f1 * 0.01745329f);

    float f15 = f12 * f13;
    float f16 = f14;
    float f17 = f11 * f13;

    double d11 = 5000d;

    Vec3d vec2 = vec1.addVector((double)f15 * d11, (double)f16 * d11, (double)f17 * d11);

    RayTraceResult position = world.rayTraceBlocks(vec1, vec2, false, true, true);

 

If anyone is able to help that would be greatly appreciated thank you very much.

 

 

 

p.s. here is the thread I was following:  

 

 

I have already tried to ask the question on there and someone told me to start a new thread so that is what I am doing. 

 

thank you

Posted
43 minutes ago, jgp22805 said:

EntityPlayer player;

You never set the player field and a lot of other fields. Where are you calling this code? Post your whole workspace as a github repo.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
45 minutes ago, jgp22805 said:

World world;
	EntityPlayer player;

	float f = 1.0f;

    float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f;
    float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f;

    double d = (double)f;

    double d1 = player.prevPosX + (player.posX - player.prevPosX) * d;
    double d2 = (player.prevPosY + (player.posY - player.prevPosY) * d + 1.6200000000000001d) - (double)player.getYOffset();
    double d3 = player.prevPosZ + (player.posZ - player.prevPosZ) * d;

    Vec3d vec1 = new Vec3d(d1, d2, d3);

    float f11 = MathHelper.cos(-f2 * 0.01745329f - 3.141593f);
    float f12 = MathHelper.sin(-f2 * 0.01745329f - 3.141593f);
    float f13 = -MathHelper.cos(-f1 * 0.01745329f);
    float f14 = MathHelper.sin(-f1 * 0.01745329f);

    float f15 = f12 * f13;
    float f16 = f14;
    float f17 = f11 * f13;

    double d11 = 5000d;

    Vec3d vec2 = vec1.addVector((double)f15 * d11, (double)f16 * d11, (double)f17 * d11);

    RayTraceResult position = world.rayTraceBlocks(vec1, vec2, false, true, true);


	public LightningBolt(String name, ToolMaterial material) { ... }

 

What the bloody fuck is all that garbage sitting OUTSIDE ALL METHODS!?

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.

Posted
1 hour ago, jgp22805 said:

World world; EntityPlayer player; float f = 1.0f; float f1 = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * f; float f2 = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * f; double d = (double)f; double d1 = player.prevPosX + (player.posX - player.prevPosX) * d; double d2 = (player.prevPosY + (player.posY - player.prevPosY) * d + 1.6200000000000001d) - (double)player.getYOffset(); double d3 = player.prevPosZ + (player.posZ - player.prevPosZ) * d; Vec3d vec1 = new Vec3d(d1, d2, d3); float f11 = MathHelper.cos(-f2 * 0.01745329f - 3.141593f); float f12 = MathHelper.sin(-f2 * 0.01745329f - 3.141593f); float f13 = -MathHelper.cos(-f1 * 0.01745329f); float f14 = MathHelper.sin(-f1 * 0.01745329f); float f15 = f12 * f13; float f16 = f14; float f17 = f11 * f13; double d11 = 5000d; Vec3d vec2 = vec1.addVector((double)f15 * d11, (double)f16 * d11, (double)f17 * d11); RayTraceResult position = world.rayTraceBlocks(vec1, vec2, false, true, true);

All those code are not necessary. Just use ray tracing normally.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

getting rid of the code at the top stops it from crashing now because I used a combination of DavidM's and Draco18's advice by moving some of it into the method but when I play the mod the lightning doesn't work.  And what does Animefan8888 mean when they say I never set the player field or any other fields?

Posted
13 minutes ago, jgp22805 said:

And what does Animefan8888 mean when they say I never set the player field or any other fields?

Not knowing what this means only tells me that you have absolutely no idea what you are doing. You have no idea how to use a programming language. You dont know Java. Please go learn these things before learning how to make a Minecraft mod. 

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
3 minutes ago, jgp22805 said:

by field do you mean like say static final

No. It was kinda the inappropriate term I should have said variable. A field is a variable of an object.

 

3 minutes ago, jgp22805 said:

declaring variables like so?

Declaring is this.

int a;

Setting one is using the = sign to assign a value.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted (edited)

okay so I was trying to do that before I started this thread but it gave me the error cannot instantiate the type entity player I was setting EntityPlayer player to new EntityPlayer, like so,

 

EntityPlayer player = new EntityPlayer();

 

I am probably setting that wrong but throughout all of the mod tutorials that I have watched they were doing this a lot so I assumed that this is what I had to do so if I set it wrong can you please tell me what I did wrong. 

Edited by jgp22805
Posted (edited)

You can’t just create a new player.

The player in your code refers to the player who is right clicking with your item.

 

Quote

but throughout all of the mod tutorials that I have watched they were doing this a lot

I am very doubtful that tutorials did that, as creating a new instance of EntityPlayer will not work. You cannot just create a new instance of EntityPlayer and expect it to refer to the player you want.

Edited by DavidM

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

no not on the EntityPlayer just in general a lot of the variables were instantiated that way a lot of them were like:

 

 public static final ItemSword RUBY_SWORD = new ToolSword("ruby_sword", MATERIAL_RUBY);

 

but I now understand what you mean by you can't just create another player and it is referring to the player that is right-clicking

Posted

1. A variable and a field aren’t really the same thing.

2. You have to override Item#onItemRightClick and do your ray tracing and summon the lightning there.

 

Although at this point I would suggest to stop modding and learn Java first.

Modding is programming in Java.

Your current problems will be easily solved if you learn Java first, and continuing to mod without learning Java will just make you more confused.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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.