瀏覽代碼

new snuvi commands

Kajetan Johannes Hammerle 2 年之前
父節點
當前提交
7d74d45604

+ 33 - 0
src/main/java/me/km/snuviscript/commands/BlockCommands.java

@@ -8,9 +8,13 @@ import me.km.utils.Location;
 import me.km.utils.Mapper;
 import me.km.utils.ReflectionUtils;
 import net.minecraft.block.*;
+import net.minecraft.block.material.Material;
 import net.minecraft.command.arguments.BlockStateParser;
+import net.minecraft.entity.Entity;
 import net.minecraft.entity.EntityType;
+import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.entity.player.ServerPlayerEntity;
+import net.minecraft.fluid.Fluids;
 import net.minecraft.inventory.IInventory;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundNBT;
@@ -136,6 +140,11 @@ public class BlockCommands {
                 tileEnt1.markDirty();
             }
         });
+        sm.registerConsumer("block.break", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            Entity ent = (Entity) in[1].get(sc);
+            l.getWorld().destroyBlock(l.getBlockPos(), true, ent);
+        });
         sm.registerConsumer("block.set", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             BlockStateParser parser =
@@ -185,6 +194,30 @@ public class BlockCommands {
             }
             return ReflectionUtils.getSignText((SignTileEntity) te, in[1].getInt(sc)).getString();
         });
