Przeglądaj źródła

code refactoring, structuring, cleanup, added super fancy own display, works with SnuviScript, icons for the display

Kajetan Johannes Hammerle 7 lat temu
rodzic
commit
9c6eabb9b0
41 zmienionych plików z 719 dodań i 414 usunięć
  1. 70 27
      src/main/java/me/km/ClientEvents.java
  2. 3 1
      src/main/java/me/km/ClientProxy.java
  3. 6 1
      src/main/java/me/km/CommonProxy.java
  4. 25 23
      src/main/java/me/km/KajetansMod.java
  5. 2 2
      src/main/java/me/km/api/MessageSender.java
  6. 9 14
      src/main/java/me/km/api/Utils.java
  7. 2 0
      src/main/java/me/km/blocks/BlockEvents.java
  8. 0 83
      src/main/java/me/km/capabilities/CapabilitiesEvents.java
  9. 5 2
      src/main/java/me/km/capabilities/DamageUtils.java
  10. 2 2
      src/main/java/me/km/commands/CommandItemInfo.java
  11. 5 5
      src/main/java/me/km/commands/CommandPvP.java
  12. 8 6
      src/main/java/me/km/datatools/CommandDataTools.java
  13. 41 74
      src/main/java/me/km/effects/EffectUtils.java
  14. 5 6
      src/main/java/me/km/effects/active/AreaDamage.java
  15. 1 1
      src/main/java/me/km/effects/active/BlockExplosion.java
  16. 5 6
      src/main/java/me/km/effects/active/Earthquake.java
  17. 4 6
      src/main/java/me/km/effects/active/Elevation.java
  18. 1 3
      src/main/java/me/km/effects/active/ElvishHorn.java
  19. 2 2
      src/main/java/me/km/effects/active/Explosion.java
  20. 1 2
      src/main/java/me/km/effects/active/FireProtectionRain.java
  21. 1 1
      src/main/java/me/km/effects/active/Flying.java
  22. 3 2
      src/main/java/me/km/effects/active/Harm.java
  23. 1 2
      src/main/java/me/km/effects/active/HealRain.java
  24. 1 1
      src/main/java/me/km/effects/active/Poison.java
  25. 2 2
      src/main/java/me/km/effects/active/Thor.java
  26. 5 6
      src/main/java/me/km/effects/passive/ArrowEffects.java
  27. 2 2
      src/main/java/me/km/effects/passive/LeaveDecay.java
  28. 0 59
      src/main/java/me/km/networking/GunLoadPackage.java
  29. 72 0
      src/main/java/me/km/networking/Icon.java
  30. 9 5
      src/main/java/me/km/networking/ModPacketHandler.java
  31. 78 0
      src/main/java/me/km/networking/PlayerDisplay.java
  32. 180 0
      src/main/java/me/km/networking/PlayerDisplayGui.java
  33. 2 2
      src/main/java/me/km/pathfinder/PathfinderGoalDestroyBlock.java
  34. 16 0
      src/main/java/me/km/pathfinder/PathfinderUtils.java
  35. 2 0
      src/main/java/me/km/playerbank/ModNetHandlerPlayServer.java
  36. 17 4
      src/main/java/me/km/playerbank/PlayerManager.java
  37. 1 1
      src/main/java/me/km/skills/ActiveSkillContainer.java
  38. 72 24
      src/main/java/me/km/snuviscript/MinecraftFunctions.java
  39. 1 3
      src/main/java/me/km/snuviscript/ScriptVars.java
  40. 57 34
      src/main/java/me/km/utils/NBTUtils.java
  41. BIN
      src/main/resources/assets/km/textures/gui/icons.png

+ 70 - 27
src/main/java/me/km/ClientEvents.java

@@ -1,16 +1,27 @@
 package me.km;
 
+import java.util.List;
 import me.km.api.GlobalText;
+import me.km.items.ItemGun;
+import me.km.items.ItemKey;
+import me.km.networking.PlayerDisplayGui;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemArmor;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
 import net.minecraft.util.text.TextComponentString;
 import net.minecraft.util.text.TextComponentTranslation;
+import net.minecraft.util.text.TextFormatting;
 import net.minecraftforge.client.event.ClientChatReceivedEvent;
+import net.minecraftforge.client.event.RenderGameOverlayEvent;
+import net.minecraftforge.event.entity.player.ItemTooltipEvent;
 import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
 import net.minecraftforge.fml.relauncher.Side;
 import net.minecraftforge.fml.relauncher.SideOnly;
 
+@SideOnly(Side.CLIENT)
 public class ClientEvents 
 {   
-    @SideOnly(Side.CLIENT)
     @SubscribeEvent
     public void preventChatMessage(ClientChatReceivedEvent e) 
     {
@@ -26,38 +37,70 @@ public class ClientEvents
             }   
         }
     }
-    
-    /*public final static HashSet<Location> LOCS = new HashSet();
-    
-    public void addLocation(Location l)
-    {
-        l = l.copy();
-        l.round();
-        LOCS.add(l);
-    }
-    
-    public boolean removeLocation(Location l)
+
+    @SubscribeEvent
+    public void onRenderGui(RenderGameOverlayEvent.Post e)
     {
-        return LOCS.remove(l);
+        if(e.getType() == RenderGameOverlayEvent.ElementType.EXPERIENCE)
+        {
+            PlayerDisplayGui.INSTANCE.paint();
+        }
     }
     
-    private static boolean b = true;
-    
     @SubscribeEvent
-    public void onPlayerMove(PlayerMoveEvent e)
-    {      
-        EntityPlayer p = e.getEntityPlayer();
-        Location l = new Location(p);
-        l.round();
-        if(b)
+    public void showingTooltip(ItemTooltipEvent e) 
+    {
+        ItemStack stack = e.getItemStack();
+        Item item = stack.getItem();
+        if(item instanceof ItemArmor)
+        {
+            NBTTagCompound com = stack.getTagCompound();
+            if(com != null && com.hasKey("magic"))
+            {
+                int magic = com.getInteger("magic");
+                if(magic != 0)
+                {
+                    List<String> list = e.getToolTip();
+                    String s = TextFormatting.BLUE + " +";
+                    for(int i = 0; i < list.size(); i++)
+                    {
+                        if(list.get(i).startsWith(s))
+                        {
+                            list.add(i, TextFormatting.BLUE + " +" + magic + " Magic Armor");
+                            break;
+                        }
+                    }
+                }
+            }
+        }
+        else if(item.getClass() == ItemGun.class)
         {
-            b = false;
-            World w = p.world;
-            LOCS.add(new Location(w, -117, 86, 169, 0, 0));
+            int load = ItemGun.getLoad(stack);
+            if(load >= 0)
+            {
+                List<String> list = e.getToolTip();
+                if(load == 1)
+                {
+                    list.add(1, TextFormatting.GOLD + "" + load + " shot loaded");
+                }
+                else
+                {
+                    list.add(1, TextFormatting.GOLD + "" + load + " shots loaded");
+                }
+            }
         }
-        if(LOCS.contains(l))
+        else if(item.getClass() == ItemKey.class)
         {
-            System.out.println(l);
+            String s = ItemKey.getKey(stack);
+            List<String> list = e.getToolTip();
+            if(s.isEmpty())
+            {
+                list.set(0, TextFormatting.RED + list.get(0));
+            }
+            else
+            {
+                list.set(0, TextFormatting.GREEN + list.get(0));
+            }
         }
-    }*/
+    }
 }

+ 3 - 1
src/main/java/me/km/ClientProxy.java

@@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
 import net.minecraft.item.Item;
 import net.minecraft.server.MinecraftServer;
 import net.minecraftforge.client.model.ModelLoader;
+import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.fluids.IFluidBlock;
 import net.minecraftforge.fml.client.registry.RenderingRegistry;
 import net.minecraftforge.fml.relauncher.Side;
@@ -58,9 +59,10 @@ public class ClientProxy extends CommonProxy
     }
     
     @Override
-    public void initEntities() 
+    public void init() 
     {
         ModEntities.initClient();
+        MinecraftForge.EVENT_BUS.register(new ClientEvents());
     }
 
     @Override

+ 6 - 1
src/main/java/me/km/CommonProxy.java

@@ -1,6 +1,8 @@
 package me.km;
 
+import me.km.blocks.BlockEvents;
 import me.km.entities.ModEntities;
+import me.km.events.CustomEventCaller;
 import me.km.playerbank.ModDedicatedPlayerList;
 import net.minecraft.client.model.ModelBiped;
 import net.minecraft.client.renderer.entity.Render;
@@ -8,6 +10,7 @@ import net.minecraft.entity.Entity;
 import net.minecraft.item.Item;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.server.dedicated.DedicatedServer;
+import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.fluids.IFluidBlock;
 import net.minecraftforge.fml.relauncher.Side;
 import net.minecraftforge.fml.relauncher.SideOnly;
@@ -30,9 +33,11 @@ public class CommonProxy
     {
     }
     
-    public void initEntities() 
+    public void init() 
     {
         ModEntities.initServer();
+        MinecraftForge.EVENT_BUS.register(new BlockEvents());
+        MinecraftForge.EVENT_BUS.register(new CustomEventCaller());
     }
     
     public void overloadPlayerList(MinecraftServer server)

+ 25 - 23
src/main/java/me/km/KajetansMod.java

@@ -5,19 +5,16 @@ import me.km.api.Module;
 import me.km.api.SimpleConfig;
 import me.km.api.CommandOverloader;
 import me.km.blockprotections.BlockProtectionBank;
-import me.km.blocks.BlockEvents;
 import me.km.capabilities.DamageUtils;
 import me.km.chatmanager.ChatManager;
 import me.km.databank.DataBank;
 import me.km.dimensions.ModWorldGeneration;
 import me.km.dimensions.WorldData;
 import me.km.effects.EffectUtils;
-import me.km.events.CustomEventCaller;
 import me.km.fluids.ModFluids;
 import me.km.jobsystem.JobAPI;
 import me.km.networking.ModPacketHandler;
 import me.km.permissions.PermissionManager;
-import me.km.playerbank.PlayerBank;
 import me.km.playerbank.PlayerManager;
 import me.km.plots.ProtectionBank;
 import me.km.scheduler.SnuviScheduler;
@@ -27,7 +24,6 @@ import me.km.snuviscript.ScriptModule;
 import me.km.snuviscript.ScriptBank;
 import net.minecraft.server.MinecraftServer;
 import net.minecraft.util.text.TextFormatting;
-import net.minecraftforge.common.MinecraftForge;
 import net.minecraftforge.fluids.FluidRegistry;
 import net.minecraftforge.fml.common.Mod;
 import net.minecraftforge.fml.common.SidedProxy;
@@ -73,7 +69,7 @@ public class KajetansMod
 
     public static final String MODID = "km";
     public static final String NAME = "Kajetans Mod";
-    public static final String VERSION = "0.0.11";
+    public static final String VERSION = "0.0.12";
 
     @Mod.Instance(MODID)
     public static KajetansMod instance;
@@ -98,16 +94,32 @@ public class KajetansMod
         
         DamageUtils.init();
         CapabilitiesEvents.init();
