Browse Source

moved custom damage system to snuvi script

Kajetan Johannes Hammerle 4 years ago
parent
commit
39a3a6bafc

+ 0 - 40
src/main/java/me/km/DamageUtils.java

@@ -1,40 +0,0 @@
-package me.km;
-
-import net.minecraft.entity.LivingEntity;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.CompoundNBT;
-import net.minecraft.util.DamageSource;
-
-public class DamageUtils 
-{
-    public static void init()
-    {
-        DamageSource.IN_FIRE.setMagicDamage();
-        DamageSource.LIGHTNING_BOLT.setMagicDamage();
-        DamageSource.ON_FIRE.setMagicDamage();
-        DamageSource.HOT_FLOOR.setMagicDamage();
-        DamageSource.WITHER.setMagicDamage();
-        DamageSource.DRAGON_BREATH.setMagicDamage();
-        
-        // Special
-        DamageSource.LAVA.setDamageBypassesArmor().setDamageIsAbsolute();
-        DamageSource.IN_WALL.setDamageIsAbsolute();
-        DamageSource.CRAMMING.setDamageIsAbsolute();
-        DamageSource.DROWN.setDamageIsAbsolute();
-        DamageSource.GENERIC.setDamageIsAbsolute();
-    }
-    
-    public static int getMagicDefense(LivingEntity liv)
-    {
-        int level = 0;
-        for(ItemStack stack : liv.getArmorInventoryList())
-        {
-            CompoundNBT com = stack.getTag();
-            if(com != null && com.contains("magic"))
-            {
-                level += com.getInt("magic");
-            }
-        }
-        return level;
-    }
-}

+ 0 - 2
src/main/java/me/km/KajetansMod.java

@@ -37,8 +37,6 @@ public class KajetansMod
         DeferredWorkQueue.runLater(() -> ModPacketHandler.init());
         ModWorldGeneration.register();
         
-        DamageUtils.init();
-        
         MinecraftForge.EVENT_BUS.register(new CommonEvents());
     }
     

+ 3 - 1
src/main/java/me/km/blocks/BlockGravelSlab.java

@@ -52,15 +52,17 @@ public class BlockGravelSlab extends SlabBlock
         if(w.isAirBlock(pos.down()) || canFallThrough(w.getBlockState(pos.down())) && pos.getY() >= 0)
         {
             BlockState fallState;
+            double y = pos.getY();
             if(state == getDefaultState().with(TYPE, SlabType.TOP))    
             {
                 fallState = w.getBlockState(pos).with(TYPE, SlabType.BOTTOM);
+                y += 0.5;
             }
             else
             {
                 fallState = w.getBlockState(pos);
             }
-            FallingBlockEntity fallingblockentity = new FallingBlockEntity(w, pos.getX() + 0.5, pos.getY(), pos.getZ() + 0.5, fallState);
+            FallingBlockEntity fallingblockentity = new FallingBlockEntity(w, pos.getX() + 0.5, y, pos.getZ() + 0.5, fallState);
             w.addEntity(fallingblockentity);
         }
     }

+ 0 - 61
src/main/java/me/km/events/CustomEventCaller.java

@@ -3,16 +3,8 @@ package me.km.events;
 import java.util.HashMap;
 import java.util.LinkedList;
 import me.hammerle.snuviscript.code.Script;
-import me.km.DamageUtils;
 import me.km.scheduler.SnuviScheduler;
-import me.km.utils.ReflectionUtils;
-import net.minecraft.entity.LivingEntity;
-import net.minecraft.entity.SharedMonsterAttributes;
 import net.minecraft.server.MinecraftServer;
-import net.minecraft.util.CombatRules;
-import net.minecraft.util.DamageSource;
-import net.minecraftforge.event.entity.living.LivingHurtEvent;
-import net.minecraftforge.eventbus.api.EventPriority;
 import net.minecraftforge.eventbus.api.SubscribeEvent;
 import net.minecraftforge.event.TickEvent;
 
@@ -84,57 +76,4 @@ public class CustomEventCaller
             }
         }
     } 
