Make lightning bolt count as player damage and support damage modifiers
This commit is contained in:
@@ -2,26 +2,40 @@ package electroblob.wizardry.spell;
|
|||||||
|
|
||||||
import electroblob.wizardry.Wizardry;
|
import electroblob.wizardry.Wizardry;
|
||||||
import electroblob.wizardry.item.SpellActions;
|
import electroblob.wizardry.item.SpellActions;
|
||||||
|
import electroblob.wizardry.registry.Spells;
|
||||||
|
import electroblob.wizardry.util.EntityUtils;
|
||||||
|
import electroblob.wizardry.util.MagicDamage;
|
||||||
|
import electroblob.wizardry.util.MagicDamage.DamageType;
|
||||||
import electroblob.wizardry.util.SpellModifiers;
|
import electroblob.wizardry.util.SpellModifiers;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityLivingBase;
|
import net.minecraft.entity.EntityLivingBase;
|
||||||
import net.minecraft.entity.effect.EntityLightningBolt;
|
import net.minecraft.entity.effect.EntityLightningBolt;
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.util.DamageSource;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.util.math.Vec3d;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.event.entity.EntityStruckByLightningEvent;
|
||||||
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
||||||
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
//@Mod.EventBusSubscriber
|
@Mod.EventBusSubscriber
|
||||||
public class LightningBolt extends SpellRay {
|
public class LightningBolt extends SpellRay {
|
||||||
|
|
||||||
/** The NBT key used to store the UUID of the player that summoned the lightning bolt. Used for achievements. */
|
/** The NBT key used to store the UUID of the entity that summoned the lightning bolt. */
|
||||||
public static final String NBT_KEY = "summoningPlayer";
|
public static final String SUMMONER_NBT_KEY = "summoner";
|
||||||
|
/** The NBT key used to store the damage modifier for the lightning bolt. */
|
||||||
|
public static final String DAMAGE_MODIFIER_NBT_KEY = "damageModifier";
|
||||||
|
/** An NBT key used to cancel vanilla's implementation of lightning damage; since there's no way of extracting the
|
||||||
|
* lightning bolt entity from {@code LivingAttackEvent} this has to be done using NBT. */
|
||||||
|
public static final String IMMUNE_TO_LIGHTNING_NBT_KEY = "immuneToLightning";
|
||||||
|
|
||||||
public LightningBolt(){
|
public LightningBolt(){
|
||||||
super("lightning_bolt", SpellActions.POINT, false);
|
super("lightning_bolt", SpellActions.POINT, false);
|
||||||
this.ignoreLivingEntities(true);
|
this.ignoreLivingEntities(true);
|
||||||
|
addProperties(DAMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean requiresPacket(){ return false; }
|
@Override public boolean requiresPacket(){ return false; }
|
||||||
@@ -41,17 +55,14 @@ public class LightningBolt extends SpellRay {
|
|||||||
// Bit of a hack but it works fine!
|
// Bit of a hack but it works fine!
|
||||||
boolean doFireTick = world.getGameRules().getBoolean("doFireTick");
|
boolean doFireTick = world.getGameRules().getBoolean("doFireTick");
|
||||||
if(doFireTick && !Wizardry.settings.playerBlockDamage) world.getGameRules().setOrCreateGameRule("doFireTick", "false");
|
if(doFireTick && !Wizardry.settings.playerBlockDamage) world.getGameRules().setOrCreateGameRule("doFireTick", "false");
|
||||||
EntityLightningBolt entitylightning = new EntityLightningBolt(world, pos.getX(), pos.getY(),
|
|
||||||
pos.getZ(), false);
|
EntityLightningBolt lightning = new EntityLightningBolt(world, pos.getX(), pos.getY(), pos.getZ(), false);
|
||||||
world.addWeatherEffect(entitylightning);
|
if(caster != null) lightning.getEntityData().setUniqueId(SUMMONER_NBT_KEY, caster.getUniqueID());
|
||||||
|
lightning.getEntityData().setFloat(DAMAGE_MODIFIER_NBT_KEY, modifiers.get(SpellModifiers.POTENCY));
|
||||||
|
world.addWeatherEffect(lightning);
|
||||||
|
|
||||||
// Reset doFireTick to true if it was true before
|
// Reset doFireTick to true if it was true before
|
||||||
if(doFireTick && !Wizardry.settings.playerBlockDamage) world.getGameRules().setOrCreateGameRule("doFireTick", "true");
|
if(doFireTick && !Wizardry.settings.playerBlockDamage) world.getGameRules().setOrCreateGameRule("doFireTick", "true");
|
||||||
|
|
||||||
// Code for eventhandler recognition for achievements
|
|
||||||
if(caster instanceof EntityPlayer){
|
|
||||||
NBTTagCompound entityNBT = entitylightning.getEntityData();
|
|
||||||
entityNBT.setUniqueId(NBT_KEY, caster.getUniqueID());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -65,22 +76,40 @@ public class LightningBolt extends SpellRay {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @SubscribeEvent
|
@SubscribeEvent(priority = EventPriority.LOW)
|
||||||
// public static void onEntityStruckByLightningEvent(EntityStruckByLightningEvent event){
|
public static void onEntityStruckByLightningEvent(EntityStruckByLightningEvent event){
|
||||||
//
|
|
||||||
// if(event.getLightning().getEntityData() != null && event.getLightning().getEntityData().hasUniqueId(NBT_KEY)){
|
float damageModifier = event.getLightning().getEntityData().getFloat(DAMAGE_MODIFIER_NBT_KEY);
|
||||||
//
|
|
||||||
// EntityPlayer player = (EntityPlayer)WizardryUtilities.getEntityByUUID(event.getLightning().world,
|
Entity summoner = null;
|
||||||
// event.getLightning().getEntityData().getUniqueId("summoningPlayer"));
|
|
||||||
//
|
if(event.getLightning().getEntityData().hasUniqueId(SUMMONER_NBT_KEY)){
|
||||||
// if(event.getEntity() instanceof EntityCreeper){
|
|
||||||
// WizardryAdvancementTriggers.charge_creeper.triggerFor(player);
|
summoner = EntityUtils.getEntityByUUID(event.getLightning().world,
|
||||||
// }
|
event.getLightning().getEntityData().getUniqueId(SUMMONER_NBT_KEY));
|
||||||
//
|
|
||||||
// if(event.getEntity() instanceof EntityPig){
|
if(!(summoner instanceof EntityLivingBase)) summoner = null;
|
||||||
// WizardryAdvancementTriggers.frankenstein.triggerFor(player);
|
}
|
||||||
// }
|
|
||||||
// }
|
if(damageModifier > 0 || summoner != null){
|
||||||
// }
|
|
||||||
|
DamageSource source = summoner == null ? DamageSource.LIGHTNING_BOLT
|
||||||
|
: MagicDamage.causeIndirectMagicDamage(event.getLightning(), summoner, DamageType.SHOCK);
|
||||||
|
float damage = Spells.lightning_bolt.getProperty(DAMAGE).floatValue() * damageModifier;
|
||||||
|
|
||||||
|
// Don't need DamageSafetyChecker here because this isn't an attack event
|
||||||
|
EntityUtils.attackEntityWithoutKnockback(event.getEntity(), source, damage);
|
||||||
|
event.getEntity().getEntityData().setBoolean(IMMUNE_TO_LIGHTNING_NBT_KEY, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@SubscribeEvent(priority = EventPriority.HIGHEST)
|
||||||
|
public static void onLivingAttackEvent(LivingAttackEvent event){
|
||||||
|
if(event.getEntity().getEntityData().hasKey(IMMUNE_TO_LIGHTNING_NBT_KEY)
|
||||||
|
&& event.getSource() == DamageSource.LIGHTNING_BOLT){
|
||||||
|
event.setCanceled(true);
|
||||||
|
event.getEntity().getEntityData().removeTag(IMMUNE_TO_LIGHTNING_NBT_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"chargeup": 10,
|
"chargeup": 10,
|
||||||
"cooldown": 80,
|
"cooldown": 80,
|
||||||
"base_properties": {
|
"base_properties": {
|
||||||
"range": 80
|
"range": 80,
|
||||||
|
"damage": 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user