Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Replace
- protected void damageEntity(DamageSource damageSource, int damage) {
- damage = this.applyArmorCalculations(damageSource, damage);
- damage = this.applyPotionDamageCalculations(damageSource, damage);
- // TODO: Damage
- if (BattleTextLayer.isBattleTextInstalled()) {
- Entity fx = BattleTextLayer.damageFX(worldObj, damageSource, damage, this.posX, this.posY, this.posZ);
- if (fx != null)
- worldObj.spawnEntityInWorld(fx); /* BATTLETEXT */
- }
- this.health -= damage;
- }
- // Replace
- public void heal(int healing) {
- if (this.health > 0) {
- // TODO: Heal
- if (BattleTextLayer.isBattleTextInstalled()) {
- Entity fx = BattleTextLayer.healFX(this.worldObj, healing, this.posX, this.posY, this.posZ);
- if (fx != null)
- worldObj.spawnEntityInWorld(fx); /* BATTLETEXT */
- }
- this.health += healing;
- if (this.health > this.getMaxHealth())
- this.health = this.getMaxHealth();
- this.heartsLife = this.heartsHalvesLife / 2;
- }
- }
- // ------------------------------------------------------------------------------------------------
- package ltd.genuine.battle;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- import net.minecraft.src.Achievement;
- import net.minecraft.src.Block;
- import net.minecraft.src.DamageSource;
- import net.minecraft.src.Entity;
- import net.minecraft.src.ItemStack;
- import net.minecraft.src.ModLoader;
- import net.minecraft.src.World;
- public class BattleTextLayer {
- static boolean init;
- static boolean battleTextInstalled;
- static Class genuineEntityFXText;
- static Constructor damageConstructor;
- static Constructor healConstructor;
- public static Entity damageFX(World world, DamageSource damagesource, int damage, double xPos, double yPos, double zPos) {
- if (!init)
- init();
- if (!battleTextInstalled || genuineEntityFXText == null || damageConstructor == null)
- return null;
- try {
- return (Entity) damageConstructor.newInstance(world, damagesource, damage, xPos, yPos, zPos);
- }
- catch (SecurityException e) {
- }
- catch (IllegalArgumentException e) {
- }
- catch (InstantiationException e) {
- }
- catch (IllegalAccessException e) {
- }
- catch (InvocationTargetException e) {
- }
- return null;
- }
- public static Entity healFX(World world, int healing, double xPos, double yPos, double zPos) {
- if (!init)
- init();
- if (!battleTextInstalled || genuineEntityFXText == null || healConstructor == null)
- return null;
- try {
- return (Entity) healConstructor.newInstance(world, healing, xPos, yPos, zPos);
- }
- catch (SecurityException e) {
- }
- catch (IllegalArgumentException e) {
- }
- catch (InstantiationException e) {
- }
- catch (IllegalAccessException e) {
- }
- catch (InvocationTargetException e) {
- }
- return null;
- }
- private static void init() {
- if (init)
- return;
- battleTextInstalled = ModLoader.isModLoaded("[Genuine] Battle Text");
- if (battleTextInstalled) {
- genuineEntityFXText = findClass("GenuineEntityFXText", "net.minecraft.src.GenuineEntityFXText");
- if (genuineEntityFXText != null) {
- try {
- damageConstructor = genuineEntityFXText.getConstructor(World.class, DamageSource.class, int.class, double.class, double.class, double.class);
- healConstructor = genuineEntityFXText.getConstructor(World.class, int.class, double.class, double.class, double.class);
- }
- catch (SecurityException e) {
- }
- catch (NoSuchMethodException e) {
- }
- }
- }
- System.out.println("[Genuine] Battle Text compatibility layer was loaded and Battle Text is " + (battleTextInstalled ? "installed." : "not installed."));
- init = true;
- }
- public static boolean isBattleTextInstalled() {
- if (!init)
- init();
- return battleTextInstalled;
- }
- private static Class findClass(String... classNames) {
- for (String name : classNames) {
- try {
- return Class.forName(name);
- }
- catch (ClassNotFoundException e) {
- }
- }
- return null;
- }
- private static Method findMethod(Class clazz, String methodName, Class... args) {
- try {
- return clazz.getDeclaredMethod(methodName, args);
- }
- catch (SecurityException e) {
- }
- catch (NoSuchMethodException e) {
- }
- return null;
- }
- }
Advertisement