Posted July 31, 20223 yr i'm trying to make my own custom recipes using lightning, but the output item gets deleted because of the lightning how do i make that item invulnerable to the lightning? Edited July 31, 20223 yr by magic_man
July 31, 20223 yr Aren't you already listening to the EntityStruckByLightining event? You need some way to differentiate the item entities you spawned from the normal ones. One simple way might be to look at the ItemEntity's age to see if it is zero, i.e. it was just created. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr Author is it also possible to make it invulnerable for only a certain time? for example 1 second after it is spawned in?
July 31, 20223 yr Author is that done the same way as just doing it permanently or is that a whole different story also in case the problem is in my code here is the code: lightning_recipes: @Mod.EventBusSubscriber(Dist.CLIENT) public class lightning_recipes { @SubscribeEvent public static void onLightningHitItem(EntityStruckByLightningEvent event) { Entity entity = event.getEntity(); if (entity instanceof ItemEntity itemEntity) { ItemStack itemStack = itemEntity.getItem(); if (itemStack.getItem() == Items.IRON_INGOT) { System.out.println("# iron ingot is struck by lightning"); entity.remove(Entity.RemovalReason.KILLED); entity.spawnAtLocation(itemInit.ELECTRIFIED_IRON_INGOT.get()); } } } } serverevent: @Mod.EventBusSubscriber(Dist.DEDICATED_SERVER) public class serverEvent { @SubscribeEvent public static void onservertick(ServerTickEvent event) { } } Edited July 31, 20223 yr by magic_man
July 31, 20223 yr Are you really trying to handle this on the client? The event is only fired on the logical server from what I can see. See LightningBolt.tick() You should remove the Dist.CLIENT. Edited July 31, 20223 yr by warjort Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr Author removing the dist.client changes nothing the item that it has to transform into is there for a split second and then is gone
July 31, 20223 yr Quote removing the dist.client changes nothing Not for this issue, yes. But it does mean your mod won't stop working on a dedicated server. 🙂 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr Author managed to do it like this: @SubscribeEvent public static void onEntityKilled(EntityLeaveWorldEvent event) { Entity entity = event.getEntity(); if (entity instanceof ItemEntity itemEntity) { ItemStack itemStack = itemEntity.getItem(); if (itemStack.getItem() == itemInit.ELECTRIFIED_IRON_INGOT.get()) { System.out.println("# not allowed"); entity.spawnAtLocation(itemInit.ELECTRIFIED_IRON_INGOT.get()); } } } } (cancelling the event didn't work) but i have a problem that if the iron stack on eachother instead of doing every single one individually it only gives one example: you drop 16 iron ingots, a lightning strike hits it, output is still 1
July 31, 20223 yr Author i tried it but didn't really get it to work and eventually thought like: what if i just say no to it deleting it?
July 31, 20223 yr Author this worked, but this isn't the part that should cause the issue @SubscribeEvent public static void onEntityKilled(EntityLeaveWorldEvent event) { Entity entity = event.getEntity(); if (entity instanceof ItemEntity itemEntity) { ItemStack itemStack = itemEntity.getItem(); if (itemStack.getItem() == itemInit.ELECTRIFIED_IRON_INGOT.get()) { System.out.println("# not allowed"); entity.spawnAtLocation(itemInit.ELECTRIFIED_IRON_INGOT.get()); } } } } it's this that should cause it: @SubscribeEvent public static void onLightningHitItem(EntityStruckByLightningEvent event) { Entity entity = event.getEntity(); if (entity instanceof ItemEntity itemEntity) { ItemStack itemStack = itemEntity.getItem(); if (itemStack.getItem() == Items.IRON_INGOT) { System.out.println("# iron ingot is struck by lightning"); entity.remove(Entity.RemovalReason.KILLED); entity.spawnAtLocation(itemInit.ELECTRIFIED_IRON_INGOT.get()); } } } }
July 31, 20223 yr There is another way you can do this. A lightning bolt does 5 points of damage and ItemEntitys are created with health = 5 If you use an Access Transformer to make the health field public, you can modify your spawned ItemEntity so it has enough health to survive a lightning strike. The side effect might be the ItemEntity also survives other damage its not supposed to, e.g. an explosion. Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr Do you really think creating a new EntityType and writing all the code to replace spawnAtLocation() and maintain in when Mojang changes it future is simpler than modifying one value? 🙂 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr By the way, nobody answered the other question. Quote but i have a problem that if the iron stack on eachother instead of doing every single one individually it only gives one example: you drop 16 iron ingots, a lightning strike hits it, output is still 1 You should use something like (untested code): Quote entity.spawnAtLocation(new ItemStack(itemInit.ELECTRIFIED_IRON_INGOT.get(), itemStack.getCount())); Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
July 31, 20223 yr Quote There is also another approach, if the spawned item is always added by the mod itself. Item.canBeHurtBy() Yes I saw that, but I got the impression the original poster was writing something more generic from the original question. 🙂 Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
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.