Parcourir la source

new snuvi commands, bugfixes for missing fractions

Kajetan Johannes Hammerle il y a 7 ans
Parent
commit
6817b1b730

+ 18 - 3
src/main/java/me/km/playerbank/PlayerManager.java

@@ -36,16 +36,31 @@ public class PlayerManager extends Module
         return backLocation.get(p.getUniqueID());
     }
     
-    public int getGuildId(EntityPlayer p) 
+    public int getGuildId(String uuid) 
     {
-        int i = bank.getTag(p, "gilde");
+        int i = bank.getTag(uuid, "gilde");
         if(i == 0)
         {
-            i = -bank.getIdByUUID(p.getUniqueID().toString());
+            i = -bank.getIdByUUID(uuid);
         }
         return i;
     }
     
+    public int getGuildId(EntityPlayer p) 
+    {
+        return getGuildId(p.getUniqueID().toString());
+    }
+    
+    public void setGuildId(String uuid, int id) 
+    {
+        bank.setTag(uuid, "gilde", id);
+    }
+    
+    public void setGuildId(EntityPlayer p, int id) 
+    {
+        setGuildId(p.getUniqueID().toString(), id);
+    }
+    
     public boolean getPvpStatus(EntityPlayer p) 
     {
         return bank.getTag(p, "pvp") >= 1;

+ 84 - 9
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -81,6 +81,7 @@ import me.km.networking.ModPacketHandler;
 import me.km.pathfinder.PathfinderUtils;
 import me.km.skills.LeveledSkill;
 import me.km.skills.Skill;
+import net.minecraft.block.BlockCrops;
 import net.minecraft.entity.item.EntityItem;
 import net.minecraft.util.NonNullList;
 import net.minecraft.util.math.MathHelper;
@@ -194,10 +195,36 @@ public class MinecraftFunctions implements ISnuviLogger
                 setTag(args));
         parser.registerFunction("player.gettag", (args, qd) -> 
                 getTag(args));
+        parser.registerConsumer("player.setguild", (args, qd) -> 
+                {
+                    if(args[0] instanceof EntityPlayer)
+                    {
+                        KajetansMod.playerbank.setGuildId((EntityPlayer) args[0], ScriptUtils.getInt(args[1]));
+                        return;
+                    }
+                    KajetansMod.playerbank.setGuildId(args[0].toString(), ScriptUtils.getInt(args[1]));
+                });
+        parser.registerFunction("player.getguild", (args, qd) -> 
+                {
+                    if(args[0] instanceof EntityPlayer)
+                    {
+                        return new Fraction(KajetansMod.playerbank.getGuildId((EntityPlayer) args[0]));
+                    }
+                    return new Fraction(KajetansMod.playerbank.getGuildId(args[0].toString()));
+                });
+        
         parser.registerConsumer("player.dropinventory", (args, qd) -> 
                 dropInventory(args));
         parser.registerFunction("player.gettarget", (args, qd) -> 
-                new Location(((EntityPlayer) args[0]).world, Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1]))));
+                {
+                    if(args.length > 2)
+                    {
+                        return new Location(((EntityPlayer) args[0]).world, 
+                                Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1]), (boolean) args[2]));
+                    }
+                    return new Location(((EntityPlayer) args[0]).world, Utils.getPlayerTarget((EntityPlayer) args[0], ScriptUtils.getInt(args[1])));
+                });
+                
         parser.registerFunction("player.gettargetentity", (args, qd) -> 
                 Utils.getTargetedEntity((EntityPlayer) args[0], ScriptUtils.getDouble(args[1]), getClass(args[2].toString())));
         parser.registerFunction("player.hasquest", (args, qd) ->     
@@ -322,11 +349,11 @@ public class MinecraftFunctions implements ISnuviLogger
                 });  
         
         parser.registerFunction("loc.getx", (args, qd) -> 
-                ((Location) args[0]).getX());  
+                Fraction.fromDouble(((Location) args[0]).getX()));  
         parser.registerFunction("loc.gety", (args, qd) -> 
-                ((Location) args[0]).getY());  
+                Fraction.fromDouble(((Location) args[0]).getY()));  
         parser.registerFunction("loc.getz", (args, qd) -> 
-                ((Location) args[0]).getZ());  
+                Fraction.fromDouble(((Location) args[0]).getZ()));  
         
         parser.registerConsumer("loc.setx", (args, qd) -> 
                 ((Location) args[0]).setX(ScriptUtils.getDouble(args[1])));  
@@ -393,6 +420,44 @@ public class MinecraftFunctions implements ISnuviLogger
                 addItemAmountChest(args));
         parser.registerFunction("block.subitem", (args, qd) -> 
                 removeItemAmountChest(args));  
