Jump to content

Recommended Posts

Posted

Hi,

 

So I am facing some trouble, whereby if item x is struck by lightning the item transforms into another. Basically the item is destroyed and the other item to be transformed into takes its place. I also want to do this with two items, say item a and item b are together and if they are struck by lightning (they are in the same position) they transform into another item. I have managed to do this with blocks, but only through the means of a rod, whereby on right click it summons lightning and through that code it checks if the block struck at the position is what I want it then it transforms it. But I want the block or item itself to check if it has been struck by lightning then transform. That way any lightning bolt from any source can transform it.

 

Thanks for your support :)

Posted

Hi,

 

So I am facing some trouble, whereby if item x is struck by lightning the item transforms into another. Basically the item is destroyed and the other item to be transformed into takes its place. I also want to do this with two items, say item a and item b are together and if they are struck by lightning (they are in the same position) they transform into another item. I have managed to do this with blocks, but only through the means of a rod, whereby on right click it summons lightning and through that code it checks if the block struck at the position is what I want it then it transforms it. But I want the block or item itself to check if it has been struck by lightning then transform. That way any lightning bolt from any source can transform it.

 

Thanks for your support :)

 

I'm fairly sure there is a EntityStruckByLightningEvent that gets called whenever any entity is about to be hit by lightning. In an event handler, you can check if the entity is an EntityItem and holds the specific item(s) you want, cancel the event (if you want to prevent the items from being set on fire and despawning in the next few ticks), and then do whatever you whatever logic you want. (Checking item and transforming or checking if there are 2 items and transforming, etc)

Posted

If one of the items is your own, create a class that extends

EntityItem

and overrides

Entity#onStruckByLightning

to attempt the transformation and then call the super method. Override

Item#hasCustomEntity

to return

true

and override

Item#createEntity

to create an instance of your custom

EntityItem

class at the same location as the

location

argument.

 

If none of the items are your own, subscribe to

EntityStruckByLightningEvent

and check if the entity is an

EntityItem

containing your item before attempting the transformation.

 

I explained how to do something similar (items transforming when near each other in the world) here, you can see my implementation here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • 3 weeks later...
Posted

Alright, Thanks!!! I will try the subscribe to event thing, its a really good way to handle this (pun not intended). But what if I want it if the block is struck by lightning. The problem here is that there is no BlockStruckByLightning Event, only EntityStruckByLightning. So what do I do in this case?

Posted

Alright, Thanks!!! I will try the subscribe to event thing, its a really good way to handle this (pun not intended). But what if I want it if the block is struck by lightning. The problem here is that there is no BlockStruckByLightning Event, only EntityStruckByLightning. So what do I do in this case?

 

Either spawn an entity inside the block when it's placed or suggest that Forge add a

BlockStruckByLightningEvent

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

A lightning bolt is an entity. Would Forge's EntityJoinWorldEvent give you a chance to detect each bolt, look at its coords and do your actions? I haven't traced lightning's execution far enough to see if it is spawned on that path, but it may be worth a try (or further research).

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

  • 5 years 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



×
×
  • Create New...

Important Information

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