-        MinecraftForge.EVENT_BUS.register(new CapabilitiesEvents());
+        /*MinecraftForge.EVENT_BUS.register(new Object()
+            {
+                @SubscribeEvent
+                public void wusi(ServerChatEvent e) 
+                {
+                    System.out.println(e.getMessage());
+                    try
+                    {
+                        String[] parts = e.getMessage().split(" ");
+                        int action = Integer.parseInt(parts[0]);
+                        int index = Integer.parseInt(parts[1]);
+                        String text = Arrays.stream(parts, 2, parts.length).collect(Collectors.joining(" ")).replace('&', '§');
+                        System.out.println("action '" + action + "' with index '" + index + "' and text '" + text + "'");
+                        ModPacketHandler.sendStats(e.getPlayer(), action, index, text);
+                    }
+                    catch(Exception ex)
+                    {
+                    }
+                }
+            });*/
     }
     
     @Mod.EventHandler
     public void init(FMLInitializationEvent e) 
     {
-        proxy.initEntities();
-        MinecraftForge.EVENT_BUS.register(new ClientEvents());
-        MinecraftForge.EVENT_BUS.register(new BlockEvents());
-        MinecraftForge.EVENT_BUS.register(new CustomEventCaller());
+        proxy.init();
     }
     
     @Mod.EventHandler
@@ -128,19 +140,9 @@ public class KajetansMod
         event = e;
         if(singlePlayer)
         {
-            /*perms = new PermissionManager("Permissions", "Perms", TextFormatting.DARK_PURPLE);
-            perms.registerEvents("me.km.permissions");
-            
-            scheduler = new SnuviScheduler("Scheduler", "Scheduler", TextFormatting.GREEN);
-            scheduler.registerEvents("me.km.scheduler");
-            
-            generalCommands = new Module("GeneralCommands", "Commands", TextFormatting.GOLD);
-            generalCommands.registerCommands(e, "me.km.commands");
-            
-            debugMode = true;*/
             return;
         }
-        // Konfiguration und Error-Dummy
+        // configuration and error-dummy
         error = new Module("ERROR", "ERROR", TextFormatting.RED);
         conf = new SimpleConfig(error, "", "config", true);
         debugMode = conf.getBoolean("debug", false);
@@ -169,8 +171,8 @@ public class KajetansMod
         scheduler.registerEvents("me.km.scheduler");
 
         // Spielerdatenbank
-        playerbank = new PlayerManager("PlayerBank", "PlayerBank", TextFormatting.RED);
-        playerbank.setDataBank(new PlayerBank(playerbank, databank.getConnection()));
+        playerbank = new PlayerManager("PlayerBank", "PlayerBank", TextFormatting.RED, databank.getConnection());
+        // databank is initialized in JobAPI in order to have a reference
         playerbank.registerEvents("me.km.playerbank");
         
         // Grundlegende Commands

+ 2 - 2
src/main/java/me/km/api/MessageSender.java

@@ -31,10 +31,10 @@ public class MessageSender
         cs.sendMessage(prefixes.createCopy().appendText(msg));
     }
 
-    public void sendToPlayers(World w, Vec3d v, double radius, String msg)
+    public void sendToPlayers(World w, double x, double y, double z, double radius, String msg)
     {
         ITextComponent s = prefixes.createCopy().appendText(msg);
-        Utils.getNearbyEntities(w, v, radius, EntityPlayer.class).forEach(p -> ((EntityPlayer) p).sendMessage(s));
+        Utils.getEntities(w, x, y, z, radius, EntityPlayer.class).forEach(p -> ((EntityPlayer) p).sendMessage(s));
     }
     
     public void sendBroadcast(String msg)

+ 9 - 14
src/main/java/me/km/api/Utils.java

@@ -456,7 +456,7 @@ public class Utils
     
     public static void teleportEntity(Entity ent, Entity ent2)
     {
-        teleportEntity(ent, new Location(ent2.world, ent2.getPositionVector(), ent2.rotationYaw, ent2.rotationPitch));
+        teleportEntity(ent, new Location(ent2));
     }
     
     public static float getRealDamage(EntityLivingBase ent, DamageSource ds, float d)
@@ -516,30 +516,25 @@ public class Utils
     }
     
     @SuppressWarnings("unchecked")
-    public static <T extends Entity> Collection<T> getNearbyEntities(World w, Vec3d v, double radius, Class<T> type)
+    public static <T extends Entity> List<T> getEntities(World w, double x, double y, double z, double radius, Class<T> type)
     {       
         double sqareRadius = radius * radius;
         return w.getEntitiesWithinAABB(type, new AxisAlignedBB(
-                v.x - radius, v.y - radius, v.z - radius, 
-                v.x + radius, v.y + radius, v.z + radius), ent -> ent.getDistanceSq(v.x, v.y, v.z) <= sqareRadius);
+                x - radius, y - radius, z - radius, 
+                x + radius, y + radius, z + radius), 
+                ent -> ent.getDistanceSq(x, y, z) <= sqareRadius);
     }
     
-    public static List<EntityPlayer> getNearbyPlayers(World w, double x, double y, double z, double radius)
+    public static List<EntityPlayer> getPlayers(World w, double x, double y, double z, double radius)
     {       
         double sqareRadius = radius * radius;
         return w.playerEntities.stream().filter(p -> p.getDistanceSq(x, y, z) <= sqareRadius).collect(Collectors.toList());
     }
-    
-    public static List<EntityPlayer> getNearbyPlayers(World w, Vec3d v, double radius)
-    {       
-        return getNearbyPlayers(w, v.x, v.y, v.z, radius);
-    }
 
-    public static <T extends Entity> T getNearestEntity(World w, Vec3d v, double radius, Class<T> type)
+    public static <T extends Entity> T getEntity(World w, double x, double y, double z, double radius, Class<T> type)
     {
-        return getNearbyEntities(w, v, radius, type).stream().min((e1, e2) -> Double.compare(
-                        e1.getDistanceSq(v.x, v.y, v.z), 
-                        e2.getDistanceSq(v.x, v.y, v.z)))
+        return getEntities(w, x, y, z, radius, type).stream()
+                .min((e1, e2) -> Double.compare(e1.getDistanceSq(x, y, z), e2.getDistanceSq(x, y, z)))
                 .orElse(null);
     }
     

+ 2 - 0
src/main/java/me/km/blocks/BlockEvents.java

@@ -4,6 +4,7 @@ import com.google.common.collect.Sets;
 import java.util.List;
 import java.util.Random;
 import java.util.Set;
+import me.km.networking.ModPacketHandler;
 import me.km.utils.ReflectionUtils;
 import net.minecraft.block.Block;
 import net.minecraft.block.material.Material;
@@ -13,6 +14,7 @@ import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityLivingBase;
 import net.minecraft.entity.item.EntityTNTPrimed;
 import net.minecraft.entity.player.EntityPlayer;
+import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.init.Blocks;
 import net.minecraft.init.SoundEvents;
 import net.minecraft.util.DamageSource;

+ 0 - 83
src/main/java/me/km/capabilities/CapabilitiesEvents.java

@@ -1,18 +1,5 @@
 package me.km.capabilities;
 
-import java.util.List;
-import me.km.items.ItemGun;
-import me.km.items.ItemKey;
-import net.minecraft.item.Item;
-import net.minecraft.item.ItemArmor;
-import net.minecraft.item.ItemStack;
-import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.util.text.TextFormatting;
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
-import net.minecraftforge.event.entity.player.ItemTooltipEvent;
-import net.minecraftforge.fml.relauncher.Side;
-import net.minecraftforge.fml.relauncher.SideOnly;
-
 public class CapabilitiesEvents 
 {
     //public static final ResourceLocation DEFENSE_CAP = new ResourceLocation(KajetansMod.MODID, "defense");
@@ -25,74 +12,4 @@ public class CapabilitiesEvents
         //CapabilityManager.INSTANCE.register(IChestKey.class, new ChestKeyStorage(), ItemChestKey.class);
         //CapabilityManager.INSTANCE.register(IGunLoad.class, new GunLoadStorage(), ItemGunLoad.class);
     }
-    
-    /*@SubscribeEvent
-    public void attachData(AttachCapabilitiesEvent<ItemStack> e) 
-    {
-        if(e.getObject().getItem() instanceof ItemSword)
-        {
-            ItemStack stack = e.getObject();
-            System.out.println("DICK");
-            ItemStackUtils.addAttribute(stack, ItemStackUtils.Attribute.ATTACK_SPEED, 
-                    EntityEquipmentSlot.MAINHAND, -2.7d, ItemStackUtils.Operation.ADD);
-        }
-    }*/
-    
-    @SideOnly(Side.CLIENT)
-    @SubscribeEvent
-    public void showingTooltip(ItemTooltipEvent e) 
-    {
-        ItemStack stack = e.getItemStack();
-        Item item = stack.getItem();
-        if(item instanceof ItemArmor)
-        {
-            NBTTagCompound com = stack.getTagCompound();
-            if(com != null && com.hasKey("magic"))
-            {
-                int magic = com.getInteger("magic");
-                if(magic != 0)
-                {
-                    List<String> list = e.getToolTip();
-                    String s = TextFormatting.BLUE + " +";
-                    for(int i = 0; i < list.size(); i++)
-                    {
-                        if(list.get(i).startsWith(s))
-                        {
-                            list.add(i, TextFormatting.BLUE + " +" + magic + " Magic Armor");
-                            break;
-                        }
-                    }
-                }
-            }
-        }
-        else if(item.getClass() == ItemGun.class)
-        {
-            int load = ItemGun.getLoad(stack);
-            if(load >= 0)
-            {
-                List<String> list = e.getToolTip();
-                if(load == 1)
-                {
-                    list.add(1, TextFormatting.GOLD + "" + load + " shot loaded");
-                }
-                else
-                {
-                    list.add(1, TextFormatting.GOLD + "" + load + " shots loaded");
-                }
-            }
-        }
-        else if(item.getClass() == ItemKey.class)
-        {
-            String s = ItemKey.getKey(stack);
-            List<String> list = e.getToolTip();
-            if(s.isEmpty())
-            {
-                list.set(0, TextFormatting.RED + list.get(0));
-            }
-            else
-            {
-                list.set(0, TextFormatting.GREEN + list.get(0));
-            }
-        }
-    }
 }

+ 5 - 2
src/main/java/me/km/capabilities/DamageUtils.java

@@ -2,6 +2,7 @@ package me.km.capabilities;
 
 import net.minecraft.entity.EntityLivingBase;
 import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
 import net.minecraft.util.DamageSource;
 
 public class DamageUtils 
