Przeglądaj źródła

new snuvi commands

Kajetan Johannes Hammerle 4 lat temu
rodzic
commit
17434066f0

+ 6 - 0
src/main/java/me/km/snuviscript/ScriptEvents.java

@@ -646,6 +646,12 @@ public class ScriptEvents {
     public void onEntityJoinWorld(EntityJoinWorldEvent e) {
         Entity ent = e.getEntity();
         if(!scripts.getEntityLimits().isAllowedToSpawn(ent.getType())) {
+            e.getEntity().getPassengers().forEach(rider -> {
+                if(rider == null || rider instanceof PlayerEntity) {
+                    return;
+                }
+                rider.remove();
+            });
             e.setCanceled(true);
             return;
         }

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

@@ -10,6 +10,7 @@ import net.minecraft.block.*;
 import net.minecraft.command.arguments.BlockStateParser;
 import net.minecraft.entity.EntityType;
 import net.minecraft.entity.player.ServerPlayerEntity;
+import net.minecraft.inventory.IInventory;
 import net.minecraft.item.ItemStack;
 import net.minecraft.nbt.CompoundNBT;
 import net.minecraft.network.play.server.SUpdateTileEntityPacket;
@@ -199,5 +200,9 @@ public class BlockCommands {
             MobSpawnerTileEntity spawner = (MobSpawnerTileEntity) l.getWorld().getTileEntity(l.getBlockPos());
             spawner.getSpawnerBaseLogic().setEntityType(EntityType.byKey(in[1].getString(sc)).get());
         });
+        sm.registerFunction("block.getinv", (sc, in) -> {
+            Location l = (Location) in[0].get(sc);
+            return (IInventory) l.getWorld().getTileEntity(l.getBlockPos());
+        });
     }
 }

+ 7 - 1
src/main/java/me/km/snuviscript/commands/EntityCommands.java

@@ -282,7 +282,13 @@ public class EntityCommands {
             }
             return entity;
         });
-        sm.registerFunction("entity.near", (sc, in) -> Utils.getLiving((Entity) in[0].get(sc), in[1].getDouble(sc)));
+        sm.registerFunction("entity.near", (sc, in) -> {
+            Object o = in[0].get(sc);
+            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(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(in[1].getDouble(sc));
         });

+ 2 - 1
src/main/java/me/km/snuviscript/commands/InventoryCommands.java

@@ -15,7 +15,7 @@ public class InventoryCommands {
     public static void registerFunctions(ScriptManager sm) {
         sm.registerFunction("inv.new", (sc, in) -> new ModInventory(in[0].getString(sc)));
         sm.registerFunction("inv.getid", (sc, in) -> (double) ((ModInventory) in[0].get(sc)).getModId());
-        sm.registerFunction("inv.loadblock", (sc, in) -> {
+        sm.registerFunction("inv.loadchest", (sc, in) -> {
             Location l = (Location) in[0].get(sc);
             ChestTileEntity chest = (ChestTileEntity) l.getWorld().getTileEntity(l.getBlockPos());
             int size = chest.getSizeInventory();
@@ -34,6 +34,7 @@ public class InventoryCommands {
             ((IInventory) in[0].get(sc)).setInventorySlotContents(in[1].getInt(sc), (ItemStack) in[2].get(sc));
         });
         sm.registerFunction("inv.getitem", (sc, in) -> ((IInventory) in[0].get(sc)).getStackInSlot(in[1].getInt(sc)));
+        sm.registerFunction("inv.getsize", (sc, in) -> ((IInventory) in[0].get(sc)).getSizeInventory());
         sm.registerConsumer("inv.open", (sc, in) -> {
             CustomContainer.openForPlayer((ServerPlayerEntity) in[1].get(sc), (ModInventory) in[0].get(sc), in[2].getString(sc), sc);
         });

+ 4 - 0
src/main/java/me/km/snuviscript/commands/ItemEntityCommands.java

@@ -15,5 +15,9 @@ public class ItemEntityCommands {
             Location l = (Location) in[0].get(sc);
             return new ItemEntity(l.getWorld().getWorld(), l.getX(), l.getY(), l.getZ(), (ItemStack) in[1].get(sc));
         });
+        sm.registerConsumer("item.entity.spawn", (sc, in) -> {
+            ItemEntity ent = (ItemEntity) in[0].get(sc);
+            ent.world.addEntity(ent);
+        });
     }
 }

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

@@ -2,7 +2,10 @@ package me.km.snuviscript.commands;
 
 import java.util.UUID;
 import me.hammerle.snuviscript.code.ScriptManager;
+import me.km.utils.Location;
 import me.km.utils.ReflectionUtils;
+import me.km.utils.Utils;
+import net.minecraft.entity.Entity;
 import net.minecraft.entity.LivingEntity;
 import net.minecraft.entity.MobEntity;
 import net.minecraft.entity.SharedMonsterAttributes;
@@ -43,5 +46,12 @@ public class LivingCommands {
                 ReflectionUtils.getGoals(mob.targetSelector).clear();
             }
         });
+        sm.registerFunction("living.near", (sc, in) -> {
+            Object o = in[0].get(sc);
+            if(o instanceof Location) {
+                return Utils.getLiving((Location) o, in[1].getDouble(sc));
+            }
+            return Utils.getLiving((Entity) o, in[1].getDouble(sc));
+        });
     }
 }

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