-    
-    private float getRealDamage(float damageAmount, DamageSource ds, LivingEntity liv)
-    {
-        if(ds != DamageSource.LAVA && ds != DamageSource.IN_WALL && ds != DamageSource.CRAMMING && ds != DamageSource.DROWN)
-        {
-            if(ds.isMagicDamage() && !ds.isDamageAbsolute()) // Magic Damage
-            {
-                ReflectionUtils.damageArmor(liv, damageAmount);
-                int armor = DamageUtils.getMagicDefense(liv);
-                damageAmount = CombatRules.getDamageAfterAbsorb(damageAmount, armor, 0);
-            }
-            else if(!ds.isUnblockable())
-            {
-                ReflectionUtils.damageArmor(liv, damageAmount);
-                int armor = liv.getTotalArmorValue();
-                damageAmount = CombatRules.getDamageAfterAbsorb(damageAmount, armor, (float) liv.getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getValue());
-            }           
-            damageAmount = ReflectionUtils.applyPotionDamageCalculations(liv, ds, damageAmount);
-        }
-        else
-        {
-            damageAmount = liv.getMaxHealth() / 10;
-        }
-        return damageAmount;
-    }
-    
-    @SubscribeEvent(priority = EventPriority.LOWEST)
-    public void newDamageSystem(LivingHurtEvent e)
-    {         
-        // ---------------------------------------------------------------------
-        // injection of new damage system
-        // ---------------------------------------------------------------------
-        if(!e.isCanceled())
-        {
-            e.setCanceled(true);
-
-            DamageSource ds = e.getSource();
-            LivingEntity liv = e.getEntityLiving();
-
-            float damageAmount = getRealDamage(e.getAmount(), ds, liv);
-            float f = damageAmount;
-            damageAmount = Math.max(damageAmount - liv.getAbsorptionAmount(), 0.0f);
-            liv.setAbsorptionAmount(liv.getAbsorptionAmount() - (f - damageAmount));
-
-            if(damageAmount != 0.0f)
-            {
-                float f1 = liv.getHealth();
-                liv.setHealth(f1 - damageAmount);
-                liv.getCombatTracker().trackDamage(ds, f1, damageAmount);
-                liv.setAbsorptionAmount(liv.getAbsorptionAmount() - damageAmount);
-            }
-        }
-    }
 }

+ 133 - 75
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -115,6 +115,7 @@ import net.minecraft.server.management.PlayerList;
 import net.minecraft.server.management.ProfileBanEntry;
 import net.minecraft.state.IProperty;
 import net.minecraft.state.properties.ChestType;
+import net.minecraft.stats.Stats;
 import net.minecraft.tags.BlockTags;
 import net.minecraft.tags.ItemTags;
 import net.minecraft.tags.Tag;
@@ -475,10 +476,15 @@ public class MinecraftFunctions
         sm.registerAlias("player.setspawn", "player.setbedspawn");
         sm.registerFunction("player.damageitem", (sc, in) -> 
         {   
-            PlayerEntity p =(PlayerEntity) in[0].get(sc);
+            PlayerEntity p = (PlayerEntity) in[0].get(sc);
             p.getHeldItemMainhand().damageItem(in[1].getInt(sc), p, (c) -> {}); 
             return Void.TYPE; 
         });