@@ -26,11 +27,13 @@ public class DamageUtils
     public static int getMagicDefense(EntityLivingBase liv)
     {
         int level = 0;
+        NBTTagCompound com;
         for(ItemStack stack : liv.getArmorInventoryList())
         {
-            if(stack.hasCapability(DefenseProvider.DEFENSE_CAP, null))
+            com = stack.getTagCompound();
+            if(com != null && com.hasKey("magic"))
             {
-                level += stack.getCapability(DefenseProvider.DEFENSE_CAP, null).getMagicDefense();
+                level += com.getInteger("magic");
             }
         }
         return level;

+ 2 - 2
src/main/java/me/km/commands/CommandItemInfo.java

@@ -3,7 +3,7 @@ package me.km.commands;
 import me.km.api.GlobalText;
 import me.km.api.Module;
 import me.km.api.ModuleCommand;
-import me.km.nms.NmsUtilities;
+import me.km.utils.NBTUtils;
 import me.km.permissions.Permissions;
 import me.km.utils.ItemStackUtils;
 import net.minecraft.command.ICommandSender;
@@ -42,7 +42,7 @@ public class CommandItemInfo extends ModuleCommand
         m.send(cs, "DV: §6" + stack.getItemDamage());
         m.send(cs, "Meta: §6" + stack.getMetadata());
         m.send(cs, "Item: §6" + stack.getItem());
-        NmsUtilities.sendCopyableText(p, ItemStackUtils.getNbtString(stack).replace("\"", "'"));
+        NBTUtils.sendCopyableText(p, ItemStackUtils.getNbtString(stack).replace("\"", "'"));
         return true;
     }
 }

+ 5 - 5
src/main/java/me/km/commands/CommandPvP.java

@@ -5,9 +5,9 @@ import me.km.api.Utils;
 import me.km.api.GlobalText;
 import me.km.api.Module;
 import me.km.api.ModuleCommand;
-import me.km.playerbank.PlayerBank;
 import me.km.exception.PlayerNotFoundException;
 import me.km.permissions.Permissions;
+import me.km.playerbank.PlayerManager;
 import net.minecraft.command.ICommandSender;
 import net.minecraft.entity.player.EntityPlayer;
 
@@ -48,10 +48,10 @@ public class CommandPvP extends ModuleCommand
             affectedPlayer = (EntityPlayer) cs;
         }
         
-        PlayerBank pb = KajetansMod.playerbank.getDataBank();
-        if(pb.getTag(affectedPlayer, "pvp") == 1)
+        PlayerManager pb = KajetansMod.playerbank;
+        if(pb.getPvpStatus(affectedPlayer))
         {
-            pb.setTag(affectedPlayer, "pvp", 0);
+            pb.setPvpStatus(affectedPlayer, false);
             this.getModule().send(affectedPlayer, "Du hast PVP nun aus.");
             if(!affectedPlayer.equals(cs))
             {
@@ -59,7 +59,7 @@ public class CommandPvP extends ModuleCommand
             }
             return true;
         }
-        pb.setTag(affectedPlayer, "pvp", 1);
+        pb.setPvpStatus(affectedPlayer, true);
         this.getModule().send(affectedPlayer, "Du hast PVP nun an.");
         if(!affectedPlayer.equals(cs))
         {

+ 8 - 6
src/main/java/me/km/datatools/CommandDataTools.java

@@ -5,11 +5,12 @@ import me.km.api.Module;
 import me.km.api.ModuleCommand;
 import me.km.api.Utils;
 import me.km.chatmanager.ChatManager;
-import me.km.nms.NmsUtilities;
+import me.km.utils.NBTUtils;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
+import me.km.pathfinder.PathfinderUtils;
 import me.km.permissions.Permissions;
 import me.km.utils.ItemStackUtils;
 import net.minecraft.command.ICommandSender;
@@ -115,9 +116,9 @@ public class CommandDataTools extends ModuleCommand
                     }       
                     this.getModule().send(cs, GlobalText.Spacer());
                     this.getModule().send(cs, "NBT-Daten " + ent.getName());
-                    String nbt = NmsUtilities.getNbtString(ent);
-                    cs.sendMessage(new TextComponentString(NmsUtilities.highlightNbtSyntax(nbt)));   
-                    NmsUtilities.sendCopyableText(p, nbt);
+                    String nbt = NBTUtils.toString(ent);
+                    cs.sendMessage(new TextComponentString(NBTUtils.highlightNbtSyntax(nbt)));   
+                    NBTUtils.sendCopyableText(p, nbt);
                     return true;
                 }
                 case "test":
@@ -128,7 +129,8 @@ public class CommandDataTools extends ModuleCommand
                         m.send(cs, "Du musst auf ein Objekt gerichtet sein.");
                         return true;
                     }       
-                    NmsUtilities.canDestroyBlocks((EntityLiving) ent);
+                    PathfinderUtils.canDestroyBlocks((EntityLiving) ent);
+                    m.send(cs, ent.getName() + " ist nun böse.");
                     return true;
                 }
                 case "flag":
@@ -196,7 +198,7 @@ public class CommandDataTools extends ModuleCommand
                     return true;    
                 }
                 case "show-entity":
-                    Collection<Entity> ents = Utils.getNearbyEntities(p.getEntityWorld(), p.getPositionVector(), 3, Entity.class);
+                    Collection<Entity> ents = Utils.getEntities(p.getEntityWorld(), p.posX, p.posY, p.posZ, 3, Entity.class);
                     if(ents.isEmpty())
                     {
                         m.send(cs, "Du musst mindestens ein Objekt in deiner Nähe haben.");

+ 41 - 74
src/main/java/me/km/effects/EffectUtils.java

@@ -10,7 +10,6 @@ import me.km.entities.EntityItemProjectile;
 import me.km.jobsystem.JobAPI;
 import me.km.plots.ProtectionBank;
 import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityAreaEffectCloud;
 import net.minecraft.entity.EntityLivingBase;
 import net.minecraft.entity.item.EntityEnderPearl;
 import net.minecraft.entity.item.EntityExpBottle;
@@ -19,10 +18,7 @@ import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.entity.projectile.*;
 import net.minecraft.init.Items;
-import net.minecraft.init.SoundEvents;
 import net.minecraft.item.ItemStack;
-import net.minecraft.network.play.server.SPacketParticles;
-import net.minecraft.network.play.server.SPacketSoundEffect;
 import net.minecraft.potion.Potion;
 import net.minecraft.potion.PotionEffect;
 import net.minecraft.potion.PotionType;
@@ -132,9 +128,9 @@ public class EffectUtils extends Module
     // Entity-Collections
     // -----------------------------------------------------------------------------------
     
-    public static Collection<EntityPlayer> getPlayersOfGuild(EntityPlayer p, World w, Vec3d v, double radius)
+    public static Collection<EntityPlayer> getPlayersOfGuild(EntityPlayer p, World w, double x, double y, double z, double radius)
     {       
-        Collection<EntityPlayer> col = Utils.getNearbyPlayers(w, v, radius);
+        Collection<EntityPlayer> col = Utils.getPlayers(w, x, y, z, radius);
         if(col.isEmpty())
         {
             return col;
@@ -146,20 +142,20 @@ public class EffectUtils extends Module
     
     public static Collection<EntityPlayer> getPlayersOfGuild(EntityPlayer p, double radius)
     {       
-        return getPlayersOfGuild(p, p.world, p.getPositionVector(), radius);
+        return getPlayersOfGuild(p, p.world, p.posX, p.posY, p.posZ, radius);
     }
     
-    public static Collection<EntityLivingBase> getEntsOfNotGuild(EntityPlayer p, World w, Vec3d v, double radius)
+    public static Collection<EntityLivingBase> getEntsOfNotGuild(EntityPlayer p, World w, double x, double y, double z, double radius)
     {       
-        boolean animals = KajetansMod.plots.getDataBank(ProtectionBank.class).canBuild(w, new BlockPos(v), p);
+        boolean animals = KajetansMod.plots.getDataBank(ProtectionBank.class).canBuild(w, new BlockPos(x, y, z), p);
         boolean pvp = !KajetansMod.worldManager.getWorldPreferences(w).pvpProtection;
-        boolean ppvp = KajetansMod.playerbank.getDataBank().getTag(p, "pvp") >= 1;
+        boolean ppvp = KajetansMod.playerbank.getPvpStatus(p);
         int id = KajetansMod.playerbank.getGuildId(p);
         
-        return Utils.getNearbyEntities(w, v, radius, EntityLivingBase.class).stream()
+        return Utils.getEntities(w, x, y, z, radius, EntityLivingBase.class).stream()
                 .filter(ent -> animals || !(ent instanceof EntityAnimal))
                 .filter(ent -> pvp || !(ent instanceof EntityPlayer) || (ppvp && 
-                        KajetansMod.playerbank.getDataBank().getTag((EntityPlayer) ent, "pvp") >= 1))
+                        KajetansMod.playerbank.getPvpStatus((EntityPlayer) ent)))
                 .filter(ent -> !(ent instanceof EntityPlayer) || 
                         (id != KajetansMod.playerbank.getGuildId((EntityPlayer) ent)))
                 .filter(ent -> ent != p)
@@ -168,83 +164,79 @@ public class EffectUtils extends Module
     
     public static Collection<EntityLivingBase> getEntsOfNotGuild(EntityPlayer p, double radius)
     {       
-        return getEntsOfNotGuild(p, p.world, p.getPositionVector(), radius);
-    }
-    
-    // -----------------------------------------------------------------------------------
-    // Target Selector
-    // -----------------------------------------------------------------------------------
-    
-    public static BlockPos getPlayerTarget(EntityPlayer p, int range)
-    {      
-        return Utils.getPlayerTarget(p, range + 7).up();
+        return getEntsOfNotGuild(p, p.world, p.posX, p.posY, p.posZ, radius);
     }
     
     // -----------------------------------------------------------------------------------
     // Particles
     // -----------------------------------------------------------------------------------
     
-    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, float x, float y, float z, float offX, float offY, float offZ, float speed, int count, int... data)
+    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, double x, double y, double z, double offX, double offY, double offZ, int count, int... data)
     {
-        SPacketParticles packet = new SPacketParticles(particle, false, x, y, z, offX, offY, offZ, speed, count, data);
-        Utils.getNearbyPlayers(w, x, y, z, 512).forEach(p -> ((EntityPlayerMP) p).connection.sendPacket(packet));
+        w.spawnParticle(particle, false, x, y, z, count, offX, offY, offZ, 1, data);
     }
     
-    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, float x, float y, float z, float offX, float offY, float offZ, int count)
+    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, double x, double y, double z, double offX, double offY, double offZ, int count)
     {
-        spawnParticle(w, particle, x, y, z, offX, offY, offZ, 1, count, new int[0]);
+        spawnParticle(w, particle, x, y, z, offX, offY, offZ, count, new int[0]);
     }
     
-    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, float x, float y, float z, int count)
+    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, double x, double y, double z, int count)
     {
         spawnParticle(w, particle, x, y, z, 0, 0, 0, count);
     }
     
-    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, Vec3d v, int count)
+    public static void spawnParticle(WorldServer w, EnumParticleTypes particle, Entity ent, int count)
     {
-        spawnParticle(w, particle, (float) v.x, (float) v.y, (float) v.z, 0, 0, 0, count);
+        spawnParticle(w, particle, ent.posX, ent.posY, ent.posZ, count);
     }
     
-    public static void playSpell(EntityPlayerMP p, int level)
+    public static void spawnSpell(EntityPlayerMP p, int level)
     {
-        spawnParticle(p.getServerWorld(), EnumParticleTypes.SPELL, (float) p.posX, (float) p.posY + 1, (float) p.posZ, 0.5f, 0.5f, 0.5f, 1, 10 + level, new int[0]);
+        spawnParticle(p.getServerWorld(), EnumParticleTypes.SPELL, p.posX, p.posY + 1, p.posZ, 0.5f, 0.5f, 0.5f, 10 + level);
     }
     
