Files
Wizardry/src/main/java/electroblob/wizardry/spell/MindTrick.java
T
Electroblob77 b374f71533 The great particle refactoring part 2: Splitting and Streamlining!
- Splits all particle textures into individual files intead of sprite sheets
- Replaces arc and lightning pulse entities with particles
- Pulls particle code up to the general ParticleWizardry so behaviours such as spin can be applied to all particle types
- Renames a few ParticleBuilder methods for conciseness.
- Adds a few new particle effects to various spells and entities, with a slight tweak to EntityMagicArrow#onBlockHit to facilitate impact effects
2019-01-01 21:40:04 +00:00

105 lines
3.9 KiB
Java

package electroblob.wizardry.spell;
import electroblob.wizardry.constants.Element;
import electroblob.wizardry.constants.SpellType;
import electroblob.wizardry.constants.Tier;
import electroblob.wizardry.registry.WizardryItems;
import electroblob.wizardry.registry.WizardryPotions;
import electroblob.wizardry.registry.WizardrySounds;
import electroblob.wizardry.util.ParticleBuilder;
import electroblob.wizardry.util.ParticleBuilder.Type;
import electroblob.wizardry.util.SpellModifiers;
import electroblob.wizardry.util.WizardryUtilities;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingAttackEvent;
import net.minecraftforge.event.entity.living.LivingSetAttackTargetEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@Mod.EventBusSubscriber
public class MindTrick extends SpellRay {
private static final int BASE_DURATION = 300;
public MindTrick(){
super("mind_trick", Tier.BASIC, Element.NECROMANCY, SpellType.ATTACK, 10, 40, false, 8, WizardrySounds.SPELL_DEFLECTION);
this.soundValues(0.7f, 1, 0.4f);
}
@Override
protected boolean onEntityHit(World world, Entity target, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
if(WizardryUtilities.isLiving(target)){
if(!world.isRemote){
if(target instanceof EntityPlayer){
((EntityLivingBase)target).addPotionEffect(new PotionEffect(MobEffects.NAUSEA,
(int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade)), 0));
}else if(target instanceof EntityLiving){
((EntityLiving)target).setAttackTarget(null);
((EntityLivingBase)target).addPotionEffect(new PotionEffect(WizardryPotions.mind_trick,
(int)(BASE_DURATION * modifiers.get(WizardryItems.duration_upgrade)), 0));
}
}else{
for(int i=0; i<10; i++){
ParticleBuilder.create(Type.DARK_MAGIC, world.rand, target.posX,
target.getEntityBoundingBox().minY + target.getEyeHeight(), target.posZ, 0.25, false)
.clr(0.8f, 0.2f, 1.0f).spawn(world);
}
}
return true;
}
return false;
}
@Override
protected boolean onBlockHit(World world, BlockPos pos, EnumFacing side, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
return false;
}
@Override
protected boolean onMiss(World world, EntityLivingBase caster, int ticksInUse, SpellModifiers modifiers){
return false;
}
@SubscribeEvent
public static void onLivingAttackEvent(LivingAttackEvent event){
if(event.getSource() != null && event.getSource().getTrueSource() instanceof EntityLivingBase){
// Cancels the mind trick effect if the creature takes damage
// This has been moved to within an (event.getSource().getEntity() instanceof EntityLivingBase) check so it
// doesn't crash the game with a ConcurrentModificationException. If you think about it, mind trick only
// ought to be cancelled if something attacks the entity since potions, drowning, cacti etc. don't affect the
// targeting.
if(event.getEntityLiving().isPotionActive(WizardryPotions.mind_trick)){
event.getEntityLiving().removePotionEffect(WizardryPotions.mind_trick);
}
}
}
@SubscribeEvent
public static void onLivingSetAttackTargetEvent(LivingSetAttackTargetEvent event){
// Mind trick
// If the target is null already, no need to set it to null, or infinite loops will occur.
if((event.getEntityLiving().isPotionActive(WizardryPotions.mind_trick)
|| event.getEntityLiving().isPotionActive(WizardryPotions.fear))
&& event.getEntityLiving() instanceof EntityLiving && event.getTarget() != null){
((EntityLiving)event.getEntityLiving()).setAttackTarget(null);
}
}
}