Quellcode durchsuchen

persistent entity attribute commands, removal of bugged player.setspeed

Kajetan Johannes Hammerle vor 4 Jahren
Ursprung
Commit
f37d99a561

+ 10 - 0
src/main/java/me/km/snuviscript/commands/LivingCommands.java

@@ -38,6 +38,16 @@ public class LivingCommands {
                 a.removeModifier(uuid);
                 a.applyNonPersistentModifier(new AttributeModifier(uuid, name, amount, AttributeModifier.Operation.ADDITION));
             });
+            sm.registerConsumer("living.setpersistent" + name, (sc, in) -> {
+                ModifiableAttributeInstance a = ((LivingEntity) in[0].get(sc)).getAttribute(attribute);
+                if(a == null) {
+                    return;
+                }
+                double amount = in[1].getDouble(sc) - a.getBaseValue();
+                UUID uuid = new UUID(name.length(), name.hashCode());
+                a.removeModifier(uuid);
+                a.applyPersistentModifier(new AttributeModifier(uuid, name, amount, AttributeModifier.Operation.ADDITION));
+            });
             sm.registerFunction("living.get" + name, (sc, in) -> {
                 ModifiableAttributeInstance a = ((LivingEntity) in[0].get(sc)).getAttribute(attribute);
                 return a == null ? null : a.getValue();

+ 0 - 8
src/main/java/me/km/snuviscript/commands/PlayerCommands.java

@@ -258,14 +258,6 @@ public class PlayerCommands {
             com.put("SkullOwner", NBTUtil.writeGameProfile(new CompoundNBT(), gp));
             return stack;
         });
-        sm.registerFunction("player.setspeed", (sc, in) -> {
-            PlayerEntity p = (PlayerEntity) in[0].get(sc);
-            float f = in[1].getFloat(sc);
-            ReflectionUtils.setFlySpeed(p.abilities, f);
-            ReflectionUtils.setWalkSpeed(p.abilities, f * 2);
-            p.sendPlayerAbilities();
-            return true;
-        });
         sm.registerFunction("player.near", (sc, in) -> Utils.getPlayers((Entity) in[0].get(sc), in[1].getDouble(sc)));
         sm.registerFunction("player.getinv", (sc, in) -> ((PlayerEntity) in[0].get(sc)).inventory);
         sm.registerFunction("player.getinvslot", (sc, in) -> ((PlayerEntity) in[0].get(sc)).inventory.mainInventory.get(in[1].getInt(sc)));

+ 1 - 16
src/main/java/me/km/utils/ReflectionUtils.java

@@ -140,22 +140,7 @@ public class ReflectionUtils {
     public static void setSaturation(FoodStats stats, float f) {
         setFloat(stats, FOOD_SATURATION_LEVEL, f);
     }
-
-    // -----------------------------------------------------------------------------------
-    // player stats
-    // -----------------------------------------------------------------------------------
-    private final static Field FLY_SPEED = getField(PlayerAbilities.class, "field_75096_f"); // flySpeed
-
-    public static void setFlySpeed(PlayerAbilities cap, float f) {
-        setFloat(cap, FLY_SPEED, f);
-    }
-
-    private final static Field WALK_SPEED = getField(PlayerAbilities.class, "field_75097_g"); // walkSpeed
-
-    public static void setWalkSpeed(PlayerAbilities cap, float f) {
-        setFloat(cap, WALK_SPEED, f);
-    }
-
+    
     // -----------------------------------------------------------------------------------
     // PlayerList
     // -----------------------------------------------------------------------------------