-    public static <T> void playEffectCircleWithData(WorldServer w, Vec3d v, EnumParticleTypes particle, double radius, int counter, int... data)
+    public static void spawnParticleCircle(WorldServer w, double x, double y, double z, EnumParticleTypes particle, double radius, int counter, int... data)
     {
-        double x = v.x;
-        float y = (float) v.y;
-        double z = v.z;
         double angle = 2 * Math.PI / counter;
         for(int i = 0; i < counter; i++)
         {
-            spawnParticle(w, particle, (float) (x + Math.cos(i * angle) * radius), y, (float) (z + Math.sin(i * angle) * radius), 0, 0, 0, 1, 1, data);
+            spawnParticle(w, particle, x + Math.cos(i * angle) * radius, y, z + Math.sin(i * angle) * radius, 0, 0, 0, 1, data);
         }                
     }
     
-    public static <T> void playEffectCircle(WorldServer w, Vec3d v, EnumParticleTypes particle, double radius, int counter)
+    public static void spawnParticleCircle(WorldServer w, Entity ent, EnumParticleTypes particle, double radius, int counter, int... data)
     {
-        playEffectCircleWithData(w, v, particle, radius, counter, new int[0]);              
+        spawnParticleCircle(w, ent.posX, ent.posY, ent.posZ, particle, radius, counter, data);              
+    }
+    
+    public static void spawnParticleCircle(WorldServer w, double x, double y, double z, EnumParticleTypes particle, double radius, int counter)
+    {
+        spawnParticleCircle(w, x, y, z, particle, radius, counter, new int[0]);              
+    }
+    
+    public static void spawnParticleCircle(WorldServer w, Entity ent, EnumParticleTypes particle, double radius, int counter)
+    {
+        spawnParticleCircle(w, ent.posX, ent.posY, ent.posZ, particle, radius, counter, new int[0]);              
     }
     
     // -----------------------------------------------------------------------------------
     // Sounds
     // -----------------------------------------------------------------------------------
     
-    public static void playSound(WorldServer w, SoundEvent se, SoundCategory sc, double x, double y, double z)
+    public static void playSound(World w, SoundEvent se, SoundCategory sc, double x, double y, double z)
     {
-        SPacketSoundEffect packet = new SPacketSoundEffect(se, sc, x, y, z, 1, 1);
-        Utils.getNearbyPlayers(w, x, y, z, 128).forEach(p -> ((EntityPlayerMP) p).connection.sendPacket(packet));
+        w.playSound(null, x, y, z, se, sc, 1, w.rand.nextFloat() * 0.1f + 0.9f);
     }
     
-    public static void playSound(EntityPlayerMP p, SoundEvent se, SoundCategory sc)
+    public static void playSound(EntityPlayer p, SoundEvent se, SoundCategory sc)
     {
-        playSound(p.getServerWorld(), se, sc, p.posX, p.posY, p.posZ);
+        playSound(p.world, se, sc, p.posX, p.posY, p.posZ);
     }
     
-    public static void playSound(EntityPlayerMP p, SoundEvent se)
+    public static void playSound(EntityPlayer p, SoundEvent se)
     {
-        playSound(p.getServerWorld(), se, SoundCategory.PLAYERS, p.posX, p.posY, p.posZ);
+        playSound(p.world, se, SoundCategory.PLAYERS, p.posX, p.posY, p.posZ);
     }
 
     // -----------------------------------------------------------------------------------
@@ -260,25 +252,6 @@ public class EffectUtils extends Module
         ent.addPotionEffect(new PotionEffect(potion, duration, amplifier));
     }
     
-    public static void spawnPotionCloud(Vec3d v, EntityPlayerMP p, Potion potion, int pduration, int amplifier, int duration, float radius)
-    {
-        EntityAreaEffectCloud cloud = new EntityAreaEffectCloud(p.getServerWorld(), v.x, v.y, v.z);
-        cloud.setDuration(duration);
-        cloud.setRadius(radius);
-        cloud.setOwner(p);
-        cloud.setWaitTime(5);
-        cloud.setPotion(new PotionType(new PotionEffect(potion, pduration, amplifier)));
-        p.getServerWorld().spawnEntity(cloud);
-    }
-    
-    public static void spawnPotionCloud(EntityPlayerMP p, Potion potion, int level)
-    {
-        BlockPos pos = getPlayerTarget(p, level);
-        spawnPotionCloud(new Vec3d(pos.getX(), pos.getY(), pos.getZ()), p, potion, 20 * level, (level / 4), 40 * level, 0.5f + level / 4f);
-        playSpell(p, level);
-        playSound(p, SoundEvents.ENTITY_FIREWORK_BLAST, SoundCategory.PLAYERS);
-    }
-    
     // -----------------------------------------------------------------------------------
     // Projectiles
     // -----------------------------------------------------------------------------------
@@ -378,18 +351,12 @@ public class EffectUtils extends Module
         return arrow;
     }
     
-    public static void jumpTo(EntityLivingBase ent, EntityLivingBase ent2)
+    public static void jumpTo(EntityLivingBase j, EntityLivingBase g)
     {
-        Vec3d v1 = ent2.getPositionVector();
-        Vec3d v2 = ent.getPositionVector();
-        
-        Utils.setVelocity(ent, (v1.x - v2.x) * 0.2, (v1.y - v2.y) * 0.2 + 0.9, (v1.z - v2.z) * 0.2);
-
+        Utils.setVelocity(j, (g.posX - g.posX) * 0.2, (g.posY - g.posY) * 0.2 + 0.9, (g.posZ - g.posZ) * 0.2);
         KajetansMod.scheduler.scheduleTask(() -> 
         {
-            Vec3d v3 = ent2.getPositionVector();
-            Vec3d v4 = ent.getPositionVector();
-            Utils.setVelocity(ent, (v3.x - v4.x) * 0.2, (v3.y - v4.y) * 0.2, (v3.z - v4.z) * 0.2);
+            Utils.setVelocity(j, (g.posX - j.posX) * 0.2, (g.posY - j.posY) * 0.2, (g.posZ - j.posZ) * 0.2);
         }, 12);
     }
 }

+ 5 - 6
src/main/java/me/km/effects/active/AreaDamage.java

