GenuineSounds

EntityLiving Battle Text Compatibility

Jun 11th, 2012
211
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.23 KB | None | 0 0
  1. // Replace
  2. protected void damageEntity(DamageSource damageSource, int damage) {
  3.     damage = this.applyArmorCalculations(damageSource, damage);
  4.     damage = this.applyPotionDamageCalculations(damageSource, damage);
  5.     // TODO: Damage
  6.     if (BattleTextLayer.isBattleTextInstalled()) {
  7.         Entity fx = BattleTextLayer.damageFX(worldObj, damageSource, damage, this.posX, this.posY, this.posZ);
  8.         if (fx != null)
  9.             worldObj.spawnEntityInWorld(fx); /* BATTLETEXT */
  10.     }
  11.     this.health -= damage;
  12. }
  13.  
  14.  
  15. // Replace
  16. public void heal(int healing) {
  17.     if (this.health > 0) {
  18.         // TODO: Heal
  19.         if (BattleTextLayer.isBattleTextInstalled()) {
  20.             Entity fx = BattleTextLayer.healFX(this.worldObj, healing, this.posX, this.posY, this.posZ);
  21.             if (fx != null)
  22.                 worldObj.spawnEntityInWorld(fx); /* BATTLETEXT */
  23.         }
  24.         this.health += healing;
  25.         if (this.health > this.getMaxHealth())
  26.             this.health = this.getMaxHealth();
  27.         this.heartsLife = this.heartsHalvesLife / 2;
  28.     }
  29. }
  30.  
  31.  
  32.  
  33. // ------------------------------------------------------------------------------------------------
  34.  
  35. package ltd.genuine.battle;
  36.  
  37. import java.lang.reflect.Constructor;
  38. import java.lang.reflect.InvocationTargetException;
  39. import java.lang.reflect.Method;
  40.  
  41. import net.minecraft.src.Achievement;
  42. import net.minecraft.src.Block;
  43. import net.minecraft.src.DamageSource;
  44. import net.minecraft.src.Entity;
  45. import net.minecraft.src.ItemStack;
  46. import net.minecraft.src.ModLoader;
  47. import net.minecraft.src.World;
  48.  
  49. public class BattleTextLayer {
  50.  
  51.     static boolean init;
  52.  
  53.     static boolean battleTextInstalled;
  54.  
  55.     static Class genuineEntityFXText;
  56.  
  57.     static Constructor damageConstructor;
  58.  
  59.     static Constructor healConstructor;
  60.  
  61.     public static Entity damageFX(World world, DamageSource damagesource, int damage, double xPos, double yPos, double zPos) {
  62.         if (!init)
  63.             init();
  64.         if (!battleTextInstalled || genuineEntityFXText == null || damageConstructor == null)
  65.             return null;
  66.         try {
  67.             return (Entity) damageConstructor.newInstance(world, damagesource, damage, xPos, yPos, zPos);
  68.         }
  69.         catch (SecurityException e) {
  70.         }
  71.         catch (IllegalArgumentException e) {
  72.         }
  73.         catch (InstantiationException e) {
  74.         }
  75.         catch (IllegalAccessException e) {
  76.         }
  77.         catch (InvocationTargetException e) {
  78.         }
  79.         return null;
  80.     }
  81.    
  82.     public static Entity healFX(World world, int healing, double xPos, double yPos, double zPos) {
  83.         if (!init)
  84.             init();
  85.         if (!battleTextInstalled || genuineEntityFXText == null || healConstructor == null)
  86.             return null;
  87.         try {
  88.             return (Entity) healConstructor.newInstance(world, healing, xPos, yPos, zPos);
  89.         }
  90.         catch (SecurityException e) {
  91.         }
  92.         catch (IllegalArgumentException e) {
  93.         }
  94.         catch (InstantiationException e) {
  95.         }
  96.         catch (IllegalAccessException e) {
  97.         }
  98.         catch (InvocationTargetException e) {
  99.         }
  100.         return null;
  101.     }
  102.  
  103.     private static void init() {
  104.         if (init)
  105.             return;
  106.         battleTextInstalled = ModLoader.isModLoaded("[Genuine] Battle Text");
  107.         if (battleTextInstalled) {
  108.             genuineEntityFXText = findClass("GenuineEntityFXText", "net.minecraft.src.GenuineEntityFXText");
  109.             if (genuineEntityFXText != null) {
  110.                 try {
  111.                     damageConstructor = genuineEntityFXText.getConstructor(World.class, DamageSource.class, int.class, double.class, double.class, double.class);
  112.                     healConstructor = genuineEntityFXText.getConstructor(World.class, int.class, double.class, double.class, double.class);
  113.                 }
  114.                 catch (SecurityException e) {
  115.                 }
  116.                 catch (NoSuchMethodException e) {
  117.                 }
  118.             }
  119.         }
  120.         System.out.println("[Genuine] Battle Text compatibility layer was loaded and Battle Text is " + (battleTextInstalled ? "installed." : "not installed."));
  121.         init = true;
  122.     }
  123.  
  124.     public static boolean isBattleTextInstalled() {
  125.         if (!init)
  126.             init();
  127.         return battleTextInstalled;
  128.     }
  129.  
  130.     private static Class findClass(String... classNames) {
  131.         for (String name : classNames) {
  132.             try {
  133.                 return Class.forName(name);
  134.             }
  135.             catch (ClassNotFoundException e) {
  136.             }
  137.         }
  138.         return null;
  139.     }
  140.  
  141.     private static Method findMethod(Class clazz, String methodName, Class... args) {
  142.         try {
  143.             return clazz.getDeclaredMethod(methodName, args);
  144.         }
  145.         catch (SecurityException e) {
  146.         }
  147.         catch (NoSuchMethodException e) {
  148.         }
  149.         return null;
  150.     }
  151. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment