Jump to content

[1.7.10] How to make lightning bolt deal no damage to an entity?


Recommended Posts

Posted

I have this enchantment effect on a sword, however it damages the attacker too.

How can I prevent the lightning damage to the holder?

Thanks.

 

public void func_151368_a(EntityLivingBase entLB, Entity entity, int level)
{
    	EntityLightningBolt lightning = new EntityLightningBolt(entity.worldObj, entity.posX, entity.posY, entity.posZ);
    	entity.worldObj.addWeatherEffect(lightning);
}

Posted

U should be using LivingHurtEvent, check if the damage source is a lightning and if the entity taking damage is the attacker, if it is dont damage him

Okay, I will look at it.

Posted

When I did this:

@SubscribeEvent
public void onEntityStruckByLightning(EntityStruckByLightningEvent event)
{		
	 if(((EntityLivingBase) event.entity).getHeldItem().getItem() == ExtraTools.redSword)
     {
    	 event.setCanceled(true);
     }
}

Minecraft crashed when spider I attacked was dying.

 

 

net.minecraft.util.ReportedException: Ticking entity

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:719) ~[MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:624) ~[MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) ~[integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:495) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:762) [MinecraftServer$2.class:?]

Caused by: java.lang.NullPointerException

at cz.extratools.ETEventHandler.onEntityStruckByLightning(ETEventHandler.java:17) ~[ETEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler_18_ETEventHandler_onEntityStruckByLightning_EntityStruckByLightningEvent.invoke(.dynamic) ~[?:?]

at cpw.mods.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:51) ~[ASMEventHandler.class:?]

at cpw.mods.fml.common.eventhandler.EventBus.post(EventBus.java:122) ~[EventBus.class:?]

at net.minecraftforge.event.ForgeEventFactory.onEntityStruckByLightning(ForgeEventFactory.java:142) ~[ForgeEventFactory.class:?]

at net.minecraft.entity.effect.EntityLightningBolt.onUpdate(EntityLightningBolt.java:117) ~[EntityLightningBolt.class:?]

at net.minecraft.world.World.updateEntities(World.java:1984) ~[World.class:?]

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:517) ~[WorldServer.class:?]

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:713) ~[MinecraftServer.class:?]

... 4 more

 

 

EDIT: My Forge # is 1199

EDIT2: Realised it now, the spider has no items.

EDIT3: Made it working:

@SubscribeEvent
public void onEntityStruckByLightning(EntityStruckByLightningEvent event)
{		
	 if(event.entity instanceof EntityLivingBase)
	 if(((EntityLivingBase) event.entity).getHeldItem() != null)
	 if(((EntityLivingBase) event.entity).getHeldItem().getItem() == ExtraTools.redSword)
     {
    	 event.setCanceled(true);
     }
}