@@ -32,12 +32,11 @@ public class AreaDamage extends ActiveEffectBase
         if(KajetansMod.playerbank.getData(p).hasData("aoe"))
         {
             WorldServer w = p.getServerWorld();
-            Vec3d v = p.getPositionVector();
-            EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.FLAME, 5, 12);
-            EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.FLAME, 4, 12);
-            EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.FLAME, 3, 12);
-            EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.FLAME, 2, 12);
-            EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.FLAME, 1, 12);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, 5, 12);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, 4, 12);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, 3, 12);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, 2, 12);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, 1, 12);
             DamageSource ds = DamageSource.causeMobDamage(p);
             EffectUtils.getEntsOfNotGuild(p, 5).stream().forEach((m) -> 
             {

+ 1 - 1
src/main/java/me/km/effects/active/BlockExplosion.java

@@ -44,7 +44,7 @@ public class BlockExplosion extends ActiveEffectBase
         KajetansMod.scheduler.scheduleTask(() -> 
         {
             item.setDead();
-            EffectUtils.spawnParticle(w, EnumParticleTypes.EXPLOSION_LARGE, item.getPositionVector(), 1);
+            EffectUtils.spawnParticle(w, EnumParticleTypes.EXPLOSION_LARGE, item, 1);
             e.run(300);
         }, 60);
         

+ 5 - 6
src/main/java/me/km/effects/active/Earthquake.java

@@ -15,12 +15,11 @@ public class Earthquake extends ActiveEffectBase
     {
         int[] data = new int[]{4};
         WorldServer w = p.getServerWorld();
-        Vec3d v = p.getPositionVector();
-        EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.BLOCK_CRACK, 5, 12, data);
-        EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.BLOCK_CRACK, 4, 12, data);
-        EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.BLOCK_CRACK, 3, 12, data);
-        EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.BLOCK_CRACK, 2, 12, data);
-        EffectUtils.playEffectCircleWithData(w, v, EnumParticleTypes.BLOCK_CRACK, 1, 12, data);
+        EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.BLOCK_CRACK, 5, 12, data);
+        EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.BLOCK_CRACK, 4, 12, data);
+        EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.BLOCK_CRACK, 3, 12, data);
+        EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.BLOCK_CRACK, 2, 12, data);
+        EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.BLOCK_CRACK, 1, 12, data);
         DamageSource ds = DamageSource.causeMobDamage(p);
         EffectUtils.getEntsOfNotGuild(p, 5).stream().forEach((m) -> 
         {

+ 4 - 6
src/main/java/me/km/effects/active/Elevation.java

@@ -9,19 +9,17 @@ import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.init.SoundEvents;
 import net.minecraft.util.EnumParticleTypes;
 import net.minecraft.util.math.BlockPos;
-import net.minecraft.util.math.Vec3d;
 
 public class Elevation extends ActiveEffectBase
 {
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        BlockPos target = EffectUtils.getPlayerTarget(p, power);    
-        Vec3d v = new Vec3d(target.getX(), target.getY(), target.getZ());
+        BlockPos target = Utils.getPlayerTarget(p, power + 3).up();    
         EffectUtils.playSound(p, SoundEvents.ENTITY_FIREWORK_TWINKLE_FAR);
-        EffectUtils.playSpell(p, power); 
-        Collection<EntityLivingBase> list = EffectUtils.getEntsOfNotGuild(p, p.world, v, 3);
-        EffectUtils.playEffectCircle(p.getServerWorld(), v, EnumParticleTypes.SPELL, 3, 30);
+        EffectUtils.spawnSpell(p, power); 
+        Collection<EntityLivingBase> list = EffectUtils.getEntsOfNotGuild(p, p.world, target.getX(), target.getY(), target.getZ(), 3);
+        EffectUtils.spawnParticleCircle(p.getServerWorld(), p, EnumParticleTypes.SPELL, 3, 30);
         double shootPower = 1 + power / 20d;
         list.stream().forEach((en) -> 
         {

+ 1 - 3
src/main/java/me/km/effects/active/ElvishHorn.java

@@ -6,7 +6,6 @@ import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.init.MobEffects;
 import net.minecraft.init.SoundEvents;
 import net.minecraft.util.EnumParticleTypes;
-import net.minecraft.util.math.Vec3d;
 import net.minecraft.world.WorldServer;
 
 public class ElvishHorn extends ActiveEffectBase
@@ -17,10 +16,9 @@ public class ElvishHorn extends ActiveEffectBase
         int time = 600 * power;
         EffectUtils.playSound(p, SoundEvents.ENTITY_GHAST_SCREAM);
         WorldServer w = p.getServerWorld();
-        Vec3d v = p.getPositionVector();
         for(int i = 1; i <= power + 2; i++)
         {
-            EffectUtils.playEffectCircle(w, v, EnumParticleTypes.NOTE, i, 6 * i);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.NOTE, i, 6 * i);
         }
         EffectUtils.getPlayersOfGuild(p, power + 2).forEach(pl -> 
         {

+ 2 - 2
src/main/java/me/km/effects/active/Explosion.java

@@ -1,7 +1,7 @@
 package me.km.effects.active;
 
+import me.km.api.Utils;
 import me.km.effects.ActiveEffectBase;
-import me.km.effects.EffectUtils;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.world.WorldServer;
@@ -11,7 +11,7 @@ public class Explosion extends ActiveEffectBase
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        BlockPos target = EffectUtils.getPlayerTarget(p, power);
+        BlockPos target = Utils.getPlayerTarget(p, power + 3).up();
         WorldServer w = p.getServerWorld();
         w.createExplosion(null, target.getX(), target.getY(), target.getZ(), power / 4f, true);
         return true;

+ 1 - 2
src/main/java/me/km/effects/active/FireProtectionRain.java

@@ -14,10 +14,9 @@ public class FireProtectionRain extends ActiveEffectBase
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
         WorldServer w = p.getServerWorld();
-        Vec3d v = p.getPositionVector();
         for(int i = 1; i <= power + 2; i++)
         {
-            EffectUtils.playEffectCircle(w, v, EnumParticleTypes.FLAME, i, 6 * i);
+            EffectUtils.spawnParticleCircle(w, p, EnumParticleTypes.FLAME, i, 6 * i);
         }
         EffectUtils.getPlayersOfGuild(p, power + 2).forEach(pl -> 
         {

+ 1 - 1
src/main/java/me/km/effects/active/Flying.java

@@ -13,7 +13,7 @@ public class Flying extends ActiveEffectBase
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
         EffectUtils.playSound(p, SoundEvents.ENTITY_FIREWORK_LAUNCH);
-        EffectUtils.playSpell(p, power);
+        EffectUtils.spawnSpell(p, power);
         Vec3d v = p.getLookVec().scale(1 + (power / 20f));
         Utils.setVelocity(p, v.x, v.y, v.z);
         return true;

+ 3 - 2
src/main/java/me/km/effects/active/Harm.java

@@ -3,14 +3,15 @@
 import me.km.effects.ActiveEffectBase;
 import me.km.effects.EffectUtils;
 import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.init.MobEffects;
+import net.minecraft.util.DamageSource;
 
 public class Harm extends ActiveEffectBase
 {
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        EffectUtils.spawnPotionCloud(p, MobEffects.INSTANT_DAMAGE, power);
+        DamageSource ds = DamageSource.causeMobDamage(p);
+        EffectUtils.getEntsOfNotGuild(p, 5).forEach(ent -> ent.attackEntityFrom(ds, power));
         return true;
     }
 

+ 1 - 2
src/main/java/me/km/effects/active/HealRain.java

@@ -3,14 +3,13 @@ package me.km.effects.active;
 import me.km.effects.ActiveEffectBase;
 import me.km.effects.EffectUtils;
 import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.init.MobEffects;
 
 public class HealRain extends ActiveEffectBase
 {
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        EffectUtils.spawnPotionCloud(p, MobEffects.INSTANT_HEALTH, power);
+        EffectUtils.getPlayersOfGuild(p, 5).forEach(pl -> pl.heal(power));
         return true;
     }
 

+ 1 - 1
src/main/java/me/km/effects/active/Poison.java

@@ -10,7 +10,7 @@ public class Poison extends ActiveEffectBase
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        EffectUtils.spawnPotionCloud(p, MobEffects.POISON, power);
+        EffectUtils.getEntsOfNotGuild(p, 5).forEach(ent -> EffectUtils.addPotionTo(ent, MobEffects.POISON, power * 20, 1));
         return true;
     }
 

+ 2 - 2
src/main/java/me/km/effects/active/Thor.java

@@ -1,9 +1,9 @@
 package me.km.effects.active;
 
+import me.km.api.Utils;
 import net.minecraft.entity.effect.EntityLightningBolt;
 import net.minecraft.world.WorldServer;
 import me.km.effects.ActiveEffectBase;
-import me.km.effects.EffectUtils;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.util.math.BlockPos;
 
@@ -12,7 +12,7 @@ public class Thor extends ActiveEffectBase
     @Override
     protected boolean executeEffect(EntityPlayerMP p, int power) 
     {
-        BlockPos pos = EffectUtils.getPlayerTarget(p, power);
+        BlockPos pos = Utils.getPlayerTarget(p, power + 3).up();
         WorldServer w = p.getServerWorld();
         w.addWeatherEffect(new EntityLightningBolt(w, pos.getX(), pos.getY(), pos.getZ(), false));
         return true;

+ 5 - 6
src/main/java/me/km/effects/passive/ArrowEffects.java

@@ -95,11 +95,10 @@ public class ArrowEffects extends ModuleListener
         {
             int power = fromList * 600;
             int damage = fromList * 3;
-            Vec3d v = arrow.getPositionVector();
-            EffectUtils.spawnParticle(w, EnumParticleTypes.EXPLOSION_LARGE, v, 1);
-            EffectUtils.playEffectCircle(w, v, EnumParticleTypes.EXPLOSION_LARGE, 3, 9);
+            EffectUtils.spawnParticle(w, EnumParticleTypes.EXPLOSION_LARGE, arrow, 1);
+            EffectUtils.spawnParticleCircle(w, arrow, EnumParticleTypes.EXPLOSION_LARGE, 3, 9);
             DamageSource ds = DamageSource.causeMobDamage(p);
-            EffectUtils.getEntsOfNotGuild(p, w, v, 4).forEach(e -> 
+            EffectUtils.getEntsOfNotGuild(p, w, arrow.posX, arrow.posY, arrow.posZ, 4).forEach(e -> 
             {
                 e.attackEntityFrom(ds, damage);
                 EffectUtils.addPotionTo(e, MobEffects.BLINDNESS, power, 0);
@@ -158,8 +157,8 @@ public class ArrowEffects extends ModuleListener
             return;
         }
         DamageSource ds = DamageSource.causeMobDamage(p);
-        EffectUtils.spawnParticle(p.getServerWorld(), EnumParticleTypes.EXPLOSION_LARGE, pro.getPositionVector(), 1);
-        EffectUtils.getEntsOfNotGuild(p, p.getServerWorld(), pro.getPositionVector(), 3).forEach(ent -> 
+        EffectUtils.spawnParticle(p.getServerWorld(), EnumParticleTypes.EXPLOSION_LARGE, pro, 1);
+        EffectUtils.getEntsOfNotGuild(p, p.getServerWorld(), pro.posX, pro.posY, pro.posZ, 3).forEach(ent -> 
         {
             ent.attackEntityFrom(ds, 4);    
             EffectUtils.addPotionTo(ent, MobEffects.BLINDNESS, 200, 0);

+ 2 - 2
src/main/java/me/km/effects/passive/LeaveDecay.java

@@ -37,7 +37,7 @@ public class LeaveDecay extends ModuleListener
         {
             World w = e.getWorld();
             BlockPos pos = e.getPos();
-            List<EntityPlayer> players = Utils.getNearbyPlayers(w, pos.getX(), pos.getY(), pos.getZ(), 15);
+            List<EntityPlayer> players = Utils.getPlayers(w, pos.getX(), pos.getY(), pos.getZ(), 15);
             int i = (int) players.stream().filter((p) -> Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.MORE_SAPLINGS)).count();
             if(i >= 1)
             {
@@ -52,7 +52,7 @@ public class LeaveDecay extends ModuleListener
         {
             World w = e.getWorld();
             BlockPos pos = e.getPos();
-            List<EntityPlayer> players = Utils.getNearbyPlayers(w, pos.getX(), pos.getY(), pos.getZ(), 15);
+            List<EntityPlayer> players = Utils.getPlayers(w, pos.getX(), pos.getY(), pos.getZ(), 15);
             int i = (int) players.stream().filter((p) -> Utils.randomInt(1, 25) <= EffectUtils.getEffectLevel(p, Effect.MORE_SAPLINGS)).count();
             if(i >= 1)
             {

+ 0 - 59
src/main/java/me/km/networking/GunLoadPackage.java

@@ -1,59 +0,0 @@
-package me.km.networking;
-
-import io.netty.buffer.ByteBuf;
-import me.km.capabilities.GunLoadProvider;
-import me.km.capabilities.IGunLoad;
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.entity.EntityPlayerSP;
-import net.minecraft.item.ItemStack;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
-import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
-import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
-
-public class GunLoadPackage implements IMessage
-{
-    private int slot;
-    private int load;
-    
-    public GunLoadPackage() 
-    {
-        slot = -1;
-        load = -1;
-    }
-    
-    public GunLoadPackage(int slot, int load) 
-    {
-        this.slot = slot;
-        this.load = load;
-    }
-    
-    @Override
-    public void fromBytes(ByteBuf buf) 
-    {
-        slot = buf.readInt();
-        load = buf.readInt();
-    }
-
-    @Override
-    public void toBytes(ByteBuf buf) 
-    {
-        buf.writeInt(slot);
-        buf.writeInt(load);
-    }
-
-    public static class Handler implements IMessageHandler<GunLoadPackage, IMessage>
-    {
-        @Override
-        public IMessage onMessage(GunLoadPackage message, MessageContext ctx) 
-        {
-            EntityPlayerSP p = Minecraft.getMinecraft().player;
-            ItemStack stack = p.inventoryContainer.inventorySlots.get(message.slot).getStack();
-            if(stack.hasCapability(GunLoadProvider.GUN_LOAD_CAP, null))
-            {
-                IGunLoad load = stack.getCapability(GunLoadProvider.GUN_LOAD_CAP, null);
-                load.setCurrentLoad(message.load);
-            }
-            return null;
-        }
-    }
-}

+ 72 - 0
src/main/java/me/km/networking/Icon.java

@@ -0,0 +1,72 @@
+package me.km.networking;
+
+public enum Icon 
+{
+    NULL(0, 0, 9, 9),
+    FULL_HEART(9, 0, 9, 9),
+    HALF_HEART(18, 0, 9, 9),
+    EMPTY_HEART(27, 0, 9, 9),
+    EMPTY_FOOD(36, 0, 9, 9),
+    FULL_FOOD(45, 0, 9, 9),
+    EMPTY_ARMOR(54, 0, 9, 9),
+    HALF_ARMOR(63, 0, 9, 9),
+    FULL_ARMOR(72, 0, 9, 9),
+    BUBBLE(81, 0, 9, 9),
+    BUBBLE_BROKEN(90, 0, 9, 9),
+    FULL_MANA(9, 9, 9, 9),
+    HALF_MANA(18, 9, 9, 9),
+    EMPTY_MANA(27, 9, 9, 9),
+    FULL_THIRST(9, 18, 9, 9),
+    HALF_THIRST(18, 18, 9, 9),
+    EMPTY_THIRST(27, 18, 9, 9),
+    FULL_COLD(9, 27, 9, 9),
+    HALF_COLD(18, 27, 9, 9),
+    EMPTY_COLD(27, 27, 9, 9),
+    FULL_ENERGY(9, 36, 9, 9),
+    HALF_ENERGY(18, 36, 9, 9),
+    EMPTY_ENERGY(27, 36, 9, 9);
+        
+    private static Icon[] icons = Icon.values();
+            
+    private int offsetX;
+    private int offsetY;
+    private int width;
+    private int height;
+        
+    Icon(int offsetX, int offsetY, int width, int height)
+    {
+        this.offsetX = offsetX;
+        this.offsetY = offsetY;
+        this.width = width;
+        this.height = height;
+    }
+
+    public int getOffsetX() 
+    {
+        return offsetX;
+    }
+
+    public int getOffsetY() 
+    {
+        return offsetY;
+    }
+
+    public int getHeight() 
+    {
+        return height;
+    }
+
+    public int getWidth() 
+    {
+        return width;
+    }
+    
+    public static Icon getIcon(int i)
+    {
+        if(i < 0 || i >= icons.length)
+        {
+            return NULL;
+        }
+        return icons[i];
+    }
+}

+ 9 - 5
src/main/java/me/km/networking/ModPacketHandler.java

@@ -1,20 +1,24 @@
 package me.km.networking;
 
+import me.km.KajetansMod;
 import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraftforge.fml.common.network.NetworkRegistry;
+import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
+import net.minecraftforge.fml.relauncher.Side;
 
 public class ModPacketHandler 
 {
-    //public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(KajetansMod.MODID);
+    public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(KajetansMod.MODID);
     
-    //private static int id = 0;
+    private static int id = 0;
     
     public static void init()
     {
-        //INSTANCE.registerMessage(GunLoadPackage.Handler.class, GunLoadPackage.class, id++, Side.CLIENT);
+        INSTANCE.registerMessage(PlayerDisplay.Handler.class, PlayerDisplay.class, id++, Side.CLIENT);
     }
     
-    public static void sendGunLoad(EntityPlayerMP p, int slot, int load)
+    public static void sendStats(EntityPlayerMP p, int action, int index, String text)
     {
-        //INSTANCE.sendTo(new GunLoadPackage(slot, load), p);
+        INSTANCE.sendTo(new PlayerDisplay(action, index, text), p);
     }
 }

+ 78 - 0
src/main/java/me/km/networking/PlayerDisplay.java

@@ -0,0 +1,78 @@
+package me.km.networking;
+
+import io.netty.buffer.ByteBuf;
+import java.nio.charset.StandardCharsets;
+import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
+import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
+import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
+
+public class PlayerDisplay implements IMessage
+{
+    // 1 - add - index, text
+    // 2 - remove - index
+    // 3 - clear
+    private int action;
+    private int index;
+    private String text;
+    
+    public PlayerDisplay() 
+    {
+        action = -1;
+        index = -1;
+        text = "";
+    }
+    
+    public PlayerDisplay(int action, int index, String text) 
+    {
+        this.action = action;
+        this.index = index;
+        if(text.length() > 32)
+        {
+            this.text = text.substring(0, 32);
+        }
+        else
+        {
+            this.text = text;
+        }
+    }
+    
+    @Override
+    public void fromBytes(ByteBuf buf) 
+    {
+        action = buf.readInt();
+        index = buf.readInt();
+        int length = buf.readInt();
+        text = buf.readBytes(length).toString(StandardCharsets.UTF_8);
+    }
+
+    @Override
+    public void toBytes(ByteBuf buf) 
+    {
+        buf.writeInt(action);
+        buf.writeInt(index);
+        byte[] b = text.getBytes(StandardCharsets.UTF_8);
+        buf.writeInt(b.length);
+        buf.writeBytes(b);
+    }
+
+    public static class Handler implements IMessageHandler<PlayerDisplay, IMessage>
+    {
+        @Override
+        public IMessage onMessage(PlayerDisplay message, MessageContext ctx) 
+        {
+            switch(message.action)
+            {
+                case 1:
+                    PlayerDisplayGui.INSTANCE.add(message.index, message.text);
+                    break;
+                case 2:
+                    PlayerDisplayGui.INSTANCE.remove(message.index);
+                    break;
+                case 3: 
+                    PlayerDisplayGui.INSTANCE.clear();
+                    break;
+            }
+            return null;
+        }
+    }
+}

+ 180 - 0
src/main/java/me/km/networking/PlayerDisplayGui.java

@@ -0,0 +1,180 @@
+package me.km.networking;
+
+import java.util.ArrayList;
+import java.util.TreeMap;
+import me.km.KajetansMod;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.Gui;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.util.ResourceLocation;
+import net.minecraftforge.fml.relauncher.Side;
+import net.minecraftforge.fml.relauncher.SideOnly;
+
+@SideOnly(Side.CLIENT)
+public class PlayerDisplayGui extends Gui
+{
+    private static final ResourceLocation CUSTOM_ICONS = new ResourceLocation(KajetansMod.MODID, "textures/gui/icons.png");
+    
+    public final static PlayerDisplayGui INSTANCE = new PlayerDisplayGui(Minecraft.getMinecraft());
+    
+    private class IconStorage
+    {
+        private Icon icon;
+        private int count;
+        
+        public IconStorage(int id, int count)
+        {
+            this.icon = Icon.getIcon(id);
+            this.count = count;
+        }
+        
+        public int getWidth()
+        {
+            return count * icon.getWidth() - count + 1;
+        }
+        
+        public int getHeight()
+        {
+            return icon.getHeight();
+        }
+    }
+    
+    private class LineData
+    {
+        private ArrayList<String> list;
+        private ArrayList<IconStorage> icons;
+        
+        public LineData(String s)
+        {
+            this.list = new ArrayList<>();
+            this.icons = new ArrayList<>();
+            
+            int pos;
+            int old = 0;
+            while(true)
+            {
+                // icon format #X-Y- where X and Y are numbers
+                pos = s.indexOf("#", old);
+                if(pos == -1)
+                {
+                    list.add(s.substring(old));
+                    break;
+                }
+                list.add(s.substring(old, pos));
+                try
+                {
+                    int first = s.indexOf("-", pos);
+                    int second = s.indexOf("-", first + 1);
+                    icons.add(new IconStorage(Integer.parseInt(s.substring(pos + 1, first)), Integer.parseInt(s.substring(first + 1, second))));
+                    old = second + 1;
+                }
+                catch(Exception ex)
+                {
+                    list.add("FEHLER");
+                    break;
+                }
+            }
+        }
+        
+        public int getWidth()
+        {
+            return list.stream().mapToInt(s -> mc.fontRenderer.getStringWidth(s)).sum() + icons.stream().mapToInt(i -> i.getWidth()).sum();
+        }
+        
+        public int getHeight()
+        {
+            return Math.max(mc.fontRenderer.FONT_HEIGHT, icons.stream().mapToInt(i -> i.getHeight()).max().orElse(0) + 1);
+        }
+    }
+    
+    private TreeMap<Integer, LineData> strings;
+    private Minecraft mc;
+    
+    public PlayerDisplayGui(Minecraft mc)
+    {
+        this.mc = mc;
+        this.strings = new TreeMap<>(); 
+    }
+    
+    public void add(int i, String s)
+    {
+        strings.put(i, new LineData(s));
+    }
+    
+    public void remove(int i)
+    {
+        strings.remove(i);
+    }
+    
+    public void clear()
+    {
+        strings.clear();
+    }
+    
+    public void paint()
+    {
+        if(strings.isEmpty())
+        {
+            return;
+        }
+        int x;
+        int y = 2;
+        
+        int width = 0;
+        int height = 4;
+        
+        for(LineData data : strings.values())
+        {
+            height += data.getHeight();
+            width = Math.max(data.getWidth(), width);
+        }
+        
+        drawRect(0, 0, width + 4, height, 1342177280);
+        
+        String s;
+        for(LineData data : strings.values())
+        {
+            x = 2;
+            for(int i = 0; i < data.list.size(); i ++)
+            {
+                s = data.list.get(i);
+                mc.fontRenderer.drawString(s, x, y + 1, 0xFFFFFF);
+                if(!s.isEmpty())
+                {
+                    x += mc.fontRenderer.getStringWidth(s);
+                }
+                else
+                {
+                    x--;
+                }
+                if(i < data.icons.size())
+                {
+                    x += paintIcons(data.icons.get(i), x, y);
+                }
+            }
+            y += data.getHeight();
+        }
+    }
+    
+    private void bind(ResourceLocation res)
+    {
+        mc.getTextureManager().bindTexture(res);
+    }
+    
+    private int paintIcons(IconStorage is, int x, int y)
+    {
+        bind(CUSTOM_ICONS);
+        GlStateManager.enableBlend();
+        Icon icon = is.icon;
+        int width = icon.getWidth();
+        int height = icon.getHeight();
+        int offX = icon.getOffsetX();
+        int offY = icon.getOffsetY();
+        for(int i = 0; i < is.count; i++)
+        {
+            drawTexturedModalRect(x + width * i - i, y, offX, offY, width, height);
+        }
+        GlStateManager.disableBlend();
+        return is.getWidth();
+    }
+}

+ 2 - 2
src/main/java/me/km/nms/PathfinderGoalDestroyBlock.java → src/main/java/me/km/pathfinder/PathfinderGoalDestroyBlock.java

@@ -1,4 +1,4 @@
-package me.km.nms;
+package me.km.pathfinder;
 
 import java.util.Random;
 import net.minecraft.entity.EntityLiving;
@@ -25,7 +25,7 @@ public class PathfinderGoalDestroyBlock extends EntityAIBase
         {
             return false;
         }
-        return entity.getRNG().nextInt(5) == 0;
+        return entity.getRNG().nextInt(3) == 0;
     }
 
     @Override

+ 16 - 0
src/main/java/me/km/pathfinder/PathfinderUtils.java

@@ -0,0 +1,16 @@
+package me.km.pathfinder;
+
+import net.minecraft.entity.EntityLiving;
+
+public class PathfinderUtils 
+{
+    public static void walkTo(EntityLiving liv, double x, double y, double z, double speed)
+    {
+        liv.getMoveHelper().setMoveTo(x, y, z, speed);
+    }
+    
+    public static void canDestroyBlocks(EntityLiving liv)
+    {
+        liv.tasks.addTask(1, new PathfinderGoalDestroyBlock(liv));
+    }
+}

+ 2 - 0
src/main/java/me/km/playerbank/ModNetHandlerPlayServer.java

@@ -7,6 +7,7 @@ import net.minecraft.entity.player.EntityPlayer;
 import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.network.NetHandlerPlayServer;
 import net.minecraft.network.NetworkManager;
+import net.minecraft.network.PacketThreadUtil;
 import net.minecraft.network.play.client.CPacketAnimation;
 import net.minecraft.network.play.client.CPacketChatMessage;
 import net.minecraft.network.play.server.SPacketChat;
@@ -35,6 +36,7 @@ public class ModNetHandlerPlayServer extends NetHandlerPlayServer
     @Override
     public void processChatMessage(CPacketChatMessage packetIn) 
     {
+        PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.player.getServerWorld());
         if(packetIn.getMessage().startsWith("/"))
         {
             String s = packetIn.getMessage();

+ 17 - 4
src/main/java/me/km/playerbank/PlayerManager.java

@@ -1,5 +1,6 @@
 package me.km.playerbank;
 
+import java.sql.Connection;
 import java.util.HashMap;
 import java.util.UUID;
 import me.km.api.Location;
@@ -12,17 +13,19 @@ public class PlayerManager extends Module
 {
     private final HashMap<UUID, PlayerData> data;
     private final HashMap<UUID, Location> back;
+    private final PlayerBank bank;
     
-    public PlayerManager(String mname, String prefix, TextFormatting color) 
+    public PlayerManager(String mname, String prefix, TextFormatting color, Connection c) 
     {
         super(mname, prefix, color);
         data = new HashMap<>();
         back = new HashMap<>();
+        bank = new PlayerBank(this, c);
     }
 
     public PlayerBank getDataBank() 
     {
-        return super.getDataBank(PlayerBank.class);
+        return bank;
     }
     
     public Location saveLocation(EntityPlayer p)
@@ -54,11 +57,21 @@ public class PlayerManager extends Module
     
     public int getGuildId(EntityPlayer p) 
     {
-        int i = getDataBank().getTag(p, "gilde");
+        int i = bank.getTag(p, "gilde");
         if(i == 0)
         {
-            i = -getDataBank().getIdByUUID(p.getUniqueID().toString());
+            i = -bank.getIdByUUID(p.getUniqueID().toString());
         }
         return i;
     }
+    
+    public boolean getPvpStatus(EntityPlayer p) 
+    {
+        return bank.getTag(p, "pvp") >= 1;
+    }
+    
+    public void setPvpStatus(EntityPlayer p, boolean b) 
+    {
+        bank.setTag(p, "pvp", b ? 1 : 0);
+    }
 }

+ 1 - 1
src/main/java/me/km/skills/ActiveSkillContainer.java

@@ -26,7 +26,7 @@ public class ActiveSkillContainer extends SkillContainer
     {
         if(ActiveEffectBase.executeEffect(s.getEffect().getEffectBase(), p, level, level, EffectCause.SKILL))
         {
-            KajetansMod.skills.sendToPlayers(p.world, p.getPositionVector(), 20, "§3" + p.getName() + "§r hat §3" + s.getName() + "§r benutzt.");
+            KajetansMod.skills.sendToPlayers(p.world, p.posX, p.posY, p.posZ, 20, "§3" + p.getName() + "§r hat §3" + s.getName() + "§r benutzt.");
             this.closeSafe(p);
         }
     }

+ 72 - 24
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -9,7 +9,7 @@ import me.km.exception.EntityNotFoundException;
 import me.km.exception.IllegalItemStackStringException;
 import me.km.exception.IllegalStringLocationException;
 import me.km.exception.PlayerNotFoundException;
-import me.km.nms.NmsUtilities;
+import me.km.utils.NBTUtils;
 import me.km.plots.ProtectionBank;
 import me.km.table.TableAPI;
 import java.util.ArrayList;
@@ -40,10 +40,8 @@ import net.minecraft.command.ICommandSender;
 import net.minecraft.enchantment.Enchantment;
 import net.minecraft.enchantment.EnchantmentHelper;
 import net.minecraft.entity.Entity;
-import net.minecraft.entity.EntityHanging;
 import net.minecraft.entity.EntityLiving;
 import net.minecraft.entity.EntityLivingBase;
-import net.minecraft.entity.item.EntityArmorStand;
 import net.minecraft.entity.item.EntityItemFrame;
 import net.minecraft.entity.monster.EntityCreeper;
 import net.minecraft.entity.passive.EntityVillager;
@@ -78,8 +76,11 @@ import me.hammerle.code.SnuviParser;
 import me.hammerle.exceptions.HoldCodeException;
 import me.hammerle.math.Fraction;
 import me.km.inventory.CustomContainer;
+import me.km.networking.ModPacketHandler;
+import me.km.pathfinder.PathfinderUtils;
 import net.minecraft.entity.item.EntityItem;
 import net.minecraft.util.math.MathHelper;
+import net.minecraft.util.text.ITextComponent;
 
 public class MinecraftFunctions implements ISnuviLogger
 {
@@ -150,7 +151,7 @@ public class MinecraftFunctions implements ISnuviLogger
         parser.registerFunction("player.isafk", (args, qd) -> 
                 KajetansMod.afkManager.getEvent(AfkListener.class).isAfk(((EntityPlayer) args[0])));
         parser.registerConsumer("player.speak", (args, qd) -> 
-                sendMessageToGroup(args[0], qd, "§7[§r" + args[1] + "§7] " + ScriptUtils.connect(args, 2)));
+                sendMessageToGroup(args[0], qd, NBTUtils.concat(2, "§7[§r" + args[1] + "§7]§r ", args)));
         parser.registerConsumer("player.setcompass", (args, qd) -> 
                 ((EntityPlayerMP) args[0]).connection.sendPacket(new SPacketSpawnPosition(((Location) args[1]).getBlockPos()))); 
         parser.registerFunction("player.gethunger", (args, qd) -> 
@@ -216,7 +217,7 @@ public class MinecraftFunctions implements ISnuviLogger
         parser.registerConsumer("players.toworldlist", (args, qd) ->     
                 qd.setVar(args[0].toString(), new ArrayList(ModDimensions.getWorldFromName(args[1].toString()).playerEntities)));
         parser.registerConsumer("players.near", (args, qd) ->     
-                qd.setVar(args[0].toString(), new ArrayList(Utils.getNearbyEntities(((Location) args[1]).getWorld(), ((Location) args[1]).getPos(), ScriptUtils.getDouble(args[2]), EntityPlayer.class)))); 
+                nearPlayers(args, qd));
 
         // -------------------------------------------------------------    
         // Rank-Bibliothek
@@ -424,6 +425,8 @@ public class MinecraftFunctions implements ISnuviLogger
                 ((EntityLivingBase) args[0]).setHealth(ScriptUtils.getFloat(args[1])));  
         parser.registerConsumer("entity.setname", (args, qd) -> 
                 nameEntity(args)); 
+        parser.registerFunction("entity.getname", (args, qd) -> 
+                ((Entity) args[0]).getDisplayName().getUnformattedText()); 
         parser.registerConsumer("entity.throw", (args, qd) -> 
                 Utils.setVelocity((Entity) args[0], ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
         parser.registerConsumer("entity.teleport", (args, qd) -> 
@@ -446,20 +449,20 @@ public class MinecraftFunctions implements ISnuviLogger
                 ((Entity) args[0]).setInvisible(false));
         parser.registerConsumer("entity.ride", (args, qd) -> 
                 ((Entity) args[0]).startRiding(((Entity) args[1])));
-        parser.registerConsumer("entity.setvars", (args, qd) -> 
-                ScriptVars.setEntityVars(qd, Utils.getNearestEntity(((Location) args[0]).getWorld(), ((Location) args[0]).getPos(), 3, (Class<? extends Entity>) getClass("net.minecraft.entity." + args[1]))));
         parser.registerConsumer("entity.addeffect", (args, qd) -> 
                 addEffect(args));
         parser.registerFunction("entity.haseffect", (args, qd) -> 
                 ((EntityLivingBase) args[0]).isPotionActive(Potion.getPotionFromResourceLocation(args[1].toString())));
         parser.registerConsumer("entity.goto", (args, qd) ->
-                NmsUtilities.walkTo((EntityLiving) args[0], ((Location) args[1]).getPos(), ScriptUtils.getDouble(args[2])));
+                walkTo(args));
         parser.registerConsumer("entity.explode", (args, qd) -> 
                 ((EntityCreeper) args[0]).ignite());
         parser.registerConsumer("entity.spawnitemframe", (args, qd) -> 
                 spawnItemFrame(args));
         parser.registerFunction("entity.getitemframe", (args, qd) -> 
-                Utils.getNearestEntity(((Location) args[0]).getWorld(), ((Location) args[0]).getPos().addVector(0.5, 0, 0.5), 1, EntityItemFrame.class).getDisplayedItem());
+                ((EntityItemFrame) args[0]).getDisplayedItem());
+        parser.registerFunction("entity.get", (args, qd) -> 
+                getEntity(args));
         parser.registerFunction("entity.getpotiontype", (args, qd) -> 
                 getPotionType(args));
         parser.registerConsumer("entity.setgravity", (args, qd) -> 
@@ -600,6 +603,16 @@ public class MinecraftFunctions implements ISnuviLogger
                 removeFromScoreBoard(args, qd));
         parser.registerConsumer("sb.reset", (args, qd) ->  
                 doForGroup(args[0], qd, p -> KajetansMod.scoreboard.resetScoreboard((EntityPlayerMP) p)));
+        
+        // -------------------------------------------------------------  
+        // Display-Bibliothek   
+        // -------------------------------------------------------------  
+        parser.registerConsumer("display.add", (args, qd) ->  
+                addToDisplay(args, qd)); 
+        parser.registerConsumer("display.remove", (args, qd) ->  
+                removeFromDisplay(args, qd));
+        parser.registerConsumer("display.reset", (args, qd) ->  
+                doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, 3, -1, "")));
 
         // -------------------------------------------------------------  
         // Effect-Bibliothek   
@@ -635,7 +648,7 @@ public class MinecraftFunctions implements ISnuviLogger
         parser.registerFunction("read.item", (args, qd) -> 
                 ScriptHelper.getItemStack(args, 0));
         parser.registerFunction("read.spawnmob", (args, qd) -> 
-                NmsUtilities.getEntityFromNbtString(qd, ScriptUtils.connect(args," ", 1).replace("'", "\""), (Location) args[0]));
+                NBTUtils.fromString(qd, ScriptUtils.connect(args," ", 1).replace("'", "\""), (Location) args[0]));
 
         // -------------------------------------------------------------  
         // Text-Bibliothek   
@@ -646,6 +659,10 @@ public class MinecraftFunctions implements ISnuviLogger
                 ((Location) args[0]).toBlockString());
         parser.registerFunction("text.item", (args, qd) -> 
                 ScriptHelper.getItemStackString((ItemStack) args[0]));
+        parser.registerFunction("text.click", (args, qd) -> 
+                NBTUtils.getClickable(args[0], args[1].toString()));
+        parser.registerFunction("text.hover", (args, qd) -> 
+                NBTUtils.getHoverable(args[0], args[1].toString()));
 
         // -------------------------------------------------------------    
         // Ohne Bibliothek
@@ -659,7 +676,7 @@ public class MinecraftFunctions implements ISnuviLogger
                 setGlobalVar(args));                          
         parser.registerAlias("sgv", "setglobalvar");
         parser.registerConsumer("msg", (args, qd) -> 
-                sendMessageToGroup(args[0], qd, ScriptUtils.connect(args, 1)));       
+                sendMessageToGroup(args[0], qd, NBTUtils.concat(1, args)));       
         parser.registerFunction("removeformat", (args, qd) -> 
                 ScriptUtils.connect(args, 0).replaceAll("§.", ""));           
         parser.registerFunction("concatspace", (args, qd) ->                            
@@ -718,7 +735,7 @@ public class MinecraftFunctions implements ISnuviLogger
         }
         TableAPI.getTable(t, ScriptUtils.getInt(args[2]), args[3].toString(), 
                 args.length >= 5 ? (boolean) args[4] : false)
-                .forEach(s -> sendMessageToGroup(args[0], sc, s));
+                .forEach(s -> sendMessageToGroup(args[0], sc, new TextComponentString(s)));
     }
     
     private static Location getBedLocation(Object[] args)
@@ -746,6 +763,12 @@ public class MinecraftFunctions implements ISnuviLogger
         ((BlockDoor) l.getWorld().getBlockState(pos).getBlock()).toggleDoor(l.getWorld(), pos, (boolean) args[1]);
     }
     
+    private static void walkTo(Object[] args)
+    {
+        Location l = (Location) args[1];
+        PathfinderUtils.walkTo((EntityLiving) args[0], l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2]));
+    }
+    
     private static void playerSay(Object[] args)
     {
         try
@@ -914,11 +937,11 @@ public class MinecraftFunctions implements ISnuviLogger
         Location l = (Location) args[0];
         if(args.length >= 4)
         {
-            NmsUtilities.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), ScriptUtils.connect(args, 3));
+            NBTUtils.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), ScriptUtils.connect(args, 3));
         }
         else
         {
-            NmsUtilities.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), null);
+            NBTUtils.setBlockWithData(l.getWorld(), l.getBlockPos(), ScriptUtils.getInt(args[2]), Block.getBlockFromName(args[1].toString()), null);
         }
         qd.incLoopCounter();
     }
