package electroblob.wizardry.util; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import electroblob.wizardry.entity.living.EntityBlazeMinion; import electroblob.wizardry.entity.living.EntityIceGiant; import electroblob.wizardry.entity.living.EntityIceWraith; import electroblob.wizardry.entity.living.EntityLightningWraith; import electroblob.wizardry.entity.living.EntityPhoenix; import electroblob.wizardry.entity.living.EntityShadowWraith; import electroblob.wizardry.entity.living.EntitySkeletonMinion; import electroblob.wizardry.entity.living.EntitySpiderMinion; import electroblob.wizardry.entity.living.EntityStormElemental; import electroblob.wizardry.entity.living.EntityZombieMinion; import net.minecraft.entity.Entity; import net.minecraft.entity.boss.EntityDragon; import net.minecraft.entity.boss.EntityWither; import net.minecraft.entity.monster.EntityBlaze; import net.minecraft.entity.monster.EntityCaveSpider; import net.minecraft.entity.monster.EntityGhast; import net.minecraft.entity.monster.EntityMagmaCube; import net.minecraft.entity.monster.EntityPigZombie; import net.minecraft.entity.monster.EntitySkeleton; import net.minecraft.entity.monster.EntitySnowman; import net.minecraft.entity.monster.EntitySpider; import net.minecraft.entity.monster.EntityWitherSkeleton; import net.minecraft.entity.monster.EntityZombie; import net.minecraft.util.DamageSource; import net.minecraft.util.EntityDamageSource; // A note on the use of the vanilla damagesources: // When using indirect damage sources, the SECOND argument is the original entity (i.e. the caster), and the // FIRST argument is the actual projectile or whatever that does the damage. getEntity() will return // the original entity, and getSourceOfDamage() will return the projectile. // The vanilla approach to damage types is inconsistent, to say the least. Poison is simply 'magic', and relies on // EntityLivingBase.isPotionApplicable to determine whether an entity is affected or not. Wither, on the other hand, is // its own damage type, but again relies on the potion to determine what is immune (which in vanilla is nothing). Fire // has a proper implementation of course, with both block-based and projectile-based types, and any other damagesource // can also be designated as fire damage with setFireDamage(). Likewise, projectile and explosion damage can also be // applied to any damagesource, but these aren't considered types in their own right; rather, they seem to be damage // type 'attributes'. This is my attempt to collect all of these into a reasonably coherent system. /** * As of wizardry 1.1, this class has replaced the damagesource-related methods in WizardryUtilities, allowing a * {@link DamageType} to be specified with the damage. The main reason for this is so that damage sources can fit with * the vanilla behaviour on armour enchantments and such like whilst still being classified as wizardry damage for the * purposes of friendly fire, etc. *
* In the future, there is scope for an entirely standalone mod based on this idea. Perhaps 'Elemental Damage' could
* be a config-only mod which allows its users to define any number of specific damage types, then give any creature a
* resistance, immunity or vulnerability to each, as well as being able to specify the sources for each type, such as
* enchantments, potions, specific items, certain entities, even particular situations and string damagesource names
* from other mods.
*
* @see IndirectMagicDamage
* @see IElementalDamage
* @since Wizardry 1.1
* @author Electroblob
*/
public class MagicDamage extends EntityDamageSource implements IElementalDamage {
/** The name of the damagesource for direct magic damage from the wizardry mod. */
public static final String DIRECT_MAGIC_DAMAGE = "wizardryMagic";
/** The name of the damagesource for indirect magic damage from the wizardry mod. */
public static final String INDIRECT_MAGIC_DAMAGE = "indirectWizardryMagic";
// Technically, I don't need to specify that the classes in this map must extend entity, but it's good practice to.
private static final Map
* Now that this is its own class, this static method is largely redundant, but it's not worth refactoring the
* entire mod just to get rid of this method and use the constructor instead.
*
* @param caster The player or other living entity causing the damage
* @param type The type that this damage belongs to; used for resistances and wand perks. Use
* {@link DamageType#MAGIC} for regular, non-elemental magic damage (sometimes you might not want an element
* even though the spell has one - for example, not all necromancy spells are 'withery', so some of them
* might reasonably affect creatures that are ususally immune to wither effects).
* @return A damagesource object of type EntityDamageSource
*/
public static DamageSource causeDirectMagicDamage(Entity caster, DamageType type){
return causeDirectMagicDamage(caster, type, false);
}
/**
* Returns a DamageSource called "wizardryMagic" with the given entity as the caster. Use in preference to vanilla
* types to allow things to distinguish between magic and regular melee/swords. Unlike DamageSource.MAGIC, it does
* not bypass armour and has a player as the source (rather than nothing). It is still classed as magic damage (for
* the record, all this does in vanilla is make witches 85% resistant to it - but that seems kinda right anyway).
*
* Now that this is its own class, this static method is largely redundant, but it's not worth refactoring the
* entire mod just to get rid of this method and use the constructor instead.
*
* @param caster The player or other living entity causing the damage
* @param type The type that this damage belongs to; used for resistances and wand perks. Use
* {@link DamageType#MAGIC} for regular, non-elemental magic damage (sometimes you might not want an element
* even though the spell has one - for example, not all necromancy spells are 'withery', so some of them
* might reasonably affect creatures that are ususally immune to wither effects).
* @param isRetaliatory whether this damage source came from a retaliatory attack; prevents infinite loops occurring
* when two entities damage each other with retaliatory effects.
* @return A damagesource object of type EntityDamageSource
*/
public static DamageSource causeDirectMagicDamage(Entity caster, DamageType type, boolean isRetaliatory){
return new MagicDamage(DIRECT_MAGIC_DAMAGE, caster, type, isRetaliatory);
}
/**
* Returns a DamageSource called "indirectWizardryMagic" with the player as the caster. Use in preference to vanilla
* types to allow things to distinguish between magic and regular arrows/throwables. Unlike
* DamageSource.causeIndirectMagicDamage, it does not bypass armour. It is still classed as magic damage (for the
* record, all this does in vanilla is make witches 85% resistant to it - but that seems kinda right anyway).
* isRetaliatory defaults to false.
*
* Now that this is its own class, this static method is largely redundant, but it's not worth refactoring the
* entire mod just to get rid of this method and use the constructor instead.
*
* @param magic The entity that actually caused the damage
* @param caster The player or other living entity that cast the spell originally
* @param type The type that this damage belongs to; used for resistances and wand perks. Use
* {@link DamageType#MAGIC} for regular, non-elemental magic damage (sometimes you might not want an element
* even though the spell has one - for example, not all necromancy spells are 'withery', so some of them
* might reasonably affect creatures that are ususally immune to wither effects).
* @return A damagesource object of type EntityDamageSourceIndirect
*/
public static DamageSource causeIndirectMagicDamage(Entity magic, Entity caster, DamageType type){
return causeIndirectMagicDamage(magic, caster, type, false);
}
/**
* Returns a DamageSource called "indirectWizardryMagic" with the player as the caster. Use in preference to vanilla
* types to allow things to distinguish between magic and regular arrows/throwables. Unlike
* DamageSource.causeIndirectMagicDamage, it does not bypass armour. It is still classed as magic damage (for the
* record, all this does in vanilla is make witches 85% resistant to it - but that seems kinda right anyway).
*
* Now that this is its own class, this static method is largely redundant, but it's not worth refactoring the
* entire mod just to get rid of this method and use the constructor instead.
*
* @param magic The entity that actually caused the damage
* @param caster The player or other living entity that cast the spell originally
* @param type The type that this damage belongs to; used for resistances and wand perks. Use
* {@link DamageType#MAGIC} for regular, non-elemental magic damage (sometimes you might not want an element
* even though the spell has one - for example, not all necromancy spells are 'withery', so some of them
* might reasonably affect creatures that are ususally immune to wither effects).
* @param isRetaliatory whether this damage source came from a retaliatory attack; prevents infinite loops occurring
* when two entities damage each other with retaliatory effects.
* @return A damagesource object of type EntityDamageSourceIndirect
*/
public static DamageSource causeIndirectMagicDamage(Entity magic, Entity caster, DamageType type,
boolean isRetaliatory){
return new IndirectMagicDamage(INDIRECT_MAGIC_DAMAGE, magic, caster, type, isRetaliatory);
}
@Override
public DamageType getType(){
return type;
}
@Override
public boolean isRetaliatory(){
return isRetaliatory;
}
}