+        sm.registerFunction("player.damagearmor", (sc, in) -> 
+        {   
+            ((PlayerEntity) in[0].get(sc)).inventory.damageArmor(in[1].getFloat(sc));
+            return Void.TYPE; 
+        });
         sm.registerFunction("player.openenderchest", (sc, in) -> 
         {   
             PlayerEntity p1 = (PlayerEntity) in[0].get(sc);
@@ -1134,59 +1140,18 @@ public class MinecraftFunctions
         // ---------------------------------------------------------------------    
         // damage stuff
         // ---------------------------------------------------------------------  
-        sm.registerFunction("damage.ismagic", (sc, in) -> 
-        {
-            DamageSource ds = ((DamageSource) in[0].get(sc));
-            return ds.isMagicDamage() && !ds.isDamageAbsolute();
-        });   
-        sm.registerFunction("damage.isphysical", (sc, in) -> 
-        {
-            DamageSource ds = ((DamageSource) in[0].get(sc));
-            return (!ds.isMagicDamage() || ds.isDamageAbsolute()) && !ds.isUnblockable();
-        });   
+        sm.registerFunction("damage.getimmediatesource", (sc, in) -> ((DamageSource) in[0].get(sc)).getImmediateSource());   
+        sm.registerFunction("damage.gettruesource", (sc, in) -> ((DamageSource) in[0].get(sc)).getTrueSource());   
+        sm.registerFunction("damage.iscreativeplayer", (sc, in) -> ((DamageSource) in[0].get(sc)).isCreativePlayer()); 
+        sm.registerFunction("damage.isabsolute", (sc, in) -> ((DamageSource) in[0].get(sc)).isDamageAbsolute()); 
+        sm.registerFunction("damage.isdifficultyscaled", (sc, in) -> ((DamageSource) in[0].get(sc)).isDifficultyScaled()); 
+        sm.registerFunction("damage.isexplosion", (sc, in) -> ((DamageSource) in[0].get(sc)).isExplosion()); 
+        sm.registerFunction("damage.isfireDamage", (sc, in) -> ((DamageSource) in[0].get(sc)).isFireDamage()); 
+        sm.registerFunction("damage.isunblockable", (sc, in) -> ((DamageSource) in[0].get(sc)).isMagicDamage()); 
+        sm.registerFunction("damage.ismagic", (sc, in) -> ((DamageSource) in[0].get(sc)).isProjectile()); 
+        sm.registerFunction("damage.isunblockable", (sc, in) -> ((DamageSource) in[0].get(sc)).isUnblockable()); 
         sm.registerFunction("damage.gettype", (sc, in) -> ((DamageSource) in[0].get(sc)).getDamageType()); 
-
-        // ---------------------------------------------------------------------    
-        // entity commands
-        // ---------------------------------------------------------------------  
-        sm.registerFunction("entity.setburning", (sc, in) -> 
-        {
-            
-            ((Entity) in[0].get(sc)).setFire(in[1].getInt(sc));
-            return Void.TYPE; 
-        });  
-        sm.registerFunction("entity.isburning", (sc, in) -> ((Entity) in[0].get(sc)).isBurning());  
-        sm.registerFunction("entity.getlook", (sc, in) -> 
-        {
-            Object[] o = new Object[3];
-            Vec3d v = ((Entity) in[0].get(sc)).getLookVec();
-            o[0] = v.x;
-            o[1] = v.y;
-            o[2] = v.z;
-            return o;
-        });  
-        sm.registerFunction("entity.getlocation", (sc, in) -> new Location((Entity) in[0].get(sc)));   
-        sm.registerFunction("entity.damage", (sc, in) -> 
-        { 
-            if(in.length >= 3)
-            {
-                ((LivingEntity) in[0].get(sc)).attackEntityFrom((DamageSource) in[2].get(sc), in[1].getFloat(sc));
-                return Void.TYPE; 
-            }
-            ((LivingEntity) in[0].get(sc)).attackEntityFrom(DamageSource.GENERIC, in[1].getFloat(sc));
-            return Void.TYPE; 
-        }); 
-        sm.registerFunction("entity.fromsource", (sc, in) -> 
-        { 
-            DamageSource ds = (DamageSource) in[0].get(sc);
-            Entity ent = ds.getTrueSource();
-            if(ent == null)
-            {
-                return ds.getImmediateSource();
-            }
-            return ent;
-        });
-        sm.registerFunction("entity.getdamagesource", (sc, in) -> 
+        sm.registerFunction("damage.get", (sc, in) -> 
         { 
             Object o = in[0].get(sc);
             if(o instanceof LivingEntity)
@@ -1235,30 +1200,114 @@ public class MinecraftFunctions
 
             switch(o.toString())
             {
-                case "IN_FIRE": return DamageSource.IN_FIRE;
-                case "LIGHTNING_BOLT": return DamageSource.LIGHTNING_BOLT;
-                case "ON_FIRE": return DamageSource.ON_FIRE;
-                case "LAVA": return DamageSource.LAVA;
-                case "HOT_FLOOR": return DamageSource.HOT_FLOOR;
-                case "IN_WALL": return DamageSource.IN_WALL;
-                case "CRAMMING": return DamageSource.CRAMMING;
-                case "DROWN": return DamageSource.DROWN;
-                case "STARVE": return DamageSource.STARVE;
-                case "CACTUS": return DamageSource.CACTUS;
-                case "FALL": return DamageSource.FALL;
-                case "FLY_INTO_WALL": return DamageSource.FLY_INTO_WALL;
-                case "OUT_OF_WORLD": return DamageSource.OUT_OF_WORLD;
-                case "GENERIC": return DamageSource.GENERIC;
-                case "MAGIC": return DamageSource.MAGIC;
-                case "WITHER": return DamageSource.WITHER;
-                case "ANVIL": return DamageSource.ANVIL;
-                case "FALLING_BLOCK": return DamageSource.FALLING_BLOCK;
-                case "DRAGON_BREATH": return DamageSource.DRAGON_BREATH;
-                case "FIREWORKS": return DamageSource.FIREWORKS;
-                case "THORNS": return DamageSource.causeThornsDamage((Entity) in[1].get(sc));
+                case "inFire": return DamageSource.IN_FIRE;
+                case "lightningBolt": return DamageSource.LIGHTNING_BOLT;
+                case "onFire": return DamageSource.ON_FIRE;
+                case "lava": return DamageSource.LAVA;
+                case "hotFloor": return DamageSource.HOT_FLOOR;
+                case "inWall": return DamageSource.IN_WALL;
+                case "cramming": return DamageSource.CRAMMING;
+                case "drown": return DamageSource.DROWN;
+                case "starve": return DamageSource.STARVE;
+                case "cactus": return DamageSource.CACTUS;
+                case "fall": return DamageSource.FALL;
+                case "flyIntoWall": return DamageSource.FLY_INTO_WALL;
+                case "outOfWorld": return DamageSource.OUT_OF_WORLD;
+                case "generic": return DamageSource.GENERIC;
+                case "magic": return DamageSource.MAGIC;
+                case "wither": return DamageSource.WITHER;
+                case "anvil": return DamageSource.ANVIL;
+                case "fallingBlock": return DamageSource.FALLING_BLOCK;
+                case "dragonBreath": return DamageSource.DRAGON_BREATH;
+                case "fireworks": return DamageSource.FIREWORKS;
+                case "dryout": return DamageSource.DRYOUT;
+                case "sweetBerryBush": return DamageSource.SWEET_BERRY_BUSH;
+                case "thorns": return DamageSource.causeThornsDamage((Entity) in[1].get(sc));
             }
             return DamageSource.GENERIC;
         });
+
+        // ---------------------------------------------------------------------    
+        // entity commands
+        // ---------------------------------------------------------------------  
+        sm.registerFunction("entity.getarmorthoughness", (sc, in) -> ((LivingEntity) in[0].get(sc)).getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getValue());
+        sm.registerFunction("entity.getarmor", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getTotalArmorValue()); 
+        sm.registerFunction("entity.getmagicarmor", (sc, in) -> 
+        {
+            int level = 0;
+            for(ItemStack stack : ((LivingEntity) in[0].get(sc)).getArmorInventoryList())
+            {
+                CompoundNBT com = stack.getTag();
+                if(com != null && com.contains("magic"))
+                {
+                    level += com.getInt("magic");
+                }
+            }
+            return level;
+        }); 
+        sm.registerFunction("entity.getenchantmentmodifier", (sc, in) -> EnchantmentHelper.getEnchantmentModifierDamage(((LivingEntity) in[0].get(sc)).getArmorInventoryList(), (DamageSource) in[1].get(sc)));
+        sm.registerFunction("entity.setburning", (sc, in) -> 
+        {
+            ((Entity) in[0].get(sc)).setFire(in[1].getInt(sc));
+            return Void.TYPE; 
+        });  
+        sm.registerFunction("entity.isburning", (sc, in) -> ((Entity) in[0].get(sc)).isBurning());  
+        sm.registerFunction("entity.getlook", (sc, in) -> 
+        {
+            Object[] o = new Object[3];
+            Vec3d v = ((Entity) in[0].get(sc)).getLookVec();
+            o[0] = v.x;
+            o[1] = v.y;
+            o[2] = v.z;
+            return o;
+        });  
+        sm.registerFunction("entity.getlocation", (sc, in) -> new Location((Entity) in[0].get(sc)));   
+        sm.registerFunction("entity.damage", (sc, in) -> 
+        { 
+            if(in.length >= 3)
+            {
+                ((LivingEntity) in[0].get(sc)).attackEntityFrom((DamageSource) in[2].get(sc), in[1].getFloat(sc));
+                return Void.TYPE; 
+            }
+            ((LivingEntity) in[0].get(sc)).attackEntityFrom(DamageSource.GENERIC, in[1].getFloat(sc));
+            return Void.TYPE; 
+        }); 
+        sm.registerFunction("entity.damagedirect", (sc, in) -> 
+        { 
+            LivingEntity liv = (LivingEntity) in[0].get(sc);
+            float damageAmount = in[1].getFloat(sc);
+            DamageSource ds = (DamageSource) in[2].get(sc);
+            if(!liv.isInvulnerableTo(ds))
+            {
+                float f2 = Math.max(damageAmount - liv.getAbsorptionAmount(), 0.0F);
+                liv.setAbsorptionAmount(liv.getAbsorptionAmount() - (damageAmount - f2));
+                float absorbedDamage = damageAmount - f2;
+                if(absorbedDamage > 0.0f && absorbedDamage < 3.4028235E37f && ds.getTrueSource() instanceof ServerPlayerEntity)
+                {
+                    ((ServerPlayerEntity) ds.getTrueSource()).addStat(Stats.DAMAGE_DEALT_ABSORBED, Math.round(absorbedDamage * 10.0f));
+                }
+
+                if(f2 > 0.0f)
+                {
+                    float f1 = liv.getHealth();
+                    liv.getCombatTracker().trackDamage(ds, f1, f2);
+                    liv.setHealth(f1 - f2);
+                    liv.setAbsorptionAmount(liv.getAbsorptionAmount() - f2);
+                }
+            }
+            return Void.TYPE; 
+        });
+        sm.registerFunction("entity.fromsource", (sc, in) -> 
+        { 
+            DamageSource ds = (DamageSource) in[0].get(sc);
+            Entity ent = ds.getTrueSource();
+            if(ent == null)
+            {
+                return ds.getImmediateSource();
+            }
+            return ent;
+        });
+        sm.registerAlias("damage.get", "entity.getdamagesource");
         sm.registerFunction("entity.gethealth", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getHealth());     
         sm.registerFunction("entity.sethealth", (sc, in) -> 
         { 
@@ -1431,7 +1480,11 @@ public class MinecraftFunctions
             ((LivingEntity) in[0].get(sc)).clearActivePotions();
             return Void.TYPE; 
         });
-        sm.registerFunction("entity.haseffect", (sc, in) -> ((LivingEntity) in[0].get(sc)).isPotionActive(Mapper.getPotion(in[1].getString(sc))));
+        sm.registerFunction("entity.geteffectamplifier", (sc, in) -> 
+        {
+            EffectInstance effect = ((LivingEntity) in[0].get(sc)).getActivePotionEffect(Mapper.getPotion(in[1].getString(sc)));
+            return effect == null ? 0 : effect.getAmplifier() + 1;
+        });
         sm.registerFunction("entity.explode", (sc, in) -> 
         { 
             ((CreeperEntity) in[0].get(sc)).ignite(); 
@@ -2458,6 +2511,11 @@ public class MinecraftFunctions
             scheduler.scheduleTask(() -> Server.executeCommand(s)); 
             return Void.TYPE;
         });
+        sm.registerFunction("isplayer", (sc, in) -> 
+        {
+            Object o = in[0].get(sc);
+            return o != null && o instanceof PlayerEntity;
+        });  
     }
     
     private static Class getClass(String s) throws ClassNotFoundException

+ 122 - 38
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -51,6 +51,11 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
 
 public class ScriptEvents
 {              
+    private static void setLivingEntity(Script sc, LivingEntity ent)
+    {
+        sc.setVar("living_entity", ent);
+    }
+
     private final Scripts scripts;
     private final MinecraftServer server;
     private final PermissionManager perms;
@@ -66,6 +71,26 @@ public class ScriptEvents
     // basics
     // -------------------------------------------------------------------------
     
+    private void handleEvent(Event e, String event, Consumer<Script> before, Consumer<Script> after)
+    {      
+        if(e.isCancelable())
+        {
+            scripts.getScriptManager().callEvent(event, sc -> 
+            {
+                before.accept(sc);
+                sc.setVar("cancel", e.isCanceled());
+            }, sc -> 
+            {
+                after.accept(sc);
+                handleVar(sc, event, "cancel", v -> e.setCanceled(v.getBoolean(sc)));
+            });
+        }
+        else
+        {
+            scripts.getScriptManager().callEvent(event, before, after);
+        }
+    }
+    
     private void handleEvent(PlayerEntity p, String event, Consumer<Script> before, Consumer<Script> after)
     {      
         scripts.getScriptManager().callEvent(event, (sc) -> 
@@ -93,6 +118,18 @@ public class ScriptEvents
         handleEvent(p, event, before, null);
     }
     
+    private void handleVar(Script sc, String event, String name, Consumer<Variable> c)
+    {
+        try
+        {
+            ifVarNotNull(sc, name, c);
+        }
+        catch(Exception ex)
+        {
+            scripts.getLogger().print(String.format("invalid var in '%s' event", event), ex, null, sc.getName(), sc, sc.getActiveSourceLine());
+        }
+    }      
+    
     private void ifVarNotNull(Script sc, String name, Consumer<Variable> c)
     {
         Variable v = sc.getVar(name);
@@ -178,7 +215,7 @@ public class ScriptEvents
     }
     
     @SubscribeEvent
-    public void onPlayerDamage(LivingHurtEvent e)
+    public void onOldPlayerDamage(LivingHurtEvent e)
     {        
         if(!(e.getEntityLiving() instanceof ServerPlayerEntity))
         {
@@ -215,6 +252,49 @@ public class ScriptEvents
         });
     } 
     
+    @SubscribeEvent
+    public void onOldEntityDamage(LivingHurtEvent e)
+    {        
+        PlayerEntity p = Utils.getDamager(e.getSource());
+        if(p == null)
+        {
+            return;
+        }
+        handleEvent(p, "entity_hurt", (sc) -> 
+        {
+            sc.setVar("entity_killed", e.getEntityLiving().getHealth() <= e.getAmount());        
+            ScriptVars.setEntityVars(sc, e.getEntity()); 
+            sc.setVar("entity_damage", (double) e.getAmount());   
+            sc.setVar("entity_damage_cause", e.getSource());
+            sc.setVar("cancel", e.isCanceled());   
+        }, (sc) -> 
+        {
+            try
+            {
+                ifVarNotNull(sc, "entity_damage", v -> e.setAmount(v.getFloat(sc)));
+                ifVarNotNull(sc, "cancel", v -> e.setCanceled(v.getBoolean(sc)));
+            }
+            catch(Exception ex)
+            {
+                scripts.getLogger().print("invalid var in 'entity_hurt' event", ex, null, sc.getName(), sc, sc.getActiveSourceLine());
+            }
+        });
+    }
+    
+    @SubscribeEvent
+    public void onEntityDamage(LivingHurtEvent e)
+    {        
+        handleEvent(e, "living_hurt", (sc) -> 
+        {
+            setLivingEntity(sc, e.getEntityLiving());
+            sc.setVar("damage_source", e.getSource());  
+            sc.setVar("damage_amount", (double) e.getAmount());  
+        }, (sc) -> 
+        {
+            handleVar(sc, "living_hurt", "damage_amount", v -> e.setAmount(v.getFloat(sc)));
+        });
+    } 
+    
     @SubscribeEvent
     public void onPlayerAttack(LivingAttackEvent e)
     {        
@@ -260,7 +340,44 @@ public class ScriptEvents
     } 
     
     @SubscribeEvent
-    public void onPlayerDamage(LivingHealEvent e)
+    public void onOldPlayerHeal(LivingHealEvent e)
+    {        
+        if(e.getEntityLiving() instanceof PlayerEntity)
+        {
+            handleEvent((PlayerEntity) e.getEntityLiving(), "player_heal", (sc) -> 
+            {
+                sc.setVar("heal", (double) e.getAmount());
+                sc.setVar("cancel", e.isCanceled()); 
+            }, (sc) -> 
+            {
+                try
+                {
+                    ifVarNotNull(sc, "heal", v -> e.setAmount(v.getFloat(sc)));
+                    ifVarNotNull(sc, "cancel", v -> e.setCanceled(v.getBoolean(sc)));
+                }
+                catch(Exception ex)
+                {
+                    scripts.getLogger().print("invalid var in 'player_heal' event", ex, null, sc.getName(), sc, sc.getActiveSourceLine());
+                }
+            });
+        }
+    } 
+    
+    @SubscribeEvent
+    public void onLivingHeal(LivingHealEvent e)
+    {        
+        handleEvent(e, "living_heal", (sc) -> 
+        {
+            setLivingEntity(sc, e.getEntityLiving());
+            sc.setVar("heal_amount", (double) e.getAmount());  
+        }, (sc) -> 
+        {
+            handleVar(sc, "living_heal", "heal_amount", v -> e.setAmount(v.getFloat(sc)));
+        });
+    } 
+    
+    @SubscribeEvent
+    public void onEntityDamage(LivingHealEvent e)
     {        
         if(e.getEntityLiving() instanceof PlayerEntity)
         {
@@ -330,35 +447,6 @@ public class ScriptEvents
             }
         });
     } 
-       
-    @SubscribeEvent
-    public void onEntityDamage(LivingHurtEvent e)
-    {        
-        PlayerEntity p = Utils.getDamager(e.getSource());
-        if(p == null)
-        {
-            return;
-        }
-        handleEvent(p, "entity_hurt", (sc) -> 
-        {
-            sc.setVar("entity_killed", e.getEntityLiving().getHealth() <= e.getAmount());        
-            ScriptVars.setEntityVars(sc, e.getEntity()); 
-            sc.setVar("entity_damage", (double) e.getAmount());   
-            sc.setVar("entity_damage_cause", e.getSource());
-            sc.setVar("cancel", e.isCanceled());   
-        }, (sc) -> 
-        {
-            try
-            {
-                ifVarNotNull(sc, "entity_damage", v -> e.setAmount(v.getFloat(sc)));
-                ifVarNotNull(sc, "cancel", v -> e.setCanceled(v.getBoolean(sc)));
-            }
-            catch(Exception ex)
-            {
-                scripts.getLogger().print("invalid var in 'entity_hurt' event", ex, null, sc.getName(), sc, sc.getActiveSourceLine());
-            }
-        });
-    }
     
     @SubscribeEvent
     public void onEntityDrop(LivingDropsEvent e)
@@ -820,14 +908,10 @@ public class ScriptEvents
     public void onExplosion(ExplosionEvent.Start e)
     {
         e.setCanceled(true);
-        handleEvent(null, "explosion", (sc) -> 
+        handleEvent(e, "explosion", sc -> 
         {
-            sc.setVar("loc", new Location(e.getWorld(), e.getExplosion().getPosition()));
-            sc.setVar("cancel", e.isCanceled());
-        }, (sc) -> 
-        {
-            simpleCancel(sc, e, "explosion");
-        });
+            sc.setVar("location", new Location(e.getWorld(), e.getExplosion().getPosition()));
+        }, null);
     }
     
     private static String getName(ICommandSource cs)

