Search in sources :

Example 1 with EntitySelector

use of com.builtbroken.mc.prefab.entity.selector.EntitySelector in project Engine by VoltzEngine-Project.

the class CommandVERemove method handleEntityPlayerCommand.

@Override
public boolean handleEntityPlayerCommand(EntityPlayer entityPlayer, String[] args) {
    if (args.length > 0) {
        int radius = 100;
        EntitySelector selector = getSelector(args[0]);
        if (selector == null) {
            //TODO return error
            return false;
        }
        //Get radius from player
        if (args.length > 1 && args[1] != null) {
            try {
                radius = Integer.parseInt(args[1]);
                if (radius > 1000) {
                    entityPlayer.addChatMessage(new ChatComponentText("To prevent lag/crashes radius is limited to 1000"));
                    return true;
                } else if (radius < 1) {
                    entityPlayer.addChatMessage(new ChatComponentText("Radius needs to be positive"));
                    return true;
                }
            } catch (NumberFormatException e) {
                entityPlayer.addChatMessage(new ChatComponentText("Radius needs to be an integer"));
                return true;
            }
        }
        if (selector != null) {
            List<Entity> list = selector.getEntities(entityPlayer, radius);
            for (Entity entity : list) {
                entity.setDead();
            }
            entityPlayer.addChatMessage(new ChatComponentText("Removed " + list.size() + " " + args[0] + " entities within " + radius + " block radius"));
        } else {
            entityPlayer.addChatMessage(new ChatComponentText("Error unknown selector"));
        }
        return true;
    }
    return false;
}
Also used : Entity(net.minecraft.entity.Entity) EntitySelector(com.builtbroken.mc.prefab.entity.selector.EntitySelector) ChatComponentText(net.minecraft.util.ChatComponentText)

Example 2 with EntitySelector

use of com.builtbroken.mc.prefab.entity.selector.EntitySelector in project Engine by VoltzEngine-Project.

the class CommandVERemove method handleConsoleCommand.

@Override
public boolean handleConsoleCommand(ICommandSender sender, String[] args) {
    long time = System.nanoTime();
    //TODO add ability to set location and range
    int dim = 0;
    EntitySelector selector = getSelector(args[0]);
    if (selector == null) {
        //TODO return error
        return false;
    }
    if (args != null && args.length > 1) {
        if (args[1].startsWith("dim")) {
            try {
                dim = Integer.parseInt(args[1].replace("dim", ""));
            } catch (NumberFormatException e) {
                sender.addChatMessage(new ChatComponentText("Dim id needs to be an int"));
                return true;
            }
        } else {
            sender.addChatMessage(new ChatComponentText("Right now only /ve butcher dim[#] is supported, ex /ve butcher dim0"));
            return true;
        }
    }
    WorldServer world = DimensionManager.getWorld(dim);
    if (world != null) {
        int entitiesKilled = 0;
        int chunksSearched = 0;
        ChunkProviderServer provider = world.theChunkProviderServer;
        for (Object object : provider.loadedChunks) {
            if (object instanceof Chunk) {
                chunksSearched++;
                for (Object l : ((Chunk) object).entityLists) {
                    if (l instanceof Collection) {
                        for (Object e : (Collection) l) {
                            if (e instanceof Entity && ((Entity) e).isEntityAlive() && selector.isEntityApplicable((Entity) e)) {
                                ((Entity) e).setDead();
                                entitiesKilled++;
                            }
                        }
                    }
                }
            }
        }
        time = System.nanoTime() - time;
        sender.addChatMessage(new ChatComponentText("Removed " + entitiesKilled + " entities over " + chunksSearched + " chunks in " + StringHelpers.formatNanoTime(time)));
    } else {
        sender.addChatMessage(new ChatComponentText("World doesn't exist, this means it unloaded or the wrong id was provided."));
    }
    return true;
}
Also used : Entity(net.minecraft.entity.Entity) EntitySelector(com.builtbroken.mc.prefab.entity.selector.EntitySelector) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) Collection(java.util.Collection) WorldServer(net.minecraft.world.WorldServer) Chunk(net.minecraft.world.chunk.Chunk) ChatComponentText(net.minecraft.util.ChatComponentText)

Aggregations

EntitySelector (com.builtbroken.mc.prefab.entity.selector.EntitySelector)2 Entity (net.minecraft.entity.Entity)2 ChatComponentText (net.minecraft.util.ChatComponentText)2 Collection (java.util.Collection)1 WorldServer (net.minecraft.world.WorldServer)1 Chunk (net.minecraft.world.chunk.Chunk)1 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)1