Bladeren bron

bugfix in display, new snuvi commands

Kajetan Johannes Hammerle 7 jaren geleden
bovenliggende
commit
6b1226b93b

+ 1 - 1
src/main/java/me/km/KajetansMod.java

@@ -68,7 +68,7 @@ public class KajetansMod
 
     public static final String MODID = "km";
     public static final String NAME = "Kajetans Mod";
-    public static final String VERSION = "0.0.18";
+    public static final String VERSION = "0.0.19";
 
     @Mod.Instance(MODID)
     public static KajetansMod instance;

+ 2 - 2
src/main/java/me/km/ObjectRegistry.java

@@ -49,7 +49,7 @@ public class ObjectRegistry
         ModBlocks.initItemBlocks(e.getRegistry());
     }
     
-    @SubscribeEvent
+    /*@SubscribeEvent
     public static void onRecipeRegistry(RegistryEvent.Register<IRecipe> e) 
     {
         if(FMLCommonHandler.instance().getSide() == Side.SERVER)
@@ -79,7 +79,7 @@ public class ObjectRegistry
             List<ResourceLocation> recipes = recipeRegistry.getKeys().stream().collect(Collectors.toList());
             recipes.forEach(key -> recipeRegistry.remove(key));
         }
-    }
+    }*/
     
     @SubscribeEvent
     public static void onSoundRegistry(RegistryEvent.Register<SoundEvent> e) 

+ 15 - 0
src/main/java/me/km/api/Location.java

@@ -148,6 +148,21 @@ public class Location
         this.z += z; 
     }
     
+    public void setX(double x)
+    {
+        this.x = x; 
+    }
+    
+    public void setY(double y)
+    {
+        this.y = y; 
+    }
+    
+    public void setZ(double z)
+    {
+        this.z = z; 
+    }
+    
     public void set(double x, double y, double z)
     {
         this.x = x; 

+ 16 - 11
src/main/java/me/km/networking/PlayerDisplay.java

@@ -2,6 +2,7 @@ package me.km.networking;
 
 import io.netty.buffer.ByteBuf;
 import java.nio.charset.StandardCharsets;
+import net.minecraft.client.Minecraft;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
 import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
@@ -60,18 +61,22 @@ public class PlayerDisplay implements IMessage
         @Override
         public IMessage onMessage(PlayerDisplay message, MessageContext ctx) 
         {
-            switch(message.action)
+            Minecraft mc = net.minecraft.client.Minecraft.getMinecraft();
+            mc.addScheduledTask(() -> 
             {
-                case 1:
-                    PlayerDisplayGui.INSTANCE.add(message.index, message.text);
-                    break;
-                case 2:
-                    PlayerDisplayGui.INSTANCE.remove(message.index);
-                    break;
-                case 3: 
-                    PlayerDisplayGui.INSTANCE.clear();
-                    break;
-            }
+                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;
         }
     }

+ 16 - 11
src/main/java/me/km/networking/StatusDisplay.java

@@ -2,6 +2,7 @@ package me.km.networking;
 
 import io.netty.buffer.ByteBuf;
 import java.nio.charset.StandardCharsets;
+import net.minecraft.client.Minecraft;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
 import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
 import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
@@ -69,18 +70,22 @@ public class StatusDisplay implements IMessage
         @Override
         public IMessage onMessage(StatusDisplay message, MessageContext ctx) 
         {
-            switch(message.action)
+            Minecraft mc = net.minecraft.client.Minecraft.getMinecraft();
+            mc.addScheduledTask(() -> 
             {
-                case 1:
-                    StatusDisplayGui.INSTANCE.add(message.index, message.time, message.text);
-                    break;
-                case 2:
-                    StatusDisplayGui.INSTANCE.remove(message.index);
-                    break;
-                case 3: 
-                    StatusDisplayGui.INSTANCE.clear();
-                    break;
-            }
+                switch(message.action)
+                {
+                    case 1:
+                        StatusDisplayGui.INSTANCE.add(message.index, message.time, message.text);
+                        break;
+                    case 2:
+                        StatusDisplayGui.INSTANCE.remove(message.index);
+                        break;
+                    case 3: 
+                        StatusDisplayGui.INSTANCE.clear();
+                        break;
+                }
+            });
             return null;
         }
     }

+ 56 - 3
src/main/java/me/km/snuviscript/MinecraftFunctions.java

@@ -82,7 +82,6 @@ import me.km.pathfinder.PathfinderUtils;
 import me.km.skills.LeveledSkill;
 import me.km.skills.Skill;
 import net.minecraft.entity.item.EntityItem;
-import net.minecraft.inventory.Slot;
 import net.minecraft.util.NonNullList;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.util.text.ITextComponent;
@@ -310,12 +309,46 @@ public class MinecraftFunctions implements ISnuviLogger
         // -------------------------------------------------------------    
         // Location-Bibliothek
         // -------------------------------------------------------------  
