Jump to content

[1.15.2] How would I spawn a Lightning Bolt?


fieldbox

Recommended Posts

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

ย 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

ย 

ย 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

ย 

ย 

Link to comment
Share on other sites

  • 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
Link to comment
Share on other sites

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.

ย 

ย 

Link to comment
Share on other sites

  • 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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • This has been released asย 49.0.49.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
  • Topics

×
×
  • Create New...

Important Information

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