Browse Source

removal of several deprecated functions, several entity commands moved
to living

Kajetan Johannes Hammerle 2 years ago
parent
commit
97d8ebc33c

+ 1 - 10
src/main/java/me/km/Server.java

@@ -21,10 +21,7 @@ import net.minecraftforge.api.distmarker.Dist;
 import net.minecraftforge.api.distmarker.OnlyIn;
 import net.minecraftforge.common.MinecraftForge;
 import me.km.snuviscript.CommandScript;
-import me.km.snuviscript.DummyScriptBank;
-import me.km.snuviscript.IScriptBank;
 import me.km.snuviscript.MinecraftFunctions;
-import me.km.snuviscript.ScriptBank;
 import me.km.snuviscript.ScriptEvents;
 import me.km.snuviscript.Scripts;
 
@@ -106,14 +103,8 @@ public class Server {
         MinecraftForge.EVENT_BUS.register(customEventCaller);
 
         // scripts
-        IScriptBank scriptBank;
-        if(databank.isDummyDatabank()) {
-            scriptBank = new DummyScriptBank();
-        } else {
-            scriptBank = new ScriptBank(databank, playerManager);
-        }
         MinecraftFunctions.registerFunctions(scripts.getScriptManager(), scripts, perms, scheduler,
-                server, playerBank, customEventCaller, scriptBank, databank, plotMap, commands);
+                server, playerBank, customEventCaller, databank, plotMap, commands);
 
         scheduler.scheduleTask(() -> scripts.startScript(null, "startscript"));
     }

+ 0 - 16
src/main/java/me/km/snuviscript/DummyScriptBank.java

@@ -1,16 +0,0 @@
-package me.km.snuviscript;
-
-public class DummyScriptBank implements IScriptBank {
-    @Override
-    public void setVar(String value, String var, int playerId) {
-    }
-
-    @Override
-    public void deleteVar(String var, int playerId) {
-    }
-
-    @Override
-    public Object getVar(String var, int playerId, Object error) {
-        return error;
-    }
-}

+ 0 - 13
src/main/java/me/km/snuviscript/IScriptBank.java

@@ -1,13 +0,0 @@
-package me.km.snuviscript;
-
-public interface IScriptBank {
-    public void setVar(String value, String var, int playerId) throws Exception;
-
-    public void deleteVar(String var, int playerId) throws Exception;
-
-    public Object getVar(String var, int playerId, Object error) throws Exception;
-
-    public default Object getVar(String var, int playerId) throws Exception {
-        return getVar(var, playerId, null);
-    }
-}

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

