From d10fd21692bad49e75a7d665005df940c91942f8 Mon Sep 17 00:00:00 2001 From: Lance5057 Date: Sat, 6 Aug 2016 21:47:17 -0500 Subject: Launch update Only a week behind... --- src/api/java/morph/api/Ability.java | 127 +++++++++++++++++++--------------- src/api/java/morph/api/Api.java | 131 ++++++++++++++++++++++-------------- 2 files changed, 155 insertions(+), 103 deletions(-) (limited to 'src/api/java/morph') diff --git a/src/api/java/morph/api/Ability.java b/src/api/java/morph/api/Ability.java index 36a75e9..266855b 100644 --- a/src/api/java/morph/api/Ability.java +++ b/src/api/java/morph/api/Ability.java @@ -15,18 +15,18 @@ import cpw.mods.fml.relauncher.SideOnly; * @author iChun * */ -public abstract class Ability +public abstract class Ability { /** * Ability parent field. Will be null for instances used in registration. Ability is then cloned and parent assigned later on. */ - private EntityLivingBase parent; + private EntityLivingBase parent; + + /** + * Flag for Ability activity. If true, tick/postRender/kill will notbe called. + */ + public boolean inactive; - /** - * Flag for Ability activity. If true, tick/postRender/kill will notbe called. - */ - public boolean inactive; - /** * Basic constructor (but you didn't really need me to tell you that ;D ) */ @@ -34,12 +34,15 @@ public abstract class Ability { parent = null; } - + /** * Function for mod mob support, with args. */ - public Ability parse(String[] args) { return this; } - + public Ability parse(String[] args) + { + return this; + } + /** * Since parent is private it needs a setter. * @param newParent @@ -48,7 +51,7 @@ public abstract class Ability { parent = ent; } - + /** * Get's the parent entity for this ability * @return Entity the ability takes effect on @@ -57,7 +60,7 @@ public abstract class Ability { return parent; } - + /** * Each ability has to return a String type. * This is used for comparison, saving, as well as construction/loading of Ability. @@ -65,60 +68,61 @@ public abstract class Ability * @return Ability type */ public abstract String getType(); - + /** * Ticks every world tick, basically an ability onUpdate, similar to Entity's onUpdate. * Will only tick if getParent() is not null. * Please remember that getParent is not necessarily a player. */ public abstract void tick(); - + /** * Called when the ability is finally removed when the parent demorphs or morphs into a state that does not have this ability type. * This will NOT be called if the parent morphs into another morph that has this type of ability. */ public abstract void kill(); - + /** * Creates a copy of this ability for use with parents. * As previously stated before the ability instance used during registration is a base so it needs to be cloned for use with parents. */ + @Override public abstract Ability clone(); - /** - * Return true for this if you need an inactive copy of this morph in-between morph states (abilities of the next morph are only swapped over when morph is complete) - * Currently used for AbilitySwim to adjust the fog render. - * @return requiresInactiveClone - */ - public boolean requiresInactiveClone() - { - return false; - } - + /** + * Return true for this if you need an inactive copy of this morph in-between morph states (abilities of the next morph are only swapped over when morph is complete) + * Currently used for AbilitySwim to adjust the fog render. + * @return requiresInactiveClone + */ + public boolean requiresInactiveClone() + { + return false; + } + /** * Saving of ability to NBTTagCompound. * Mainly used for synching Abilities between the client-server for mod mobs which do not use the API to add abilities. * The ability type (getType()) is appended to nbt before function is called. - * Not actually used. + * Not actually used. * @param NBTTagCompound saveData */ public abstract void save(NBTTagCompound tag); - + /** * Loading of ability from NBTTagCompound. * Mainly used to load custom fields from NBT. - * Not actually used. + * Not actually used. * @param NBTTagCompound saveData */ public abstract void load(NBTTagCompound tag); - + /** * Rendering to be done post-render. * EG: Used by AbilitySwim to render air bubbles whilst on land. */ @SideOnly(Side.CLIENT) public abstract void postRender(); - + /** * Icon location for ability. Can be null. * Mod's default icons are 32x32. Can be any resolution though. @@ -126,13 +130,13 @@ public abstract class Ability */ @SideOnly(Side.CLIENT) public abstract ResourceLocation getIcon(); - + @SideOnly(Side.CLIENT) public boolean entityHasAbility(EntityLivingBase living) { return true; } - + /** * Registers the ability so the mod can look up the class when attempting to load Ability save data. * Call this no later than PostInit. @@ -141,9 +145,12 @@ public abstract class Ability */ public static void registerAbility(String name, Class clz) { - try { + try + { Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("registerAbility", String.class, Class.class).invoke(null, name, clz); - } catch (Exception e) { + } + catch(final Exception e) + { } } @@ -156,14 +163,17 @@ public abstract class Ability * @param entClass * @param abilities */ - public static void mapAbilities(Class entClass, Ability...abilities) + public static void mapAbilities(Class entClass, Ability... abilities) { - try { + try + { Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("mapAbilities", Class.class, Ability[].class).invoke(null, entClass, abilities); - } catch (Exception e) { + } + catch(final Exception e) + { } } - + /** * Superman's kryptonite. * @param Entity class to remove ability from @@ -171,12 +181,15 @@ public abstract class Ability */ public static void removeAbility(Class entClass, String type) { - try { + try + { Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("removeAbility", Class.class, String.class).invoke(null, entClass, type); - } catch (Exception e) { + } + catch(final Exception e) + { } } - + /** * Checks to see if the entity class has a mapped ability type. * @param entClass @@ -185,24 +198,30 @@ public abstract class Ability */ public static boolean hasAbility(Class entClass, String type) { - try { - return (Boolean)Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("hasAbility", Class.class, String.class).invoke(null, entClass, type); - } catch (Exception e) { + try + { + return (Boolean) Class.forName("morph.common.ability.AbilityHandler").getDeclaredMethod("hasAbility", Class.class, String.class).invoke(null, entClass, type); + } + catch(final Exception e) + { return false; } } - + /** * Creates an ability by type. - * Check out AbilityHandler to see each Ability type and the parse function in their respective classes for the arguments. + * Check out AbilityHandler to see each Ability type and the parse function in their respective classes for the arguments. * @return */ - 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; - } - } + 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(final Exception e) + { + return null; + } + } } diff --git a/src/api/java/morph/api/Api.java b/src/api/java/morph/api/Api.java index 1cfb49d..a02c62f 100644 --- a/src/api/java/morph/api/Api.java +++ b/src/api/java/morph/api/Api.java @@ -9,7 +9,7 @@ import net.minecraft.util.ResourceLocation; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public final class Api +public final class Api { /** * Returns if a player is has a morph. If morph progress < 1.0F, player is mid-morphing. @@ -19,13 +19,16 @@ public final class Api */ public static boolean hasMorph(String playerName, boolean isClient) { - try { - return (Boolean)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("hasMorph", String.class, boolean.class).invoke(null, playerName, isClient); - } catch (Exception e) { + try + { + return (Boolean) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("hasMorph", String.class, boolean.class).invoke(null, playerName, isClient); + } + catch(final Exception e) + { return false; } } - + /** * Returns morph progression of a player. Time per morph is 80 ticks. * If player does not have a morph, 1.0F will be returned. @@ -34,13 +37,16 @@ public final class Api */ public static float morphProgress(String playerName, boolean isClient) { - try { - return (Float)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("morphProgress", String.class, boolean.class).invoke(null, playerName, isClient); - } catch (Exception e) { + try + { + return (Float) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("morphProgress", String.class, boolean.class).invoke(null, playerName, isClient); + } + catch(final Exception e) + { return 1.0F; } } - + /** * Returns previous entity instance used to render the morph. * If player does not have a previous morph state, null will be returned. @@ -49,9 +55,12 @@ public final class Api */ public static EntityLivingBase getPrevMorphEntity(String playerName, boolean isClient) { - try { - return (EntityLivingBase)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getPrevMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); - } catch (Exception e) { + try + { + return (EntityLivingBase) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getPrevMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); + } + catch(final Exception e) + { return null; } } @@ -64,13 +73,16 @@ public final class Api */ public static EntityLivingBase getMorphEntity(String playerName, boolean isClient) { - try { - return (EntityLivingBase)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); - } catch (Exception e) { + try + { + return (EntityLivingBase) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphEntity", String.class, boolean.class).invoke(null, playerName, isClient); + } + catch(final Exception e) + { return null; } } - + /** * Blacklists an entity from being morphed into. * Previously saved morphs of the classtype will not be removed. @@ -78,12 +90,15 @@ public final class Api */ public static void blacklistEntity(Class clz) { - try { + try + { Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("blacklistEntity", Class.class).invoke(null, clz); - } catch (Exception e) { + } + catch(final Exception e) + { } } - + /** * Forces a player to morph into an EntityLivingBase, also adds said entity to the morph list. * Called Serverside only. @@ -93,13 +108,16 @@ public final class Api */ public static boolean forceMorph(EntityPlayerMP player, EntityLivingBase living) { - try { - return (Boolean)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("forceMorph", EntityPlayerMP.class, EntityLivingBase.class).invoke(null, player, living); - } catch (Exception e) { + try + { + return (Boolean) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("forceMorph", EntityPlayerMP.class, EntityLivingBase.class).invoke(null, player, living); + } + catch(final Exception e) + { return false; } } - + /** * Forces a player to demorph. * Called Serverside only. @@ -107,12 +125,15 @@ public final class Api */ public static void forceDemorph(EntityPlayerMP player) { - try { + try + { Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("forceDemorph", EntityPlayerMP.class).invoke(null, player); - } catch (Exception e) { + } + catch(final Exception e) + { } } - + /** * Checks if the entity passed on is a Morph. * If it is, the player name will be passed, else null. @@ -121,25 +142,31 @@ public final class Api */ public static String isEntityAMorph(EntityLivingBase living, boolean isClient) { - try { - return (String)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("isEntityAMorph", EntityLivingBase.class, boolean.class).invoke(null, living, isClient); - } catch (Exception e) { + try + { + return (String) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("isEntityAMorph", EntityLivingBase.class, boolean.class).invoke(null, living, isClient); + } + catch(final Exception e) + { return null; } } - + /** * Allows the rendering of the next player rendered. * Prevents Morph from cancelling the player render event to render the morphed entity. */ public static void allowNextPlayerRender() { - try { + try + { Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("allowNextPlayerRender").invoke(null); - } catch (Exception e) { + } + catch(final Exception e) + { } } - + /** * Returns the black grainy morph skin that overlays the player when the player is morphing * @return Morph Skin Resource Location @@ -147,24 +174,30 @@ public final class Api @SideOnly(Side.CLIENT) public static ResourceLocation getMorphSkinTexture() { - try { - return (ResourceLocation)Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphSkinTexture").invoke(null); - } catch (Exception e) { + try + { + return (ResourceLocation) Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("getMorphSkinTexture").invoke(null); + } + catch(final Exception e) + { return AbstractClientPlayer.locationStevePng; } } - /** - * Assign a specific arm to a model for rendering in First Person. - * @param model Model which arm you are registering for - * @param arm The arm in a ModelRenderer form. - */ - @SideOnly(Side.CLIENT) - public static void registerArmForModel(ModelBase model, ModelRenderer arm) - { - try { - Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("registerArmForModel", ModelBase.class, ModelRenderer.class).invoke(null, model, arm); - } catch (Exception e) { - } - } + /** + * Assign a specific arm to a model for rendering in First Person. + * @param model Model which arm you are registering for + * @param arm The arm in a ModelRenderer form. + */ + @SideOnly(Side.CLIENT) + public static void registerArmForModel(ModelBase model, ModelRenderer arm) + { + try + { + Class.forName("morph.common.core.ApiHandler").getDeclaredMethod("registerArmForModel", ModelBase.class, ModelRenderer.class).invoke(null, model, arm); + } + catch(final Exception e) + { + } + } } -- cgit v1.2.3