+        parser.registerConsumer("block.grow", (args, qd) -> 
+                {
+                    World w = ((Location) args[0]).getWorld();
+                    BlockPos pos1 = ((Location) args[0]).getBlockPos();
+                    BlockPos pos2 = ((Location) args[1]).getBlockPos();
+                    
+                    int x = Math.min(pos1.getX(), pos2.getX());
+                    int endX = Math.max(pos1.getX(), pos2.getX());
+                    
+                    int y = Math.min(pos1.getY(), pos2.getY());
+                    int endY = Math.max(pos1.getY(), pos2.getY());
+                    
+                    int z = Math.min(pos1.getZ(), pos2.getZ());
+                    int endZ = Math.max(pos1.getZ(), pos2.getZ());
+                    
+                    if(endX - x > 50 || endY - y > 50 || endZ - z > 50)
+                    {
+                        throw new IllegalArgumentException("uhh, that area seems way to big for growing plants");
+                    }
+                    
+                    BlockPos relative;
+                    IBlockState state;
+                    for(; x <= endX; x++)
+                    {
+                        for(; y <= endY; y++)
+                        {
+                            for(; z <= endZ; z++)
+                            {
+                                relative = new BlockPos(x, y, z);
+                                state = w.getBlockState(relative);
+                                if(state.getBlock() instanceof BlockCrops)
+                                {
+                                    w.setBlockState(relative, state.withProperty(BlockCrops.AGE, 7));                
+                                }                      
+                            }
+                        }
+                    }
+                });  
 
         // -------------------------------------------------------------    
         // Event-Bibliothek 
@@ -1488,7 +1553,7 @@ public class MinecraftFunctions implements ISnuviLogger
             KajetansMod.playerbank.getDataBank().setTag((EntityPlayer) args[0], args[1].toString(), ScriptUtils.getInt(args[2]));
             return;
         }
-        KajetansMod.playerbank.getDataBank().setTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString(), ScriptUtils.getInt(args[2]));
+        KajetansMod.playerbank.getDataBank().setTag(args[0].toString(), args[1].toString(), ScriptUtils.getInt(args[2]));
     }
     
     private static Fraction getTag(Object[] args)
@@ -1497,7 +1562,7 @@ public class MinecraftFunctions implements ISnuviLogger
         {
             return new Fraction(KajetansMod.playerbank.getDataBank().getTag((EntityPlayer) args[0], args[1].toString()));
         }
-        return new Fraction(KajetansMod.playerbank.getDataBank().getTag(KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()), args[1].toString()));
+        return new Fraction(KajetansMod.playerbank.getDataBank().getTag(args[0].toString(), args[1].toString()));
     }
     
     private static void setGlobalVar(Object[] args)
@@ -1505,9 +1570,15 @@ public class MinecraftFunctions implements ISnuviLogger
         if(args[0] instanceof EntityPlayer)
         {
             KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
-            return;
         }
-        KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
+        else if(args[0].equals("SERVER"))
+        {
+            KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), "-1");
+        }
+        else
+        {
+            KajetansMod.scripts.getDataBank(ScriptBank.class).setVar(args[2].toString(), args[1].toString(), args[0].toString());
+        }
     }
     
     private static Object getGlobalVar(Object[] args)
@@ -1516,7 +1587,11 @@ public class MinecraftFunctions implements ISnuviLogger
         {
             return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), ((EntityPlayer) args[0]).getUniqueID().toString());
         }
-        return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), KajetansMod.playerbank.getDataBank().getUUID(args[0].toString()));
+        else if(args[0].equals("SERVER"))
+        {
+            return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), "-1");
+        }
+        return KajetansMod.scripts.getDataBank(ScriptBank.class).getVar(args[1].toString(), args[0].toString());
     }
     
     // -------------------------------------------------------------------------    

+ 25 - 0
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -236,6 +236,14 @@ public class ScriptEvents extends ModuleListener
             qd.setVar("cancel", e.isCanceled()); 
         }, (qd) -> 
         {
+            try
+            {
+                e.setAmount(ScriptUtils.getFloat(qd.getVar("player_damage")));
+            }
+            catch(Exception ex)
+            {
+                KajetansMod.scripts.logger.printException(ex, "player_hurt", qd, qd.getActiveRealCodeLine());
+            }
             e.setCanceled(qd.getBooleanVar("cancel")); 
         });
     } 
@@ -247,9 +255,18 @@ public class ScriptEvents extends ModuleListener
         {
             handleEvent((EntityPlayer) e.getEntityLiving(), "player_heal", (qd) -> 
             {
+                qd.setEventVar("heal", Fraction.fromDouble(e.getAmount()));
                 qd.setVar("cancel", e.isCanceled()); 
             }, (qd) -> 
             {
+                try
+                {
+                    e.setAmount(ScriptUtils.getFloat(qd.getVar("heal")));
+                }
+                catch(Exception ex)
+                {
+                    KajetansMod.scripts.logger.printException(ex, "player_heal", qd, qd.getActiveRealCodeLine());
+                }
                 e.setCanceled(qd.getBooleanVar("cancel")); 
             });
         }
@@ -318,6 +335,14 @@ public class ScriptEvents extends ModuleListener
             qd.setVar("cancel", e.isCanceled());   
         }, (qd) -> 
         {
+            try
+            {
+                e.setAmount(ScriptUtils.getFloat(qd.getVar("entity_damage")));
+            }
+            catch(Exception ex)
+            {
+                KajetansMod.scripts.logger.printException(ex, "entity_hurt", qd, qd.getActiveRealCodeLine());
+            }
             e.setCanceled(qd.getBooleanVar("cancel"));
         });
     }