@@ -942,8 +965,9 @@ public class MinecraftFunctions implements ISnuviLogger
     
     private static void playParticle(Object[] args) throws IllegalStringLocationException
     {
-        Location l = ((Location) args[0]).copyAdd(0.5, 0.5, 0.5);
-        EffectUtils.spawnParticle((WorldServer) l.getWorld(), EnumParticleTypes.getByName(args[1].toString()), l.getPos(), ScriptUtils.getInt(args[2]));
+        Location l = ((Location) args[0]);
+        EffectUtils.spawnParticle((WorldServer) l.getWorld(), EnumParticleTypes.getByName(args[1].toString()),
+                l.getX() + 0.5, l.getY() + 0.5, l.getZ() + 0.5, ScriptUtils.getInt(args[2]));
     }
     
     private static void setEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException, IllegalItemStackStringException
@@ -971,7 +995,7 @@ public class MinecraftFunctions implements ISnuviLogger
                 liv.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, stack);
         }
     }  
-    
+
     private static ItemStack getEntityEquip(Object[] args) throws IllegalStringLocationException, EntityNotFoundException
     {
         EntityLivingBase liv = (EntityLivingBase) args[0];        
@@ -1010,12 +1034,12 @@ public class MinecraftFunctions implements ISnuviLogger
     private static void removeEntities(Object[] args) throws IllegalStringLocationException
     {
         Class<? extends Entity> c = (Class<? extends Entity>) getClass(args[0].toString());
-        if(c == Entity.class || c == EntityVillager.class || c == EntityArmorStand.class || c == EntityItemFrame.class || c == EntityHanging.class)
+        if(c == Entity.class)
         {
             return;
         }
         Location l = (Location) args[1];
-        Utils.getNearbyEntities(l.getWorld(), l.getPos(), ScriptUtils.getDouble(args[2]), c).stream().forEach(ent -> 
+        Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2]), c).stream().forEach(ent -> 
         {
             ent.setDead();
         });