+        sm.registerConsumer("block.settrapdoorstatus", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            BlockPos pos = l.getBlockPos();
+            BlockState state = l.getWorld().getBlockState(pos);
+            World w = l.getWorld();
+            state = state.with(TrapDoorBlock.OPEN, in[1].getBoolean(sc));
+            w.setBlockState(pos, state, 2);
+            if(state.get(TrapDoorBlock.WATERLOGGED)) {
+                w.getPendingFluidTicks().scheduleTick(pos, Fluids.WATER,
+                        Fluids.WATER.getTickRate(w));
+            }
+            Material m = state.getMaterial();
+            if(state.get(TrapDoorBlock.OPEN)) {
+                int i = m == Material.IRON ? 1037 : 1007;
+                w.playEvent(null, i, pos, 0);
+            } else {
+                int j = m == Material.IRON ? 1036 : 1013;
+                w.playEvent(null, j, pos, 0);
+            }
+        });
+        sm.registerFunction("block.gettrapdoorstatus", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            return l.getBlockState().get(TrapDoorBlock.OPEN);
+        });
         sm.registerConsumer("block.setdoorstatus", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             BlockPos pos = l.getBlockPos();

+ 51 - 23
src/main/java/me/km/snuviscript/commands/LocationCommands.java

@@ -4,21 +4,23 @@ import me.hammerle.snuviscript.code.ScriptManager;
 import me.km.utils.Location;
 import me.km.utils.LocationIterator;
 import me.km.utils.Utils;
+import net.minecraft.entity.Entity;
 import net.minecraft.util.math.BlockPos;
 import net.minecraft.util.math.MathHelper;
 import net.minecraft.world.IWorld;
 import net.minecraft.world.World;
+import net.minecraft.world.Explosion.Mode;
 
 public class LocationCommands {
     @SuppressWarnings("")
     public static void registerFunctions(ScriptManager sm) {
         sm.registerFunction("loc.new", (sc, in) -> {
             if(in.length >= 6) {
-                return new Location((World) in[0].get(sc),
-                        in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc),
-                        in[4].getFloat(sc), in[5].getFloat(sc));
+                return new Location((World) in[0].get(sc), in[1].getDouble(sc), in[2].getDouble(sc),
+                        in[3].getDouble(sc), in[4].getFloat(sc), in[5].getFloat(sc));
             }
-            return new Location((World) in[0].get(sc), in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc), 0, 0);
+            return new Location((World) in[0].get(sc), in[1].getDouble(sc), in[2].getDouble(sc),
+                    in[3].getDouble(sc), 0, 0);
         });
         sm.registerConsumer("loc.setblockpos", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
@@ -28,21 +30,34 @@ public class LocationCommands {
         sm.registerFunction("loc.getx", (sc, in) -> ((Location) in[0].get(sc)).getX());
         sm.registerFunction("loc.gety", (sc, in) -> ((Location) in[0].get(sc)).getY());
         sm.registerFunction("loc.getz", (sc, in) -> ((Location) in[0].get(sc)).getZ());
-        sm.registerConsumer("loc.set", (sc, in) -> ((Location) in[0].get(sc)).set(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
-        sm.registerConsumer("loc.setx", (sc, in) -> ((Location) in[0].get(sc)).setX(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.sety", (sc, in) -> ((Location) in[0].get(sc)).setY(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.setz", (sc, in) -> ((Location) in[0].get(sc)).setZ(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.add", (sc, in) -> ((Location) in[0].get(sc)).add(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
-        sm.registerConsumer("loc.addx", (sc, in) -> ((Location) in[0].get(sc)).addX(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.addy", (sc, in) -> ((Location) in[0].get(sc)).addY(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.addz", (sc, in) -> ((Location) in[0].get(sc)).addZ(in[1].getDouble(sc)));
-        sm.registerConsumer("loc.setyaw", (sc, in) -> ((Location) in[0].get(sc)).setYaw(in[1].getFloat(sc)));
+        sm.registerConsumer("loc.set", (sc, in) -> ((Location) in[0].get(sc))
+                .set(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
+        sm.registerConsumer("loc.setx",
+                (sc, in) -> ((Location) in[0].get(sc)).setX(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.sety",
+                (sc, in) -> ((Location) in[0].get(sc)).setY(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.setz",
+                (sc, in) -> ((Location) in[0].get(sc)).setZ(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.add", (sc, in) -> ((Location) in[0].get(sc))
+                .add(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
+        sm.registerConsumer("loc.addx",
+                (sc, in) -> ((Location) in[0].get(sc)).addX(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.addy",
+                (sc, in) -> ((Location) in[0].get(sc)).addY(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.addz",
+                (sc, in) -> ((Location) in[0].get(sc)).addZ(in[1].getDouble(sc)));
+        sm.registerConsumer("loc.setyaw",
+                (sc, in) -> ((Location) in[0].get(sc)).setYaw(in[1].getFloat(sc)));
         sm.registerFunction("loc.getyaw", (sc, in) -> (double) ((Location) in[0].get(sc)).getYaw());
-        sm.registerConsumer("loc.setpitch", (sc, in) -> ((Location) in[0].get(sc)).setPitch(in[1].getFloat(sc)));
-        sm.registerFunction("loc.getpitch", (sc, in) -> (double) ((Location) in[0].get(sc)).getPitch());
+        sm.registerConsumer("loc.setpitch",
+                (sc, in) -> ((Location) in[0].get(sc)).setPitch(in[1].getFloat(sc)));
+        sm.registerFunction("loc.getpitch",
+                (sc, in) -> (double) ((Location) in[0].get(sc)).getPitch());
         sm.registerFunction("loc.getworld", (sc, in) -> ((Location) in[0].get(sc)).getWorld());
-        sm.registerFunction("loc.distance", (sc, in) -> ((Location) in[0].get(sc)).getPos().distanceTo(((Location) in[1].get(sc)).getPos()));
-        sm.registerFunction("loc.mod", (sc, in) -> ((Location) in[0].get(sc)).copyAdd(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
+        sm.registerFunction("loc.distance", (sc, in) -> ((Location) in[0].get(sc)).getPos()
+                .distanceTo(((Location) in[1].get(sc)).getPos()));
+        sm.registerFunction("loc.mod", (sc, in) -> ((Location) in[0].get(sc))
+                .copyAdd(in[1].getDouble(sc), in[2].getDouble(sc), in[3].getDouble(sc)));
         sm.registerFunction("loc.getcoord", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             switch(in[1].getString(sc)) {
@@ -68,9 +83,12 @@ public class LocationCommands {
             Location l1 = (Location) in[0].get(sc);
             Location l2 = (Location) in[1].get(sc);
             Location l3 = (Location) in[2].get(sc);
-            return l1.getX() >= Math.min(l2.getX(), l3.getX()) && l1.getX() <= Math.max(l2.getX(), l3.getX())
-                    && l1.getY() >= Math.min(l2.getY(), l3.getY()) && l1.getY() <= Math.max(l2.getY(), l3.getY())
-                    && l1.getZ() >= Math.min(l2.getZ(), l3.getZ()) && l1.getZ() <= Math.max(l2.getZ(), l3.getZ());
+            return l1.getX() >= Math.min(l2.getX(), l3.getX())
+                    && l1.getX() <= Math.max(l2.getX(), l3.getX())
+                    && l1.getY() >= Math.min(l2.getY(), l3.getY())
+                    && l1.getY() <= Math.max(l2.getY(), l3.getY())
+                    && l1.getZ() >= Math.min(l2.getZ(), l3.getZ())
+                    && l1.getZ() <= Math.max(l2.getZ(), l3.getZ());
         });
         sm.registerConsumer("loc.sort", (sc, in) -> {
             Location l1 = (Location) in[0].get(sc);
@@ -92,9 +110,8 @@ public class LocationCommands {
             }
         });
         sm.registerFunction("loc.iterator", (sc, in) -> {
-            return new LocationIterator((World) in[0].get(sc),
-                    in[1].getInt(sc), in[2].getInt(sc), in[3].getInt(sc),
-                    in[4].getInt(sc), in[5].getInt(sc), in[6].getInt(sc));
+            return new LocationIterator((World) in[0].get(sc), in[1].getInt(sc), in[2].getInt(sc),
+                    in[3].getInt(sc), in[4].getInt(sc), in[5].getInt(sc), in[6].getInt(sc));
         });
         sm.registerFunction("loc.trace", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
@@ -125,5 +142,16 @@ public class LocationCommands {
             }
             return false;
         });
+        sm.registerFunction("loc.explode", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            Entity ent = (Entity) in[1].get(sc);
+            float radius = in[2].getFloat(sc);
+            boolean fire = in[3].getBoolean(sc);
+            boolean destroys = in[4].getBoolean(sc);
+            l.getWorld().createExplosion(ent, l.getX(), l.getY(), l.getZ(), radius, fire,
+                    destroys ? Mode.BREAK : Mode.NONE);
+            return false;
+        });
+
     }
 }

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

@@ -67,7 +67,7 @@ public class PlayerCommands {
                 try {
                     p.connection.processClientStatus(
                             new CClientStatusPacket(CClientStatusPacket.State.PERFORM_RESPAWN));
-                } catch (ThreadQuickExitException ex) {
+                } catch(ThreadQuickExitException ex) {
                     // Minecraft needs this for canceling and queueing into main thread
                 }
             });
@@ -84,7 +84,7 @@ public class PlayerCommands {
             try {
                 ((ServerPlayerEntity) in[0].get(sc)).connection
                         .processChatMessage(new CChatMessagePacket(SnuviUtils.connect(sc, in, 1)));
-            } catch (ThreadQuickExitException ex) {
+            } catch(ThreadQuickExitException ex) {
                 // Minecraft needs this for canceling and queueing into main thread
             }
         });
@@ -159,7 +159,7 @@ public class PlayerCommands {
                 (sc, in) -> ((PlayerEntity) in[0].get(sc)).abilities.isFlying);
         sm.registerConsumer("player.setgamemode", (sc, in) -> {
             PlayerEntity p = (PlayerEntity) in[0].get(sc);
-            switch (in[1].get(sc).toString()) {
+            switch(in[1].get(sc).toString()) {
                 case "survival":
                 case "s":
                 case "0":