29261082f1
- Adds new generic spell superclasses which aim to group spells such that duplicate code is eliminated, and functions standardised, as much as possible. - Removes numerous spell classes which are no longer required as a result of this change, and replaces them with instances of the relevant generic spell classes. - Changes the remaining spell classes to fit with the new system, mostly by having them extend the generic spell classes. - Completes the transfer of particle spawning to the ParticleBuilder system.
105 lines
4.0 KiB
Java
105 lines
4.0 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)
|
|
.colour(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);
|
|
}
|
|
}
|
|
}
|