-        parser.registerFunction("loc.distance", (args, qd) -> 
-                Fraction.fromDouble(((Location) args[0]).getPos().distanceTo(((Location) args[1]).getPos())));  
+        parser.registerFunction("loc.new", (args, qd) -> 
+                {
+                    if(args.length >= 6)
+                    {
+                        return new Location(ModDimensions.getWorldFromName(args[0].toString()), 
+                                ScriptUtils.getDouble(args[0]), ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), 
+                                ScriptUtils.getFloat(args[3]), ScriptUtils.getFloat(args[4]));
+                    }
+                    return new Location(ModDimensions.getWorldFromName(args[0].toString()), 
+                            ScriptUtils.getDouble(args[0]), ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), 0, 0);
+                });  
+        
+        parser.registerFunction("loc.getx", (args, qd) -> 
+                ((Location) args[0]).getX());  
+        parser.registerFunction("loc.gety", (args, qd) -> 
+                ((Location) args[0]).getY());  
+        parser.registerFunction("loc.getz", (args, qd) -> 
+                ((Location) args[0]).getZ());  
+        
+        parser.registerConsumer("loc.setx", (args, qd) -> 
+                ((Location) args[0]).setX(ScriptUtils.getDouble(args[1])));  
+        parser.registerConsumer("loc.sety", (args, qd) -> 
+                ((Location) args[0]).setY(ScriptUtils.getDouble(args[1])));  
+        parser.registerConsumer("loc.setz", (args, qd) -> 
+                ((Location) args[0]).setZ(ScriptUtils.getDouble(args[1])));  
+        
+        parser.registerConsumer("loc.addx", (args, qd) -> 
+                ((Location) args[0]).addX(ScriptUtils.getDouble(args[1])));  
+        parser.registerConsumer("loc.addy", (args, qd) -> 
+                ((Location) args[0]).addY(ScriptUtils.getDouble(args[1])));  
+        parser.registerConsumer("loc.addz", (args, qd) -> 
+                ((Location) args[0]).addZ(ScriptUtils.getDouble(args[1])));  
+        
         parser.registerConsumer("loc.setyaw", (args, qd) -> 
                 ((Location) args[0]).setYaw(ScriptUtils.getFloat(args[1])));  
         parser.registerConsumer("loc.setpitch", (args, qd) -> 
                 ((Location) args[0]).setPitch(ScriptUtils.getFloat(args[1])));  
+        
+        parser.registerFunction("loc.distance", (args, qd) -> 
+                Fraction.fromDouble(((Location) args[0]).getPos().distanceTo(((Location) args[1]).getPos())));  
         parser.registerFunction("loc.mod", (args, qd) -> 
                 ((Location) args[0]).copyAdd(ScriptUtils.getDouble(args[1]), ScriptUtils.getDouble(args[2]), ScriptUtils.getDouble(args[3])));
         parser.registerFunction("loc.getcoord", (args, qd) -> 
@@ -538,6 +571,15 @@ public class MinecraftFunctions implements ISnuviLogger
                 qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalMapAsTable(args[1].toString())));
         parser.registerFunction("gmap.get", (args, qd) ->    
                 KajetansMod.scripts.getDataBank(ScriptBank.class).getMapValue(args[0].toString(), args[1].toString()));
+        parser.registerFunction("gmap.getordefault", (args, qd) ->    
+                {
+                    Object o = KajetansMod.scripts.getDataBank(ScriptBank.class).getMapValue(args[0].toString(), args[1].toString());
+                    if(o == null)
+                    {
+                        return args[2];
+                    }
+                    return o;
+                });
         
         // -------------------------------------------------------------  
         // GDMap-Bibliothek   
@@ -552,6 +594,15 @@ public class MinecraftFunctions implements ISnuviLogger
                 qd.setVar(args[0].toString(), KajetansMod.scripts.getDataBank(ScriptBank.class).getGlobalDualMapAsTable(args[1].toString(), args[2].toString())));
         parser.registerFunction("gdmap.get", (args, qd) ->    
                 KajetansMod.scripts.getDataBank(ScriptBank.class).getDualMapValue(args[0].toString(), args[1].toString(), args[2].toString()));
+        parser.registerFunction("gdmap.getordefault", (args, qd) ->    
+                {
+                    Object o = KajetansMod.scripts.getDataBank(ScriptBank.class).getDualMapValue(args[0].toString(), args[1].toString(), args[2].toString());
+                    if(o == null)
+                    {
+                        return args[3];
+                    }
+                    return o;
+                });
 
         // -------------------------------------------------------------  
         // Table-Bibliothek   
@@ -576,6 +627,8 @@ public class MinecraftFunctions implements ISnuviLogger
                 ((Table) args[0]).removeRow(ScriptUtils.getInt(args[1])));
         parser.registerFunction("table.get", (args, qd) -> 
                 ((Table) args[0]).getElement(ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2])));
+        parser.registerConsumer("table.set", (args, qd) -> 
+                ((Table) args[0]).setElement(ScriptUtils.getInt(args[1]), ScriptUtils.getInt(args[2]), args[3]));
         parser.registerFunction("table.getindexof", (args, qd) -> 
                 new Fraction(((Table) args[0]).getIndexOf(args[1])));
         parser.registerConsumer("table.setsortcolumn", (args, qd) -> 

+ 1 - 1
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -837,4 +837,4 @@ public class ScriptEvents extends ModuleListener
             itemEnt.setDead();                
         }, 40);                    
     }*/
-}
+}

+ 5 - 0
src/main/java/me/km/table/Table.java

@@ -48,6 +48,11 @@ public class Table
         list.remove(i);
     }
     
+    public void setElement(int row, int column, Object o)
+    {
+        list.get(row)[column] = o;
+    }
+    
     public Object getElement(int row, int column)
     {
         return list.get(row)[column];