@@ -1096,11 +1120,24 @@ public class MinecraftFunctions implements ISnuviLogger
         int id = ScriptUtils.getInt(args[1]);
         doForGroup(args[0], qd, p -> KajetansMod.scoreboard.getScoreboard((EntityPlayerMP) p).removeText(id));
     }
+    
+    private static void addToDisplay(Object[] args, Script qd) throws PlayerNotFoundException
+    {
+        int id = ScriptUtils.getInt(args[1]);
+        String message = ScriptUtils.connect(args, 2);
+        doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, 1, id, message));
+    }
+    
+    private static void removeFromDisplay(Object[] args, Script qd) throws PlayerNotFoundException
+    {
+        int id = ScriptUtils.getInt(args[1]);
+        doForGroup(args[0], qd, p -> ModPacketHandler.sendStats((EntityPlayerMP) p, 2, id, ""));
+    }
 
     private static void sendToActionBar(Object[] args, Script qd) throws PlayerNotFoundException
     {
-        String text = ScriptUtils.connect(args, 1);
-        doForGroup(args[0], qd, p -> NmsUtilities.sendActionBar((EntityPlayerMP) p, text));
+        TextComponentString text = new TextComponentString(ScriptUtils.connect(args, 1));
+        doForGroup(args[0], qd, p -> ((EntityPlayerMP) p).sendStatusMessage(text, true));
     }
 
     private static void kickPlayerFromQuest(Object[] args, Script qd) throws PlayerNotFoundException, UnsupportedOperationException