@@ -14,7 +14,7 @@ import me.km.snuviscript.commands.*;
 public class MinecraftFunctions {
     public static void registerFunctions(ScriptManager sm, Scripts scripts, Permissions perms,
             SnuviScheduler scheduler, MinecraftServer server, IPlayerBank playerBank,
-            CustomEventCaller cec, IScriptBank scriptBank, DataBank dataBank, WorldPlotMap plots,
+            CustomEventCaller cec, DataBank dataBank, WorldPlotMap plots,
             ModCommandManager commands) {
         CommandCommands.registerFunctions(sm, scripts, perms, server, commands);
         PermissionCommands.registerFunctions(sm, perms);
@@ -28,11 +28,9 @@ public class MinecraftFunctions {
         BlockCommands.registerFunctions(sm);
         EventCommands.registerFunctions(sm, cec);
         DamageCommands.registerFunctions(sm);
-        EntityCommands.registerFunctions(sm, scheduler);
-        LivingCommands.registerFunctions(sm);
+        EntityCommands.registerFunctions(sm);
+        LivingCommands.registerFunctions(sm, scheduler);
         HumanCommands.registerFunctions(sm);
-        DeprecatedCommands.registerFunctions(sm, scripts, perms, scheduler, server, playerBank, cec,
-                scriptBank, dataBank, plots, commands);
         DatabankCommands.registerFunctions(sm, scheduler, dataBank);
         PlotCommands.registerFunctions(sm, plots);
         ScriptCommands.registerFunctions(sm, scripts, server);

+ 0 - 64
src/main/java/me/km/snuviscript/ScriptBank.java

@@ -1,64 +0,0 @@
-package me.km.snuviscript;
-
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import me.hammerle.snuviscript.code.SnuviUtils;
-import me.km.databank.DataBank;
-import me.km.playerbank.PlayerManager;
-
-public class ScriptBank implements IScriptBank {
-    private final DataBank databank;
-    private final PreparedStatement getVar;
-
-    public ScriptBank(DataBank databank, PlayerManager manager) {
-        this.databank = databank;
-        databank.execute("CREATE TABLE IF NOT EXISTS scriptdata ("
-                + "id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
-                + "player_id INT NOT NULL, "
-                + "var VARCHAR(20) NOT NULL, "
-                + "value VARCHAR(256) NOT NULL, "
-                + "UNIQUE INDEX (player_id,var), "
-                + "FOREIGN KEY (player_id) REFERENCES minecraft.players(id) ON DELETE RESTRICT);");
-
-        getVar = databank.prepareStatement("SELECT value from scriptdata WHERE player_id = ? and var = ?;");
-    }
-
-    @Override
-    public void setVar(String value, String var, int playerId) throws Exception {
-        try(PreparedStatement setVar = databank.prepareStatement(
-                "INSERT INTO scriptdata (player_id,var,value) SELECT ?, ?, ? ON DUPLICATE KEY UPDATE scriptdata.value=?;")) {
-            setVar.setInt(1, playerId);
-            setVar.setString(2, var);
-            setVar.setString(3, value);
-            setVar.setString(4, value);
-            setVar.executeUpdate();
-        }
-    }
-
-    @Override
-    public void deleteVar(String var, int playerId) throws Exception {
-        try(PreparedStatement deleteVar = databank.prepareStatement(
-                "DELETE FROM scriptdata WHERE player_id = ? AND var = ?;")) {
-            deleteVar.setInt(1, playerId);
-            deleteVar.setString(2, var);
-            deleteVar.executeUpdate();
-        }
-    }
-
-    @Override
-    public Object getVar(String var, int playerId, Object error) throws Exception {
-        getVar.setInt(1, playerId);
-        getVar.setString(2, var);
-        try(ResultSet rs = getVar.executeQuery()) {
-            if(rs.next()) {
-                return SnuviUtils.convert(rs.getString(1));
-            }
-            return error;
-        }
-    }
-
-    @Override
-    public Object getVar(String var, int playerId) throws Exception {
-        return getVar(var, playerId, null);
-    }
-}

+ 34 - 5
src/main/java/me/km/snuviscript/commands/BlockCommands.java

@@ -18,6 +18,9 @@ import net.minecraft.inventory.IInventory;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.network.play.server.SUpdateTileEntityPacket;
+import net.minecraft.state.BooleanProperty;
+import net.minecraft.state.EnumProperty;
+import net.minecraft.state.IntegerProperty;
 import net.minecraft.state.Property;
 import net.minecraft.state.properties.ChestType;
 import net.minecraft.tags.BlockTags;
@@ -100,9 +103,14 @@ public class BlockCommands {
             Location l = (Location) in[0].get(sc);
             return l.getWorld().getBlockState(l.getBlockPos()).getBlock();
         });
+        sm.registerFunction("block.getproperties", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            return l.getWorld().getBlockState(l.getBlockPos()).getBlock().getStateContainer()
+                    .getProperties();
+        });
         sm.registerFunction("block.getproperty",
                 (sc, in) -> Mapper.getProperty(in[0].getString(sc)));
-        sm.registerFunction("block.getstate", (sc, in) -> {
+        sm.registerFunction("block.property.getvalue", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             Property<?> prop = (Property) in[1].get(sc);
             BlockState state = l.getWorld().getBlockState(l.getBlockPos());
@@ -117,6 +125,31 @@ public class BlockCommands {
             }
             return null;
         });
+        sm.registerConsumer("block.property.setint", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            World w = l.getWorld();
+            BlockPos pos = l.getBlockPos();
+            IntegerProperty prop = (IntegerProperty) in[1].get(sc);
+            BlockState state = w.getBlockState(pos);
+            w.setBlockState(pos, state.with(prop, in[2].getInt(sc)), 18);
+        });
+        sm.registerConsumer("block.property.setbool", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            World w = l.getWorld();
+            BlockPos pos = l.getBlockPos();
+            BooleanProperty prop = (BooleanProperty) in[1].get(sc);
+            BlockState state = w.getBlockState(pos);
+            w.setBlockState(pos, state.with(prop, in[2].getBoolean(sc)), 18);
+        });
+        sm.registerConsumer("block.property.setenum", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            World w = l.getWorld();
+            BlockPos pos = l.getBlockPos();
+            EnumProperty prop = (EnumProperty) in[1].get(sc);
+            Enum e = (Enum) prop.parseValue(in[2].getString(sc)).get();
+            BlockState state = w.getBlockState(pos);
+            w.setBlockState(pos, state.with(prop, e), 18);
+        });
         sm.registerConsumer("block.clone", (sc, in) -> {
             Location l0 = (Location) in[0].get(sc);
             Location l1 = (Location) in[1].get(sc);
@@ -228,10 +261,6 @@ public class BlockCommands {
             Location l = (Location) in[0].get(sc);
             return l.getBlockState().get(DoorBlock.OPEN);
         });
-        sm.registerFunction("block.isdoor", (sc, in) -> {
-            Location l = (Location) in[0].get(sc);
-            return l.getWorld().getBlockState(l.getBlockPos()).getBlock() instanceof DoorBlock;
-        });
         sm.registerFunction("block.issolid", (sc, in) -> {
             return CommandUtils.getBlockState((Location) in[0].get(sc)).isSolid();
         });

+ 0 - 58
src/main/java/me/km/snuviscript/commands/DeprecatedCommands.java

@@ -1,58 +0,0 @@
-package me.km.snuviscript.commands;
-
-import me.hammerle.snuviscript.code.ScriptManager;
-import me.km.databank.DataBank;
-import me.km.events.CustomEventCaller;
-import me.km.permissions.ModCommandManager;
-import me.km.permissions.Permissions;
-import me.km.playerbank.IPlayerBank;
-import me.km.plots.WorldPlotMap;
-import me.km.scheduler.SnuviScheduler;
-import me.km.snuviscript.IScriptBank;
-import me.km.snuviscript.Scripts;
-import static me.km.snuviscript.commands.CommandUtils.getId;
-import net.minecraft.server.MinecraftServer;
-
-public class DeprecatedCommands {
-    public static void registerFunctions(ScriptManager sm, Scripts scripts, Permissions perms, SnuviScheduler scheduler,
-            MinecraftServer server, IPlayerBank playerBank, CustomEventCaller cec, IScriptBank scriptBank,
-            DataBank dataBank, WorldPlotMap plots, ModCommandManager commands) {
-        sm.registerFunction("getglobalvar", (sc, in) -> {
-            Object o = in[0].get(sc);
-            if(in.length == 2) {
-                return scriptBank.getVar(in[1].getString(sc), getId(playerBank, o));
-            }
-            return scriptBank.getVar(in[1].getString(sc), getId(playerBank, o), in[2].get(sc));
-        });
-        sm.registerAlias("getglobalvar", "ggv");
-        sm.registerConsumer("setglobalvar", (sc, in) -> {
-            final String value = in[2].getString(sc);
-            final String var = in[1].getString(sc);
-            final int id = getId(playerBank, in[0].get(sc));
-            scheduler.scheduleAsyncTask(() -> {
-                try {
-                    scriptBank.setVar(value, var, id);
-                } catch(Exception ex) {
-                    scheduler.scheduleTask(() -> {
-                        sc.getScriptManager().getLogger().print("Worker error", ex, null, sc.getName(), sc, null);
-                    });
-                }
-            });
-        });
-        sm.registerAlias("setglobalvar", "sgv");
-        sm.registerConsumer("delglobalvar", (sc, in) -> {
-            final String var = in[1].getString(sc);
-            final int id = getId(playerBank, in[0].get(sc));
-            scheduler.scheduleAsyncTask(() -> {
-                try {
-                    scriptBank.deleteVar(var, id);
-                } catch(Exception ex) {
-                    scheduler.scheduleTask(() -> {
-                        sc.getScriptManager().getLogger().print("Worker error", ex, null, sc.getName(), sc, null);
-                    });
-                }
-            });
-        });
-        sm.registerAlias("delglobalvar", "dgv");
-    }
-}

+ 54 - 174
src/main/java/me/km/snuviscript/commands/EntityCommands.java

@@ -1,8 +1,6 @@
 package me.km.snuviscript.commands;
 
 import me.hammerle.snuviscript.code.ScriptManager;
-import me.km.entities.EntityItemProjectile;
-import me.km.scheduler.SnuviScheduler;
 import static me.km.snuviscript.commands.CommandUtils.getNamedClass;
 import me.km.utils.Location;
 import me.km.utils.Mapper;
@@ -17,7 +15,6 @@ import net.minecraft.entity.passive.TameableEntity;
 import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.entity.player.ServerPlayerEntity;
 import net.minecraft.entity.projectile.*;
-import net.minecraft.inventory.EquipmentSlotType;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.nbt.JsonToNBT;
@@ -34,21 +31,17 @@ import net.minecraft.world.server.ServerWorld;
 
 public class EntityCommands {
     @SuppressWarnings("unchecked")
-    public static void registerFunctions(ScriptManager sm, SnuviScheduler scheduler) {
+    public static void registerFunctions(ScriptManager sm) {
         sm.registerConsumer("entity.setnopickup", (sc, in) -> {
-            ((AbstractArrowEntity) in[0].get(sc)).pickupStatus = AbstractArrowEntity.PickupStatus.DISALLOWED;
-        });
-        sm.registerFunction("entity.shootprojectile", (sc, in) -> launchProjectile((LivingEntity) in[0].get(sc),
-                getNamedClass(in[1].getString(sc)), in[2].getDouble(sc), in.length >= 4 ? in[3].get(sc) : null));
-        sm.registerFunction("entity.isblocking",
-                (sc, in) -> ((LivingEntity) in[0].get(sc)).isActiveItemStackBlocking());
-        sm.registerFunction("entity.getarmorthoughness",
-                (sc, in) -> ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.ARMOR_TOUGHNESS).getValue());
-        sm.registerFunction("entity.getarmor",
-                (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getTotalArmorValue());
-        sm.registerFunction("entity.getenchantmentmodifier", (sc, in) -> EnchantmentHelper.getEnchantmentModifierDamage(
-                ((LivingEntity) in[0].get(sc)).getArmorInventoryList(), (DamageSource) in[1].get(sc)));
-        sm.registerConsumer("entity.setburning", (sc, in) -> ((Entity) in[0].get(sc)).forceFireTicks(in[1].getInt(sc)));
+            ((AbstractArrowEntity) in[0].get(sc)).pickupStatus =
+                    AbstractArrowEntity.PickupStatus.DISALLOWED;
+        });
+        sm.registerFunction("entity.getenchantmentmodifier",
+                (sc, in) -> EnchantmentHelper.getEnchantmentModifierDamage(
+                        ((LivingEntity) in[0].get(sc)).getArmorInventoryList(),
+                        (DamageSource) in[1].get(sc)));
+        sm.registerConsumer("entity.setburning",
+                (sc, in) -> ((Entity) in[0].get(sc)).forceFireTicks(in[1].getInt(sc)));
         sm.registerFunction("entity.isburning", (sc, in) -> ((Entity) in[0].get(sc)).isBurning());
         sm.registerFunction("entity.getlook", (sc, in) -> {
             Object[] o = new Object[3];
@@ -67,40 +60,17 @@ public class EntityCommands {
             return o;
         });
         sm.registerFunction("entity.getlocation", (sc, in) -> new Location((Entity) in[0].get(sc)));
-        sm.registerConsumer("entity.heal", (sc, in) -> {
-            LivingEntity liv = (LivingEntity) in[0].get(sc);
-            float heal = in[1].getFloat(sc);
-            scheduler.scheduleTask(() -> liv.heal(heal));
-        });
-        sm.registerConsumer("entity.damage", (sc, in) -> {
-            LivingEntity liv = (LivingEntity) in[0].get(sc);
-            float damage = in[1].getFloat(sc);
-            DamageSource damageSource = (in.length >= 3) ? (DamageSource) in[2].get(sc) : DamageSource.GENERIC;
-            scheduler.scheduleTask(() -> liv.attackEntityFrom(damageSource, damage));
-        });
-        sm.registerFunction("entity.fromsource", (sc, in) -> {
-            DamageSource ds = (DamageSource) in[0].get(sc);
-            Entity ent = ds.getTrueSource();
-            if (ent == null) {
-                return ds.getImmediateSource();
-            }
-            return ent;
-        });
-        sm.registerAlias("damage.get", "entity.getdamagesource");
-        sm.registerFunction("entity.getmaxhealth", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getMaxHealth());
-        sm.registerFunction("entity.gethealth", (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getHealth());
-        sm.registerConsumer("entity.sethealth",
-                (sc, in) -> ((LivingEntity) in[0].get(sc)).setHealth(in[1].getFloat(sc)));
         sm.registerConsumer("entity.setname", (sc, in) -> {
             Entity ent = (Entity) in[0].get(sc);
             ent.setCustomName(new StringTextComponent(in[1].getString(sc)));
-            if (in.length >= 3) {
+            if(in.length >= 3) {
                 ent.setCustomNameVisible(in[2].getBoolean(sc));
                 return;
             }
             ent.setCustomNameVisible(false);
         });
-        sm.registerFunction("entity.getname", (sc, in) -> ((Entity) in[0].get(sc)).getDisplayName().getString());
+        sm.registerFunction("entity.getname",
+                (sc, in) -> ((Entity) in[0].get(sc)).getDisplayName().getString());
         sm.registerConsumer("entity.throw", (sc, in) -> {
             Entity ent = (Entity) in[0].get(sc);
             ent.setMotion(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc));
@@ -109,14 +79,14 @@ public class EntityCommands {
         sm.registerConsumer("entity.teleport", (sc, in) -> {
             Entity ent = (Entity) in[0].get(sc);
             Location l = (Location) in[1].get(sc);
-            if (l.getWorld() == null) {
+            if(l.getWorld() == null) {
                 throw new IllegalArgumentException("world must not be null");
             }
-            if (ent instanceof ServerPlayerEntity) {
+            if(ent instanceof ServerPlayerEntity) {
                 ServerPlayerEntity p = (ServerPlayerEntity) ent;
 
                 p.stopRiding();
-                if (p.isSleeping()) {
+                if(p.isSleeping()) {
                     p.stopSleepInBed(true, true);
                 }
 
@@ -124,7 +94,7 @@ public class EntityCommands {
                 float pitch = l.getPitch() != 0.0f ? l.getPitch() : ent.rotationPitch;
                 p.teleport((ServerWorld) l.getWorld(), l.getX(), l.getY(), l.getZ(), yaw, pitch);
             } else {
-                if (ent.world != l.getWorld()) {
+                if(ent.world != l.getWorld()) {
                     ServerWorld ws = (ServerWorld) l.getWorld();
                     ent.changeDimension(ws);
                 }
@@ -133,55 +103,16 @@ public class EntityCommands {
                 ent.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), yaw, pitch);
             }
         });
-        sm.registerConsumer("entity.setequip", (sc, in) -> {
-            LivingEntity liv = (LivingEntity) in[0].get(sc);
-            ItemStack stack = ((ItemStack) in[2].get(sc)).copy();
-            switch (in[1].getString(sc)) {
-                case "hand":
-                    liv.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
-                    return;
-                case "head":
-                    liv.setItemStackToSlot(EquipmentSlotType.HEAD, stack);
-                    return;
-                case "chest":
-                    liv.setItemStackToSlot(EquipmentSlotType.CHEST, stack);
-                    return;
-                case "legs":
-                    liv.setItemStackToSlot(EquipmentSlotType.LEGS, stack);
-                    return;
-                case "feet":
-                    liv.setItemStackToSlot(EquipmentSlotType.FEET, stack);
-                    return;
-                case "offhand":
-                    liv.setItemStackToSlot(EquipmentSlotType.OFFHAND, stack);
-            }
-        });
-        sm.registerFunction("entity.getequip", (sc, in) -> {
-            LivingEntity liv = (LivingEntity) in[0].get(sc);
-            switch (in[1].getString(sc)) {
-                case "hand":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.MAINHAND);
-                case "head":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.HEAD);
-                case "chest":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.CHEST);
-                case "legs":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.LEGS);
-                case "feet":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.FEET);
-                case "offhand":
-                    return liv.getItemStackFromSlot(EquipmentSlotType.OFFHAND);
-            }
-            return ItemStack.EMPTY;
-        });
+
         sm.registerConsumer("entity.removeall", (sc, in) -> {
-            Class<? extends Entity> c = (Class<? extends Entity>) getNamedClass(in[0].getString(sc));
-            if (c == Entity.class) {
+            Class<? extends Entity> c =
+                    (Class<? extends Entity>) getNamedClass(in[0].getString(sc));
+            if(c == Entity.class) {
                 return;
             }
             Location l = (Location) in[1].get(sc);
-            Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[2].getDouble(sc), c).stream()
-                    .forEach(ent -> {
+            Utils.getEntities(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[2].getDouble(sc), c)
+                    .stream().forEach(ent -> {
                         ent.remove();
                     });
         });
@@ -204,14 +135,15 @@ public class EntityCommands {
         sm.registerConsumer("entity.addeffect", (sc, in) -> {
             LivingEntity base = (LivingEntity) in[0].get(sc);
             Effect potion = Mapper.getPotion(in[1].getString(sc));
-            if (potion == null) { // doing this only to prevent EffectInstance doing shit
+            if(potion == null) { // doing this only to prevent EffectInstance doing shit
                 throw new IllegalArgumentException("potion does not exist");
             }
-            if (base.isPotionActive(potion)) {
+            if(base.isPotionActive(potion)) {
                 base.removePotionEffect(potion);
             }
             boolean showParticles = in.length >= 5 ? in[4].getBoolean(sc) : true;
-            base.addPotionEffect(new EffectInstance(potion, in[2].getInt(sc), in[3].getInt(sc), false, showParticles));
+            base.addPotionEffect(new EffectInstance(potion, in[2].getInt(sc), in[3].getInt(sc),
+                    false, showParticles));
         });
         sm.registerConsumer("entity.cleareffects", (sc, in) -> {
             ((LivingEntity) in[0].get(sc)).clearActivePotions();
@@ -235,8 +167,9 @@ public class EntityCommands {
             return Utils.getEntity(l.getWorld(), l.getX(), l.getY(), l.getZ(), in[1].getDouble(sc),
                     (Class<? extends Entity>) getNamedClass(in[2].getString(sc)));
         });
-        sm.registerFunction("entity.getpotiontype", (sc, in) -> PotionUtils
-                .getPotionFromItem(((PotionEntity) in[0].get(sc)).getItem()).getRegistryName().toString());
+        sm.registerFunction("entity.getpotiontype",
+                (sc, in) -> PotionUtils.getPotionFromItem(((PotionEntity) in[0].get(sc)).getItem())
+                        .getRegistryName().toString());
         sm.registerConsumer("entity.setgravity", (sc, in) -> {
             ((Entity) in[0].get(sc)).setNoGravity(!in[1].getBoolean(sc));
         });
@@ -247,119 +180,66 @@ public class EntityCommands {
         sm.registerFunction("entity.spawn", (sc, in) -> {
             ResourceLocation type = new ResourceLocation(in[0].getString(sc));
             Location l = (Location) in[1].get(sc);
-            if (!World.isInvalidPosition(l.getBlockPos())) {
+            if(!World.isInvalidPosition(l.getBlockPos())) {
                 return null;
             }
-            CompoundNBT nbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc)) : new CompoundNBT();
+            CompoundNBT nbt = in.length >= 3 ? JsonToNBT.getTagFromJson(in[2].getString(sc))
+                    : new CompoundNBT();
             nbt.putString("id", type.toString());
             ServerWorld sw = (ServerWorld) l.getWorld();
             Entity ent = EntityType.loadEntityAndExecute(nbt, sw, (e) -> {
-                e.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), e.rotationYaw, e.rotationPitch);
+                e.setLocationAndAngles(l.getX(), l.getY(), l.getZ(), e.rotationYaw,
+                        e.rotationPitch);
                 return e;
             });
-            if (ent == null) {
+            if(ent == null) {
                 return ent;
             }
-            if (ent instanceof MobEntity) {
+            if(ent instanceof MobEntity) {
                 ((MobEntity) ent).onInitialSpawn(sw, sw.getDifficultyForLocation(ent.getPosition()),
                         SpawnReason.COMMAND, null, null);
             }
-            if (!sw.func_242106_g(ent)) {
+            if(!sw.func_242106_g(ent)) {
                 return null;
             }
             return ent;
         });
         sm.registerFunction("entity.near", (sc, in) -> {
             Object o = in[0].get(sc);
-            if (o instanceof Location) {
+            if(o instanceof Location) {
                 return Utils.getEntities((Location) o, in[1].getDouble(sc));
             }
             return Utils.getEntities((Entity) o, in[1].getDouble(sc));
         });
         sm.registerConsumer("entity.setspeed", (sc, in) -> {
-            ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(in[1].getDouble(sc));
+            ((LivingEntity) in[0].get(sc)).getAttribute(Attributes.MOVEMENT_SPEED)
+                    .setBaseValue(in[1].getDouble(sc));
         });
         sm.registerConsumer("entity.setgrowingage", (sc, in) -> {
             ((AgeableEntity) in[0].get(sc)).setGrowingAge(in[1].getInt(sc));
         });
         sm.registerFunction("entity.gettype",
                 (sc, in) -> ((Entity) in[0].get(sc)).getType().getRegistryName().getPath());
-        sm.registerFunction("entity.issneaking", (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
-        sm.registerFunction("entity.issneaking", (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
-        sm.registerFunction("sheep.issheared", (sc, in) -> ((SheepEntity) in[0].get(sc)).getSheared());
-        sm.registerFunction("sheep.getcolor", (sc, in) -> ((SheepEntity) in[0].get(sc)).getFleeceColor().toString());
-        sm.registerConsumer("creeper.explode", (sc, in) -> ((CreeperEntity) in[0].get(sc)).ignite());
+        sm.registerFunction("entity.issneaking",
+                (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
+        sm.registerFunction("entity.issneaking",
+                (sc, in) -> ((Entity) in[0].get(sc)).isCrouching());
+        sm.registerFunction("sheep.issheared",
+                (sc, in) -> ((SheepEntity) in[0].get(sc)).getSheared());
+        sm.registerFunction("sheep.getcolor",
+                (sc, in) -> ((SheepEntity) in[0].get(sc)).getFleeceColor().toString());
+        sm.registerConsumer("creeper.explode",
+                (sc, in) -> ((CreeperEntity) in[0].get(sc)).ignite());
         sm.registerFunction("pet.istamed", (sc, in) -> ((TameableEntity) in[0].get(sc)).isTamed());
         sm.registerConsumer("pet.settamed", (sc, in) -> {
             TameableEntity t = (TameableEntity) in[0].get(sc);
             boolean b = in[1].getBoolean(sc);
-            if (b) {
+            if(b) {
                 t.setTamedBy((PlayerEntity) in[2].get(sc));
             }
             t.setTamed(b);
         });
-        sm.registerFunction("pet.getowner", (sc, in) -> ((TameableEntity) in[0].get(sc)).getOwner());
-    }
-
-    @SuppressWarnings("unchecked")
-    private static <T> T launchProjectile(LivingEntity liv, Class<? extends T> projectile, double scale, Object data) {
-        World w = liv.world;
-        Entity launch = null;
-
-        if (EntityItemProjectile.class == projectile) {
-            if (data == null) {
-                throw new NullPointerException("Data musn't be null for EntityItemProjectile");
-            }
-            ItemStack stack = (ItemStack) data;
-            if (stack.isEmpty()) {
-                throw new IllegalArgumentException("Empty ItemStack not allowed here");
-            }
-            launch = new EntityItemProjectile(liv, stack.copy());
-            ((EntityItemProjectile) launch).setHeadingFromThrower(liv, liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f,
-                    1.0f);
-        } else if (SnowballEntity.class == projectile) {
-            launch = new SnowballEntity(w, liv);
-            ((SnowballEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
-        } else if (EggEntity.class == projectile) {
-            launch = new EggEntity(w, liv);
-            ((EggEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
-        } else if (EnderPearlEntity.class == projectile) {
-            launch = new EnderPearlEntity(w, liv);
-            ((EnderPearlEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
-        } else if (PotionEntity.class == projectile) {
-            launch = new PotionEntity(w, liv);
-            ((PotionEntity) launch).setItem((ItemStack) data);
-            ((PotionEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f, 0.5f, 1.0f);
-        } else if (ExperienceBottleEntity.class == projectile) {
-            launch = new ExperienceBottleEntity(w, liv);
-            ((ExperienceBottleEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f, 0.7f, 1.0f);
-        } else if (AbstractArrowEntity.class.isAssignableFrom(projectile)) {
-            if (SpectralArrowEntity.class == projectile) {
-                launch = new SpectralArrowEntity(w, liv);
-            } else {
-                launch = new ArrowEntity(w, liv);
-                if (data != null) {
-                    ((ArrowEntity) launch).setPotionEffect((ItemStack) data);
-                }
-            }
-            ((AbstractArrowEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0F, 3.0F, 1.0F);
-        } else if (DamagingProjectileEntity.class.isAssignableFrom(projectile)) {
-            Vector3d v = liv.getLookVec().scale(10);
-            if (SmallFireballEntity.class == projectile) {
-                launch = new SmallFireballEntity(w, liv, v.x, v.y, v.z);
-            } else if (WitherSkullEntity.class == projectile) {
-                launch = new WitherSkullEntity(w, liv, v.x, v.y, v.z);
-            } else if (DragonFireballEntity.class == projectile) {
-                launch = new DragonFireballEntity(w, liv, v.x, v.y, v.z);
-            } else {
-                launch = new FireballEntity(w, liv, v.x, v.y, v.z);
-            }
-        } else {
-            return null;
-        }
-
-        launch.setMotion(launch.getMotion().scale(scale));
-        w.addEntity(launch);
-        return (T) launch;
+        sm.registerFunction("pet.getowner",
+                (sc, in) -> ((TameableEntity) in[0].get(sc)).getOwner());
     }
 }

+ 139 - 1
src/main/java/me/km/snuviscript/commands/LivingCommands.java

@@ -2,6 +2,7 @@ package me.km.snuviscript.commands;
 
 import java.util.UUID;
 import me.hammerle.snuviscript.code.ScriptManager;
+import me.km.scheduler.SnuviScheduler;
 import me.km.utils.Location;
 import me.km.utils.ReflectionUtils;
 import me.km.utils.Utils;
@@ -11,7 +12,16 @@ import net.minecraft.entity.MobEntity;
 import net.minecraft.entity.ai.attributes.Attribute;
 import net.minecraft.entity.ai.attributes.AttributeModifier;
 import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
+import net.minecraft.util.DamageSource;
 import net.minecraftforge.registries.ForgeRegistries;
+import me.km.entities.EntityItemProjectile;
+import static me.km.snuviscript.commands.CommandUtils.getNamedClass;
+import net.minecraft.entity.item.*;
+import net.minecraft.entity.projectile.*;
+import net.minecraft.item.ItemStack;
+import net.minecraft.util.math.vector.Vector3d;
+import net.minecraft.world.World;
+import net.minecraft.inventory.EquipmentSlotType;
 
 public class LivingCommands {
     private static String getName(Attribute attribute) {
@@ -25,7 +35,7 @@ public class LivingCommands {
         return name;
     }
 
-    public static void registerFunctions(ScriptManager sm) {
+    public static void registerFunctions(ScriptManager sm, SnuviScheduler scheduler) {
         for(Attribute attribute : ForgeRegistries.ATTRIBUTES.getValues()) {
             String name = getName(attribute);
             sm.registerConsumer("living.set" + name, (sc, in) -> {
@@ -78,5 +88,133 @@ public class LivingCommands {
             }
             return Utils.getLiving((Entity) o, in[1].getDouble(sc));
         });
+        sm.registerFunction("living.gethealth",
+                (sc, in) -> (double) ((LivingEntity) in[0].get(sc)).getHealth());
+        sm.registerConsumer("living.sethealth",
+                (sc, in) -> ((LivingEntity) in[0].get(sc)).setHealth(in[1].getFloat(sc)));
+        sm.registerConsumer("living.damage", (sc, in) -> {
+            LivingEntity liv = (LivingEntity) in[0].get(sc);
+            float damage = in[1].getFloat(sc);
+            DamageSource damageSource =
+                    (in.length >= 3) ? (DamageSource) in[2].get(sc) : DamageSource.GENERIC;
+            scheduler.scheduleTask(() -> liv.attackEntityFrom(damageSource, damage));
+        });
+        sm.registerConsumer("living.heal", (sc, in) -> {
+            LivingEntity liv = (LivingEntity) in[0].get(sc);
+            float heal = in[1].getFloat(sc);
+            scheduler.scheduleTask(() -> liv.heal(heal));
+        });
+        sm.registerFunction("living.shootprojectile",
+                (sc, in) -> launchProjectile((LivingEntity) in[0].get(sc),
+                        getNamedClass(in[1].getString(sc)), in[2].getDouble(sc),
+                        in.length >= 4 ? in[3].get(sc) : null));
+        sm.registerFunction("living.isblocking",
+                (sc, in) -> ((LivingEntity) in[0].get(sc)).isActiveItemStackBlocking());
+        sm.registerConsumer("living.setequip", (sc, in) -> {
+            LivingEntity liv = (LivingEntity) in[0].get(sc);
+            ItemStack stack = ((ItemStack) in[2].get(sc)).copy();
+            switch(in[1].getString(sc)) {
+                case "hand":
+                    liv.setItemStackToSlot(EquipmentSlotType.MAINHAND, stack);
+                    return;
+                case "head":
+                    liv.setItemStackToSlot(EquipmentSlotType.HEAD, stack);
+                    return;
+                case "chest":
+                    liv.setItemStackToSlot(EquipmentSlotType.CHEST, stack);
+                    return;
+                case "legs":
+                    liv.setItemStackToSlot(EquipmentSlotType.LEGS, stack);
+                    return;
+                case "feet":
+                    liv.setItemStackToSlot(EquipmentSlotType.FEET, stack);
+                    return;
+                case "offhand":
+                    liv.setItemStackToSlot(EquipmentSlotType.OFFHAND, stack);
+            }
+        });
+        sm.registerFunction("living.getequip", (sc, in) -> {
+            LivingEntity liv = (LivingEntity) in[0].get(sc);
+            switch(in[1].getString(sc)) {
+                case "hand":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.MAINHAND);
+                case "head":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.HEAD);
+                case "chest":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.CHEST);
+                case "legs":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.LEGS);
+                case "feet":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.FEET);
+                case "offhand":
+                    return liv.getItemStackFromSlot(EquipmentSlotType.OFFHAND);
+            }
+            return ItemStack.EMPTY;
+        });
+    }
+
+    @SuppressWarnings("unchecked")
+    private static <T> T launchProjectile(LivingEntity liv, Class<? extends T> projectile,
+            double scale, Object data) {
+        World w = liv.world;
+        Entity launch = null;
+
+        if(EntityItemProjectile.class == projectile) {
+            if(data == null) {
+                throw new NullPointerException("Data musn't be null for EntityItemProjectile");
+            }
+            ItemStack stack = (ItemStack) data;
+            if(stack.isEmpty()) {
+                throw new IllegalArgumentException("Empty ItemStack not allowed here");
+            }
+            launch = new EntityItemProjectile(liv, stack.copy());
+            ((EntityItemProjectile) launch).setHeadingFromThrower(liv, liv.rotationPitch,
+                    liv.rotationYaw, 0.0f, 1.5f, 1.0f);
+        } else if(SnowballEntity.class == projectile) {
+            launch = new SnowballEntity(w, liv);
+            ((SnowballEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
+        } else if(EggEntity.class == projectile) {
+            launch = new EggEntity(w, liv);
+            ((EggEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
+        } else if(EnderPearlEntity.class == projectile) {
+            launch = new EnderPearlEntity(w, liv);
+            ((EnderPearlEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0f, 1.5f, 1.0f);
+        } else if(PotionEntity.class == projectile) {
+            launch = new PotionEntity(w, liv);
+            ((PotionEntity) launch).setItem((ItemStack) data);
+            ((PotionEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f, 0.5f, 1.0f);
+        } else if(ExperienceBottleEntity.class == projectile) {
+            launch = new ExperienceBottleEntity(w, liv);
+            ((ExperienceBottleEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, -20.0f,
+                    0.7f, 1.0f);
+        } else if(AbstractArrowEntity.class.isAssignableFrom(projectile)) {
+            if(SpectralArrowEntity.class == projectile) {
+                launch = new SpectralArrowEntity(w, liv);
+            } else {
+                launch = new ArrowEntity(w, liv);
+                if(data != null) {
+                    ((ArrowEntity) launch).setPotionEffect((ItemStack) data);
+                }
+            }
+            ((AbstractArrowEntity) launch).shoot(liv.rotationPitch, liv.rotationYaw, 0.0F, 3.0F,
+                    1.0F);
+        } else if(DamagingProjectileEntity.class.isAssignableFrom(projectile)) {
+            Vector3d v = liv.getLookVec().scale(10);
+            if(SmallFireballEntity.class == projectile) {
+                launch = new SmallFireballEntity(w, liv, v.x, v.y, v.z);
+            } else if(WitherSkullEntity.class == projectile) {
+                launch = new WitherSkullEntity(w, liv, v.x, v.y, v.z);
+            } else if(DragonFireballEntity.class == projectile) {
+                launch = new DragonFireballEntity(w, liv, v.x, v.y, v.z);
+            } else {
+                launch = new FireballEntity(w, liv, v.x, v.y, v.z);
+            }
+        } else {
+            return null;
+        }
+
+        launch.setMotion(launch.getMotion().scale(scale));
+        w.addEntity(launch);
+        return (T) launch;
     }
 }

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

@@ -291,21 +291,8 @@ public class PlayerCommands {
         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)));
-        sm.registerConsumer("player.setinvslot", (sc, in) -> {
-            ((PlayerEntity) in[0].get(sc)).inventory.mainInventory.set(in[1].getInt(sc),
-                    ((ItemStack) in[2].get(sc)).copy());
-        });
         sm.registerFunction("player.getenderinv",
                 (sc, in) -> ((PlayerEntity) in[0].get(sc)).getInventoryEnderChest());
-        sm.registerFunction("player.getenderslot", (sc, in) -> ((PlayerEntity) in[0].get(sc))
-                .getInventoryEnderChest().getStackInSlot(in[1].getInt(sc)));
-        sm.registerConsumer("player.setenderslot", (sc, in) -> {
-            ((PlayerEntity) in[0].get(sc)).getInventoryEnderChest()
-                    .setInventorySlotContents(in[1].getInt(sc), ((ItemStack) in[2].get(sc)).copy());
-        });
         sm.registerConsumer("player.setdisplayname", (sc, in) -> {
             ((ModEntityPlayerMP) in[0].get(sc)).setTabListDisplayName(in[1].getString(sc),
                     scheduler);