+ 0 - 1
src/main/java/me/km/utils/ClientReflectionUtils.java

@@ -8,7 +8,6 @@ import static me.km.utils.ReflectionUtils.getField;
 import static me.km.utils.ReflectionUtils.getMethod;
 import net.minecraft.client.Minecraft;
 import net.minecraft.client.gui.overlay.BossOverlayGui;
-import net.minecraft.client.renderer.BlockRendererDispatcher;
 import net.minecraft.client.renderer.entity.EntityRenderer;
 import net.minecraft.client.renderer.entity.EntityRendererManager;
 import net.minecraft.client.renderer.entity.LivingRenderer;

+ 0 - 37
src/main/java/me/km/utils/ReflectionUtils.java

@@ -257,43 +257,6 @@ public class ReflectionUtils
         getFieldValue(Map.class, null, SAVED_ENTRIES).remove(rl);
     }
     
-    // -----------------------------------------------------------------------------------
-    // LivingEntity stuff
-    // -----------------------------------------------------------------------------------
-    
-    private final static Method APPLY_POTION_DAMAGE_CALCULATIONS = getMethod(
-            LivingEntity.class, 
-            "func_70672_c", DamageSource.class, float.class);
-    
-    public static float applyPotionDamageCalculations(LivingEntity liv, DamageSource ds, float damage)
-    {
-        try
-        {
-            return (float) APPLY_POTION_DAMAGE_CALCULATIONS.invoke(liv, ds, damage);
-        }
-        catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
-        {
-            LogManager.getLogger().warn("applyPotionDamageCalculations - " + ex);
-            return damage;
-        }
-    }
-    
-    private final static Method DAMAGE_ARMOR = getMethod(
-            LivingEntity.class, 
-            "func_70675_k", float.class);
-    
-    public static void damageArmor(LivingEntity liv, float damage)
-    {
-        try
-        {
-            DAMAGE_ARMOR.invoke(liv, damage);
-        }
-        catch(IllegalAccessException | IllegalArgumentException | InvocationTargetException ex)
-        {
-            LogManager.getLogger().warn("damageArmor - " + ex);
-        }
-    }
-    
     // -----------------------------------------------------------------------------------
     // explosion stuff
     // -----------------------------------------------------------------------------------