Permalink
Browse files

Removed ability getters in favour of createNewAbilityByType in the API.

  • Loading branch information...
iChun committed Jul 8, 2014
1 parent 11dba19 commit 040f8879f4bce5b2f9b14e5289ce2e187c896b8d
Showing with 38 additions and 114 deletions.
  1. +10 −76 src/main/java/morph/api/Ability.java
  2. +28 −38 src/main/java/morph/common/ability/AbilityHandler.java
@@ -193,82 +193,16 @@ public static boolean hasAbility(Class<? extends EntityLivingBase> entClass, Str
}
/**
* The following are helper functions to create abilities packaged with Morph.
* Use these to ability instances for mapping vanilla abilities to mobs.
* Self explanatory.
* Creates an ability by type.
* Check out AbilityHandler to see each Ability type and the parse function in their respective classes for the arguments.
* @return
*/
public static Ability getNewAbilityClimb()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityClimb").invoke(null);
} catch (Exception e) {
return null;
}
}//TODO add new abilities
public static Ability getNewAbilityFireImmunity()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFireImmunity").invoke(null);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilityFloat(float terminalVelocity, boolean negateFallDamage)
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFloat", float.class, boolean.class).invoke(null, terminalVelocity, negateFallDamage);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilityFly(boolean slowdownInWater)
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFly", boolean.class).invoke(null, slowdownInWater);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilityFly()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityFly", boolean.class).invoke(null, true);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilityHostile()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityHostile").invoke(null);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilitySunburn()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilitySunburn").invoke(null);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilitySwim(boolean canBreatheOnLand)
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilitySwim", boolean.class).invoke(null, canBreatheOnLand);
} catch (Exception e) {
return null;
}
}
public static Ability getNewAbilityWaterAllergy()
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("getNewAbilityWaterAllergy").invoke(null);
} catch (Exception e) {
return null;
}
}
public static Ability createNewAbilityByType(String type, String[] arguments)
{
try {
return (Ability)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("createNewAbilityByType", String.class, String[].class).invoke(null, type, arguments);
} catch (Exception e) {
return null;
}
}
}
@@ -143,44 +143,34 @@ public static boolean hasAbility(Class<? extends EntityLivingBase> entClass, Str
return new ArrayList<Ability>();
}
public static Ability getNewAbilityClimb()
public static Ability createNewAbilityByType(String type, String[] arguments)
{
return new AbilityClimb();
}
public static Ability getNewAbilityFireImmunity()
{
return new AbilityFireImmunity();
}
public static Ability getNewAbilityFloat(float terminalVelocity, boolean negateFallDamage)
{
return new AbilityFloat(terminalVelocity, negateFallDamage);
}
public static Ability getNewAbilityFly(boolean slowdownInWater)
{
return new AbilityFly(slowdownInWater);
}
public static Ability getNewAbilityHostile()
{
return new AbilityHostile();
}
public static Ability getNewAbilitySunburn()
{
return new AbilitySunburn();
}
public static Ability getNewAbilitySwim(boolean canBreatheOnLand)
{
return new AbilitySwim(canBreatheOnLand);
}
public static Ability getNewAbilityWaterAllergy()
{
return new AbilityWaterAllergy();
try
{
Class abilityClass = AbilityHandler.stringToClassMap.get(type);
if(abilityClass != null)
{
Ability ab = ((Ability)abilityClass.getConstructor().newInstance());
try
{
ab.parse(arguments);
}
catch(Exception e2)
{
Morph.console("Arguments are erroring when trying to create ability by type: " + abilityClass.getName() + ", "+ type + ", args: " + arguments == null ? "none" : "arg list of size " + arguments.length, true);
e2.printStackTrace();
}
}
else
{
Morph.console("Ability type \"" + type + "\" does not exist!", true);
}
}
catch(Exception e)
{
Morph.console("Error creating ability by type: " + type, true);
e.printStackTrace();
}
return null;
}
}

0 comments on commit 040f887

Please sign in to comment.