Jump to content

[1.17.1] How to prevent lightning from creating fire


Squander

Recommended Posts

For a special one that I created
Here is the code

    @Override
    public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
        ItemStack itemStack = pPlayer.getItemInHand(pHand);
        if(itemStack.is(Items.DIAMOND)){
            LightningBolt bolt = new LightningBolt(EntityType.LIGHTNING_BOLT, pLevel);
            bolt.setPos(pPos.getX(), pPos.getY(), pPos.getZ());
            pLevel.addFreshEntity(bolt);
        }else
            pPlayer.sendMessage(new TextComponent("You have no diamond!"), Util.NIL_UUID);

        return InteractionResult.SUCCESS;
    }

 

Link to comment
Share on other sites

use LightningBolt#setVisualOnly with parm true, this will stop the LightningBolt for
damage Entities and place Fire, after that you need to call the damge function manualy,
something like:

List<Entity> entities = lightningBolt.level.getEntities(this, new AABB(this.getX() - 3.0D, this.getY() - 3.0D, this.getZ() - 3.0D, this.getX() + 3.0D, this.getY() + 6.0D + 3.0D, this.getZ() + 3.0D), Entity::isAlive);

for(Entity entity : entities) {
	if (!net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(entity, this))
		entity.thunderHit((ServerLevel)lightningBolt.level, this);
	}
}

 

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.



×
×
  • Create New...

Important Information

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