@@ -1172,6 +1209,12 @@ public class MinecraftFunctions implements ISnuviLogger
         return ds.getImmediateSource();
     }
     
+    private static void nearPlayers(Object[] args, Script sc)
+    {
+        Location l = (Location) args[1];
+        sc.setVar(args[0].toString(), Utils.getPlayers(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[2])));
+    }
+    
     @SuppressWarnings("")
     private static SnuviInventory newInventory(Location l, MinecraftScript qd, String s)
     {
@@ -1203,6 +1246,12 @@ public class MinecraftFunctions implements ISnuviLogger
         return true;
     }
     
+    private static Entity getEntity(Object[] args)
+    {
+        Location l = (Location) args[0];
+        return Utils.getEntity(l.getWorld(), l.getX(), l.getY(), l.getZ(), ScriptUtils.getDouble(args[1]), getClass(args[2].toString()));
+    }
+    
     private static String getName(Object[] args)
     {
         Object o = args[0];
@@ -1393,12 +1442,11 @@ public class MinecraftFunctions implements ISnuviLogger
         c.accept((EntityPlayer) group);
     } 
     
-    private static void sendMessageToGroup(Object group, Script sc, String message)
+    private static void sendMessageToGroup(Object group, Script sc, ITextComponent text)
     {
-        TextComponentString comp = new TextComponentString(message);
         doForGroup(group, sc, p -> 
         {
-            p.sendMessage(comp);
+            p.sendMessage(text);
         });
     }
     

+ 1 - 3
src/main/java/me/km/snuviscript/ScriptVars.java

@@ -38,9 +38,7 @@ public class ScriptVars
 
     public static void setEntityVars(Script qd, Entity ent)
     {
-        qd.setEventVar("entity", ent);
-        qd.setEventVar("entity_name", ent.getDisplayName().getUnformattedText());
-        qd.setEventVar("entity_type", ent.getClass().getSimpleName());             
+        qd.setEventVar("entity", ent);          
     }
 
     public static void setItemVars(Script qd, ItemStack stack)

+ 57 - 34
src/main/java/me/km/nms/NmsUtilities.java → src/main/java/me/km/utils/NBTUtils.java

@@ -1,6 +1,5 @@
-package me.km.nms;
+package me.km.utils;
 
-import java.util.List;
 import me.hammerle.code.Script;
 import me.hammerle.exceptions.HoldCodeException;
 import me.hammerle.exceptions.IllegalStringException;
@@ -10,58 +9,37 @@ import net.minecraft.block.state.IBlockState;
 import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityLiving;
 import net.minecraft.entity.player.EntityPlayer;
-import net.minecraft.entity.player.EntityPlayerMP;
 import net.minecraft.init.Blocks;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.nbt.JsonToNBT;
 import net.minecraft.nbt.NBTException;
 import net.minecraft.nbt.NBTTagCompound;
-import net.minecraft.network.play.server.SPacketChat;
 import net.minecraft.tileentity.TileEntity;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.util.math.Vec3d;
-import net.minecraft.util.text.ChatType;
+import net.minecraft.util.text.ITextComponent;
 import net.minecraft.util.text.Style;
 import net.minecraft.util.text.TextComponentString;
 import net.minecraft.util.text.TextFormatting;
 import net.minecraft.util.text.event.ClickEvent;
+import net.minecraft.util.text.event.HoverEvent;
 import net.minecraft.world.World;
 import net.minecraft.world.chunk.storage.AnvilChunkLoader;
 
-public class NmsUtilities 
+public class NBTUtils 
 {
     // -----------------------------------------------------------------------------------
     // Entity Tools
     // -----------------------------------------------------------------------------------
-    
-    public static List<Entity> getCollidingEntities(Entity e, double x, double y, double z)
-    {
-        return e.getEntityWorld().getEntitiesWithinAABBExcludingEntity(e, e.getCollisionBoundingBox().expand(x, y, z));
-    }
-    
-    public static List<Entity> getCollidingEntities(Entity e)
-    {
-        return getCollidingEntities(e, 0, 0, 0);
-    }   
 
-    public static void walkTo(EntityLiving liv, Vec3d v, double speed)
-    {
-        liv.getMoveHelper().setMoveTo(v.x, v.y, v.z, speed);
-    }
-    
-    public static void canDestroyBlocks(EntityLiving liv)
-    {
-        liv.tasks.addTask(1, new PathfinderGoalDestroyBlock(liv));
-    }
-    
-    public static String getNbtString(Entity ent)
+    public static String toString(Entity ent)
     {
         NBTTagCompound tag = new NBTTagCompound();
         ent.writeToNBTAtomically(tag);
         return tag.toString();
     }
     
-    public static Entity getEntityFromNbtString(Script sc, String s, Location l)
+    public static Entity fromString(Script sc, String s, Location l)
     {
         try 
         {
@@ -125,7 +103,7 @@ public class NmsUtilities
         IBlockState iblockdata = block.getStateFromMeta(dv);
         if(w.setBlockState(pos, iblockdata, 2)) 
         {
-            if (flag) 
+            if(flag) 
             {
                 TileEntity tileentity1 = w.getTileEntity(pos);
                 if (tileentity1 != null) 
@@ -256,12 +234,57 @@ public class NmsUtilities
         p.sendMessage(text);
     }
     
-    // -------------------------------------------------------------------------
-    // Action-Bar
-    // -------------------------------------------------------------------------
+    public static ITextComponent getClickable(Object message, String command)
+    {
+        ITextComponent text; 
+        if(message instanceof ITextComponent)
+        {
+            text = (ITextComponent) message;
+        }
+        else
+        {
+            text = new TextComponentString(String.valueOf(message));
+        }
+        Style style = text.getStyle();
+        style.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, command));
+        return text;
+    }
+    
+    public static ITextComponent getHoverable(Object message, String hover)
+    {
+        ITextComponent text; 
+        if(message instanceof ITextComponent)
+        {
+            text = (ITextComponent) message;
+        }
+        else
+        {
+            text = new TextComponentString(String.valueOf(message));
+        }
+        Style style = text.getStyle();
+        style.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(hover)));
+        return text;
+    }
+    
+    public static ITextComponent concat(int start, String pre, Object... ob)
+    {
+        TextComponentString text = new TextComponentString(pre);
+        for(int i = start; i < ob.length; i++)
+        {
+            if(ob[i] instanceof ITextComponent)
+            {
+                text.appendSibling((ITextComponent) ob[i]);
+            }
+            else
+            {
+                text.appendText(String.valueOf(ob[i]));
+            }
+        }
+        return text;
+    }
     
-    public static void sendActionBar(EntityPlayerMP p, String message) 
+    public static ITextComponent concat(int start, Object... ob)
     {
-        p.connection.sendPacket(new SPacketChat(new TextComponentString(message), ChatType.GAME_INFO));
+        return concat(start, "", ob);
     }
 }

BIN
src/main/resources/assets/km/textures/gui/icons.png