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

    • "I want to understand how complex mods with ASM transformation and coremods work, such as Xray or AntiXray. Why do they break when you simply rename packages? What features of their architecture make refactoring difficult? And what techniques are used to protect these mods? I am interested in technical aspects in order to better understand the bytecode and Forge loader system."
    • I can't figure out if you're looking for help trying to steal someone elses work, or cheat at the game....
    • Title: Why Is It So Hard to Rename and Restructure Mods Like Xray or AntiXray? 🤔 Post text: Hey everyone! I’ve been digging into Minecraft modding for a while and have one big question that I can’t figure out on my own. Maybe someone with more experience could help or give me some advice. Here’s the issue: When I take a “normal” Minecraft mod — for example, one that just adds some blocks or new items — I can easily change its structure, package names, or even rebrand it entirely. It’s straightforward. But as soon as I try this with cheat-type mods like XrayMod or AntiXray, everything falls apart. Even if I just rename the classes, refactor the packages, or hide its identity somehow, the mod either breaks or stops working properly. XrayMod in particular is proving to be a nightmare to modify without losing its core function. So my question is — why is this so much harder with cheat mods like Xray? Is there something fundamentally different about how they’re coded, loaded, or protected that prevents simple renaming or restructuring? And if so, how can I actually learn to understand someone else’s cheat mod enough to safely refactor it without breaking the core features? I’ve already been spending over two months trying to figure this out and haven’t gotten anywhere. It feels like there must be some trick or knowledge I’m missing. Would really appreciate any thoughts, tips, or references — maybe there are guides or techniques for understanding cheat-mod internals? Or if you’ve successfully “disguised” a cheat mod like Xray before, I’d love to hear how you did it. Thanks in advance for any help or discussion. ✌️
    • just started making cinamatic contect check it out on my channel or check out my facebook page    Humbug City Minecraft Youtube https://www.youtube.com/watch?v=v2N6OveKwno https://www.facebook.com/profile.php?id=61575866982337  
    • Where did you get the schematic? Source/Link? And do use an own modpack or a pre-configured from curseforge? If yes, which one On a later time, I can make some tests on my own - but I need the schematic and the modpack name
  • Topics

×
×
  • Create New...

Important Information

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