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 tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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