elbaslito Posted August 27, 2016 Posted August 27, 2016 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 Quote
TheMasterGabriel Posted August 27, 2016 Posted August 27, 2016 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) Quote
Choonster Posted August 27, 2016 Posted August 27, 2016 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. Quote 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.
elbaslito Posted September 14, 2016 Author Posted September 14, 2016 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? Quote
Choonster Posted September 14, 2016 Posted September 14, 2016 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 . Quote 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.
jeffryfisher Posted September 14, 2016 Posted September 14, 2016 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). Quote 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.
Losokos Posted February 22, 2022 Posted February 22, 2022 You could check for coordinates at which the lightning is struck instead... Quote
Recommended Posts
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.