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

Hello, I'm new to modding and have only started a few weeks ago. I'm currently trying to create a SwordItem that upons being right-clicked will summon lightning in front of the player. The problem is, when I right-click the sword it only plays the sound effects of the lightning bolt and change the sky's color for a bit. No actual lightning is being summoned.

Here is my code for the lightning functionality:

 @Override
    public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
        LightningBolt lightningBolt = EntityType.LIGHTNING_BOLT.create(world);
        if(!world.isClientSide()) {
            world.addFreshEntity(lightningBolt);
        }

        return super.use(world, player, hand);
    }

 

  • Author

I am not able to find InteractionResultHolder.sidedSuccess, I can find InteractionResultHolder. I'm currently modding on version 1.18.1 if that helps

  • Author

I've made a few changes and added a position for the bolt, but the lightning bolt is still not being rendered. The effects are taking place for example, the player takes damage and catches on fire, the sky blinks and sound effects still play but the lightning just doesn't appear. I've also added a cooldown time for fun (just to learn more methods).

@Override
    public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
        LightningBolt lightningBolt = EntityType.LIGHTNING_BOLT.create(world);
        if(!world.isClientSide) {
            world.addFreshEntity(lightningBolt);
            lightningBolt.moveTo(player.position());
            player.getCooldowns().addCooldown(this, 100);
        }

        return super.use(world, player, hand);
    }

 

  • Author

Nevermind I found the solution to the lightning not appearing. I had to summon the lightningBolt after giving the location. Thanks for helping!

  • Author
17 minutes ago, diesieben07 said:

Update to 1.18.2.

InteractionResultHolder.sidedSuccess definitely exists.

I just checked and InteractionResultHolder.sidedSuccess does exist however I am not sure as to how I would implement it. When I add it as in the code below I receive an error. Sorry for my inexperience.

@Override
    public InteractionResultHolder.sidedSuccess<ItemStack> use(Level world, Player player, InteractionHand hand) {
        LightningBolt lightningBolt = EntityType.LIGHTNING_BOLT.create(world);
        if(!world.isClientSide) {
            lightningBolt.moveTo(player.position());
            world.addFreshEntity(lightningBolt);
            player.getCooldowns().addCooldown(this, 60);
        }
        return super.use(world, player, hand);

    }

 

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.