Now i just need to fix the problem when someone else is in the radius and has that sword (BTW it's the only sword that you can get the enchantment on)

Posted

maybe you can add a tag to the player when he starts hitting, in the death event check for the tag and remove it, so you know who should be the one not taking damage

Posted

Thank you guys, it looks like I finally did it.

 

Is this the best soulution?

 

@SubscribeEvent
public void onEntityStruckByLightning(EntityStruckByLightningEvent event)
{		
	 if(event.entity.getUniqueID().toString().equals(((LightningBoltExtended) event.lightning.getExtendedProperties("ChargedStrikeCreator")).getCreator()))
     {
    	 event.setCanceled(true);
     }
}

 

public void func_151368_a(EntityLivingBase entLB, Entity entity, int level)
    {
    	EntityLightningBolt lightning = new EntityLightningBolt(entity.worldObj, entity.posX, entity.posY, entity.posZ);
    	entity.worldObj.addWeatherEffect(lightning);
    	lightning.registerExtendedProperties("ChargedStrikeCreator", new LightningBoltExtended());
    	LightningBoltExtended prop = (LightningBoltExtended) lightning.getExtendedProperties("ChargedStrikeCreator");
    	prop.setCreator(entLB.getUniqueID().toString());
    }

 

public class LightningBoltExtended implements IExtendedEntityProperties 
{
    public final static String subCompound = "chargedStrikeCreator";
    protected EntityLightningBolt theEntity;
    protected World theWorld;
    public String playerId;

    @Override
    public void saveNBTData(NBTTagCompound parCompound)
    {
    	NBTTagCompound compound = new NBTTagCompound();
        parCompound.setTag(subCompound, compound);
        
        compound.setString("owner", playerId);
    }

    @Override
    public void loadNBTData(NBTTagCompound parCompound)

    {
        NBTTagCompound compound = (NBTTagCompound) 
        parCompound.getTag(subCompound);
        
        playerId = parCompound.getString("owner");	        
   }

   @Override
   public void init(Entity entity, World world)
   {
        theEntity = (EntityLightningBolt)entity;
        theWorld = world;
   }
   
   public void setCreator(String creator)
   {
	   playerId = creator;
   }
   
   public String getCreator()
   {
	   return playerId;
   }
}

 

Sorry about the look of the code, I am quite messy.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So i have a forge modded aternos server that worked just fine for a month untill today it suddenly crashes most of the time giving errors and idk which mod is causing the error or its smth else here is the crash log link https://mclo.gs/gGkzGKT
    • Struggling to decipher a crash report I'm getting in a custom modpack I'm tinkering with. The crash happens on startup, but weirdly, only some of the time. It seems to be related to Steves Carts, but weirdly it only started happening recently, and I can't identify if another mod is conflicting, or why it is only happening some of the time:   java.lang.NullPointerException: Cannot invoke "net.minecraft.world.entity.player.Player.m_20202_()" because "player" is null at vswe.stevescarts.events.OverlayEventHandler.onRenderTick(OverlayEventHandler.java:24) ~[stevescarts-1.20.1-1.1.14.jar%23527!/:1.20.1-1.1.14] {re:classloading} at net.minecraftforge.eventbus.EventBus.doCastFilter(EventBus.java:260) ~[eventbus-6.0.5.jar%23127!/:?] {} at net.minecraftforge.eventbus.EventBus.lambda$addListener$11(EventBus.java:252) ~[eventbus-6.0.5.jar%23127!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%23127!/:?] {} at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%23127!/:?] {} at net.minecraftforge.event.ForgeEventFactory.onRenderTickEnd(ForgeEventFactory.java:919) ~[forge-1.20.1-47.1.106-universal.jar%23581!/:?] {re:mixin,re:classloading,pl:mixin:APP:modernfix-forge.mixins.json:perf.potential_spawns_alloc.ForgeEventFactoryMixin,pl:mixin:A} at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1148) ~[client-1.20.1-20230612.114412-srg.jar%23576!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick_render_call,xf:fml:xaerominimap:xaero_minecraftclient,xf:fml:xaeroworldmap:xaero_wm_minecraftclient,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick_render_call,xf:fml:xaerominimap:xaero_minecraftclient,xf:fml:xaeroworldmap:xaero_wm_minecraftclient,pl:mixin:A,pl:runtimedistcleaner:A} at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:718) ~[client-1.20.1-20230612.114412-srg.jar%23576!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick_render_call,xf:fml:xaerominimap:xaero_minecraftclient,xf:fml:xaeroworldmap:xaero_wm_minecraftclient,pl:runtimedistcleaner:A,re:classloading,pl:accesstransformer:B,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick,xf:fml:xaeroworldmap:xaero_wm_minecraft_runtick_render_call,xf:fml:xaerominimap:xaero_minecraftclient,xf:fml:xaeroworldmap:xaero_wm_minecraftclient,pl:mixin:A,pl:runtimedistcleaner:A} at net.minecraft.client.main.Main.main(Main.java:218) ~[minecraft-1.20.1-client.jar:?] {re:mixin,pl:runtimedistcleaner:A,re:classloading,pl:mixin:APP:flywheel.mixins.json:ClientMainMixin,pl:mixin:A,pl:runtimedistcleaner:A}     Including some extra info in case any of it is relevant^. Appreciate any ideas/advice!    
    • Try the JVM argument in this post, just sub xmx/xms numbers for what you want/need allocated.  https://www.reddit.com/r/feedthebeast/s/lzmKUNZFrG I'm having the same issue with a huge modpack using the 3 culprits to your issue.  Let me know if this helps!
    • i have been trying to  lauch a modpack and it crashes in the lauching phase   
    • nope, even the log is the exact same, i also tried with the Dimensional doors just in case and nothing.
  • Topics

×
×
  • Create New...

Important Information

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