Jump to content

[1.7.10] Lightning detection


iWasHere

Recommended Posts

How can I tell when/where a lightning bolt strikes? I've tried basically all of the events relating to entity spawning, and none work. The only even relating to lightning seems to be when entities are struck by it. Does anybody have any idea of what I could do? Thanks in advance.

Link to comment
Share on other sites

EntityLightningBolt extends EntityWeatherEffect extends Entity

public EntityLightningBolt(World worldIn, double posX, double posY, double posZ)
    {
        super(worldIn);
        this.setLocationAndAngles(posX, posY, posZ, 0.0F, 0.0F);

 

Ligtning entity has x,y,z you can easily get it from EntityJoinWorldEvent with checking if entity is lightning (and ofc. side).

 

EDIT:

Whoa (post below) - I didn't know that, sry OP.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Hi

 

I'm not sure there's an easy way to do this; although EntityLightningBolt is an "Entity", it isn't treated the same as other entities.  It gets "spawned" into its own list of weather effects.  The code is in WorldServer::

 

                this.theProfiler.endStartSection("thunder");
                int i1;
                BlockPos blockpos;

                if (this.provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering())
                {
                    this.updateLCG = this.updateLCG * 3 + 1013904223;
                    i1 = this.updateLCG >> 2;
                    blockpos = this.func_175736_a(new BlockPos(k + (i1 & 15), 0, l + (i1 >> 8 & 15)));

                    if (this.func_175727_C(blockpos))
                    {
                        this.addWeatherEffect(new EntityLightningBolt(this, (double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ()));
                    }
                }

 

There is also client-side code (see S2CPacketSpawnGlobalEntity.processPacket() but I don't think it will help either.

 

I think you will probably need to use ASM+Reflection to insert your own hook in there.  That's a pretty advanced technique.

 

-TGG

 

 

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.