@@ -228,7 +228,6 @@ public class PlayerCommands {
         sm.registerConsumer("player.openenderchest", (sc, in) -> {
             PlayerEntity p1 = (PlayerEntity) in[0].get(sc);
             PlayerEntity p2 = (PlayerEntity) in[1].get(sc);
-
             EnderChestInventory inv = p2.getInventoryEnderChest();
             p1.openContainer(new SimpleNamedContainerProvider((id, pInv, p) -> {
                 return ChestContainer.createGeneric9X3(id, pInv, inv);
@@ -266,10 +265,12 @@ public class PlayerCommands {
             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)));
         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());

+ 11 - 0
src/main/java/me/km/snuviscript/commands/ScriptCommands.java

@@ -10,7 +10,18 @@ import net.minecraft.entity.player.PlayerEntity;
 import net.minecraft.server.MinecraftServer;
 
 public class ScriptCommands {
+    private static void nothing(Script sc) {
+    }
+
     public static void registerFunctions(ScriptManager sm, Scripts scripts, MinecraftServer server) {
+        sm.registerConsumer("script.callevent", (sc, in) -> {
+            String name = in[0].getString(sc);
+            if(in.length >= 2) {
+                sm.callEvent(name, (Script) in[1].get(sc), ScriptCommands::nothing, ScriptCommands::nothing);
+            } else {
+                sm.callEvent(name, ScriptCommands::nothing, ScriptCommands::nothing);
+            }
+        });
         sm.registerFunction("script.playerstolist", (sc, in) -> new ArrayList<>(scripts.getPlayerList(sc.getId())));
         sm.registerFunction("script.getplayeramount", (sc, in) -> (double) scripts.getPlayerList(sc.getId()).size());
         sm.registerFunction("script.start", (sc, in) -> {

+ 26 - 1
src/main/java/me/km/utils/Utils.java

@@ -49,10 +49,26 @@ public class Utils {
         double sqareRadius = radius * radius;
         return w.getWorld().getEntitiesWithinAABB(type, buildBoxAround(x, y, z, radius), ent -> ent.getDistanceSq(x, y, z) <= sqareRadius);
     }
+    
+    public static List<Entity> getEntities(Entity ent, double radius) {
+        double sqareRadius = radius * radius;
+        double x = ent.getPosX();
+        double y = ent.getPosY();
+        double z = ent.getPosZ();
+        return ent.world.getEntitiesInAABBexcluding(ent, buildBoxAround(x, y, z, radius), e -> e.getDistanceSq(x, y, z) <= sqareRadius);
+    }
+    
+    public static List<Entity> getEntities(Location loc, double radius) {
+        double sqareRadius = radius * radius;
+        double x = loc.getX();
+        double y = loc.getY();
+        double z = loc.getZ();
+        return loc.getWorld().getEntitiesInAABBexcluding(null, buildBoxAround(x, y, z, radius), ent -> ent.getDistanceSq(x, y, z) <= sqareRadius);
+    }
 
     public static List<PlayerEntity> getPlayers(IWorld w, double x, double y, double z, double radius) {
         double sqareRadius = radius * radius;
-        return w.getWorld().getEntitiesWithinAABB(PlayerEntity.class, buildBoxAround(x, y, z, radius), p -> p.getDistanceSq(x, y, z) <= sqareRadius);
+        return w.getEntitiesWithinAABB(PlayerEntity.class, buildBoxAround(x, y, z, radius), p -> p.getDistanceSq(x, y, z) <= sqareRadius);
     }
 
     public static List<PlayerEntity> getPlayers(Entity not, double radius) {
@@ -66,6 +82,15 @@ public class Utils {
         return not.world.getEntitiesWithinAABB(LivingEntity.class, buildBoxAround(not.getPosX(), not.getPosY(), not.getPosZ(), radius),
                 p -> p != not && p.getDistanceSq(not) <= sqareRadius);
     }
+    
+    public static List<LivingEntity> getLiving(Location loc, double radius) {
+        double sqareRadius = radius * radius;
+        double x = loc.getX();
+        double y = loc.getY();
+        double z = loc.getZ();
+        return loc.getWorld().getEntitiesWithinAABB(LivingEntity.class, buildBoxAround(x, y, z, radius),
+                p -> p.getDistanceSq(x, y, z) <= sqareRadius);
+    }
 
     public static <T extends Entity> T getEntity(IWorld w, double x, double y, double z, double radius, Class<T> type) {
         return getEntities(w, x, y, z, radius, type).stream()