Jump to content

Recommended Posts

Posted

I'm trying to make a Lightning Rod item to learn how to use the onItemUse method in modding. It's supposed to summon a lightning bolt when right clicked. However, when I right click with the item, it just plays the sound of a lightning bolt being summoned and doesn't spawn an actual bolt. What have I done wrong? Here's the code inside my onItemUse method.

@Override
public ActionResultType onItemUse(ItemUseContext context) {
	LightningBoltEntity bolt = new LightningBoltEntity(context.getWorld(), context.getPos().getX(), context.getPos().getY(), context.getPos().getZ(), true);
	context.getWorld().addEntity(bolt);
	return ActionResultType.PASS;
}

 

Posted

If you look at the LightningBoltEntity code, there's a lot of stuff that doesn't happen if effectOnly is true.

I've never tried doing this myself, or messed with lightning, but that's the first thing I noticed when I looked at the vanilla code.

  • Thanks 1
Posted
2 minutes ago, fieldbox said:

Ah, of course. I probably should've changed the boolean that I just made true because I had no idea what it was. Thanks!

Did that fix it? Just curious :)

 

Also, always check out what the parameters are for methods/constructors you call, never know when one of them is important, and sometimes ones that are, say, true for vanilla, mods might have to call false, so it's worth looking at. :)

Posted

You should also check whether you are on the server side via World#isRemote.

Entities should only be spawned on the server.

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
17 minutes ago, fieldbox said:

Oh, whoops, I thought it had fixed it but checking again, it hasn't. This time it just lights one block of the ground on fire and plays the sound.

The thing about LightningBoltEntities is they have to be spawned with ServerWorld::addLightningBolt

  • Thanks 1

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
11 minutes ago, DavidM said:

You should also check whether you are on the server side via World#isRemote.

Entities should only be spawned on the server.

Still doesn't work. Also, thanks for the TechnoVision and HarryTalks tips, those were the two YouTubers I was specifically using.

Posted
4 minutes ago, Animefan8888 said:

The thing about LightningBoltEntities is they have to be spawned with ServerWorld::addLightningBolt

Thanks so much! It works!

Posted (edited)
6 minutes ago, fieldbox said:

Also, thanks for the TechnoVision and HarryTalks tips, those were the two YouTubers I was specifically using.

To be honest, those two YouTubers are notorious for creating low quality tutorials with bad coding practices.

I would suggest ditching those tutorials to avoid writing problematic code.

Some good quality tutorials are https://github.com/TheGreyGhost/MinecraftByExample and https://github.com/Cadiboo/Example-Mod.

Edited by DavidM
  • Thanks 1

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.

 

 

  • 2 weeks later...
Posted (edited)
On 4/9/2020 at 9:53 PM, fieldbox said:

Thanks so much! It works!

Could you mind show the code ?  I have same problem and dunno how to solve it after I check this thread. 

 

Thank you!

 

 

PS:  I got it!!!!     

 

add  private ServerWorld world;   and using this.world.addLightningBolt(lightningBolt);

 

 

Edited by gasgas4
Posted
26 minutes ago, gasgas4 said:

add  private ServerWorld world;   and using this.world.addLightningBolt(lightningBolt);

That is not how you get an instance of the server world.

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.

 

 

  • 1 month later...

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.