Initial 1.11.2 update
This commit is contained in:
@@ -26,8 +26,8 @@ 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.entity.monster.SkeletonType;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.EntityDamageSource;
|
||||
|
||||
@@ -44,40 +44,47 @@ import net.minecraft.util.EntityDamageSource;
|
||||
// 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.
|
||||
* <p><i>
|
||||
* 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
|
||||
/**
|
||||
* 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.
|
||||
* <p>
|
||||
* <i> 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.
|
||||
* </i>
|
||||
* from other mods. </i>
|
||||
*
|
||||
* @see IndirectMagicDamage
|
||||
* @see IElementalDamage
|
||||
* @since Wizardry 1.1
|
||||
* @author Electroblob */
|
||||
* @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<Class<? extends Entity>, DamageType[]> immunityMapping = new HashMap<Class<? extends Entity>, DamageType[]>();
|
||||
|
||||
|
||||
private final DamageType type;
|
||||
private final boolean isRetaliatory;
|
||||
|
||||
/** A simple set of constants for the types of damage. The names are deliberately different to those in EnumElement
|
||||
* to avoid confusion. All types are classified as magic damage in the vanilla system, so witches are resistant to them. */
|
||||
|
||||
/**
|
||||
* A simple set of constants for the types of damage. The names are deliberately different to those in EnumElement
|
||||
* to avoid confusion. All types are classified as magic damage in the vanilla system, so witches are resistant to
|
||||
* them.
|
||||
*/
|
||||
public enum DamageType {
|
||||
/** Generic magic damage from the wizardry mod. Like vanilla magic damage, except it doesn't bypass armour. */
|
||||
MAGIC,
|
||||
/** Fire damage from the wizardry mod. Counts as fire damage in the vanilla system, so is blocked by any mobs that
|
||||
* are immune to fire and entities with the fire resistance effect. */
|
||||
/**
|
||||
* Fire damage from the wizardry mod. Counts as fire damage in the vanilla system, so is blocked by any mobs
|
||||
* that are immune to fire and entities with the fire resistance effect.
|
||||
*/
|
||||
FIRE,
|
||||
/** Frost (ice) damage from the wizardry mod. Snow golems, ice wraiths and ice giants are immune. */
|
||||
FROST,
|
||||
@@ -87,15 +94,17 @@ public class MagicDamage extends EntityDamageSource implements IElementalDamage
|
||||
WITHER,
|
||||
/** Poison damage from the wizardry mod. Spiders, cave spiders and undead mobs are immune. */
|
||||
POISON,
|
||||
/** [NYI] Force damage from the wizardry mod. Insubstantial creatures (ghast, shadow wraith, etc.) are immune. */
|
||||
/**
|
||||
* [NYI] Force damage from the wizardry mod. Insubstantial creatures (ghast, shadow wraith, etc.) are immune.
|
||||
*/
|
||||
FORCE,
|
||||
/** Blast damage from the wizardry mod. Affected by the blast protection enchantment. */
|
||||
BLAST,
|
||||
/** [NYI] Radiant damage from the wizardry mod. */
|
||||
RADIANT;
|
||||
}
|
||||
|
||||
static {
|
||||
|
||||
static{
|
||||
// Of course, the entities that are immune to fire already are since there's a vanilla system for that, but
|
||||
// they're included here anyway for completeness and in case anyone wants to check if an entity is immune to
|
||||
// an unspecified element for reasons other than dealing damage.
|
||||
@@ -113,6 +122,7 @@ public class MagicDamage extends EntityDamageSource implements IElementalDamage
|
||||
setEntityImmunities(EntityIceGiant.class, DamageType.FROST);
|
||||
setEntityImmunities(EntityLightningWraith.class, DamageType.SHOCK);
|
||||
setEntityImmunities(EntityShadowWraith.class, DamageType.WITHER);
|
||||
setEntityImmunities(EntityWitherSkeleton.class, DamageType.WITHER);
|
||||
setEntityImmunities(EntitySpider.class, DamageType.POISON);
|
||||
setEntityImmunities(EntitySpiderMinion.class, DamageType.POISON);
|
||||
setEntityImmunities(EntityCaveSpider.class, DamageType.POISON);
|
||||
@@ -130,35 +140,29 @@ public class MagicDamage extends EntityDamageSource implements IElementalDamage
|
||||
if(type == DamageType.FIRE) this.setFireDamage();
|
||||
if(type == DamageType.BLAST) this.setExplosion();
|
||||
}
|
||||
|
||||
/** Returns true if the given entity is immune to the given damage type according to the entity immunity mappings,
|
||||
|
||||
/**
|
||||
* Returns true if the given entity is immune to the given damage type according to the entity immunity mappings,
|
||||
* false otherwise. When you want to check for resistances, check this method rather than just checking the result
|
||||
* of attackEntityFrom, since that could return false for all sorts of reasons besides immunities. However, if you
|
||||
* don't need to know whether the damage succeeded or not, there's no point in checking this method. A common use
|
||||
* of this method is to check for immunity and if so display the "[mob] resisted [spell]" chat message. See
|
||||
* {@link electroblob.wizardry.spell.Arc Arc} for a good example of this, and also of when not to use it. */
|
||||
* don't need to know whether the damage succeeded or not, there's no point in checking this method. A common use of
|
||||
* this method is to check for immunity and if so display the "[mob] resisted [spell]" chat message. See
|
||||
* {@link electroblob.wizardry.spell.Arc Arc} for a good example of this, and also of when not to use it.
|
||||
*/
|
||||
public static boolean isEntityImmune(DamageType type, Entity entity){
|
||||
// Because Mojang, in their infinite wisdom, did not make wither skeletons their own separate class (despite the
|
||||
// fact that cave spiders are), I have to test for this manually. Realistically, no mod author would be stupid
|
||||
// enough to put two entities in one class, so this should be the only time I ever have to do this.
|
||||
if(type == DamageType.WITHER && entity instanceof EntitySkeleton
|
||||
// Don't need to check EntitySkeletonMinion separately any more because it now extends EntitySkeleton.
|
||||
&& ((EntitySkeleton)entity).getSkeletonType() == SkeletonType.WITHER){
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if(type == DamageType.FIRE && entity.isImmuneToFire()) return true;
|
||||
|
||||
|
||||
DamageType[] immunities = MagicDamage.immunityMapping.get(entity.getClass());
|
||||
|
||||
|
||||
return immunities != null && Arrays.asList(immunities).contains(type);
|
||||
}
|
||||
|
||||
|
||||
/** Registers the given type of entity as immune to all of the passed in damage types. */
|
||||
public static void setEntityImmunities(Class<? extends Entity> entityType, DamageType... immunities){
|
||||
immunityMapping.put(entityType, immunities);
|
||||
}
|
||||
|
||||
|
||||
/** Adds the passed in damage type to the list of damage types to which the given entity is immune. */
|
||||
public static void addEntityImmunity(Class<? extends Entity> entityType, DamageType immunity){
|
||||
List<DamageType> immunities = Arrays.asList(immunityMapping.get(entityType));
|
||||
@@ -169,45 +173,47 @@ public class MagicDamage extends EntityDamageSource implements IElementalDamage
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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).
|
||||
* isRetaliatory defaults to false.
|
||||
* <p>
|
||||
* 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.
|
||||
* 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).
|
||||
* {@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
|
||||
* 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).
|
||||
* <p>
|
||||
* 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.
|
||||
* 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.
|
||||
* {@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
|
||||
@@ -215,39 +221,42 @@ public class MagicDamage extends EntityDamageSource implements IElementalDamage
|
||||
* record, all this does in vanilla is make witches 85% resistant to it - but that seems kinda right anyway).
|
||||
* isRetaliatory defaults to false.
|
||||
* <p>
|
||||
* 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.
|
||||
* 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).
|
||||
* {@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).
|
||||
* <p>
|
||||
* 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.
|
||||
* 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.
|
||||
* {@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){
|
||||
public static DamageSource causeIndirectMagicDamage(Entity magic, Entity caster, DamageType type,
|
||||
boolean isRetaliatory){
|
||||
return new IndirectMagicDamage(INDIRECT_MAGIC_DAMAGE, magic, caster, type, isRetaliatory);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user