Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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;
}

 

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.

  • Author

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

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. :)

  • Author

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.

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.

 

 

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

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.

  • Author
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.

  • Author
4 minutes ago, Animefan8888 said:

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

Thanks so much! It works!

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

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

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...
On 4/23/2020 at 3:52 PM, DavidM said:

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

How would you do that???

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.