Jump to content

LightningBolt sounds effect playing but no Lightning


Tinn

Recommended Posts

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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

    }

 

Link to comment
Share on other sites

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.