Search in sources :

Example 11 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class PhysicsWireframeDebugger method render.

public void render(RenderingInterface renderer) {
    Vector3dc cameraPosition = renderer.getCamera().getCameraPosition();
    // int id, data;
    int drawDebugDist = 6;
    // Iterate over nearby voxels
    for (int i = ((int) (double) cameraPosition.x()) - drawDebugDist; i <= ((int) (double) cameraPosition.x()) + drawDebugDist; i++) for (int j = ((int) (double) cameraPosition.y()) - drawDebugDist; j <= ((int) (double) cameraPosition.y()) + drawDebugDist; j++) for (int k = ((int) (double) cameraPosition.z()) - drawDebugDist; k <= ((int) (double) cameraPosition.z()) + drawDebugDist; k++) {
        // data = world.peekSimple(i, j, k);
        // id = VoxelFormat.id(data);
        CellData cell = world.peekSafely(i, j, k);
        // System.out.println(i+":"+j+":"+k);
        // System.out.println(cell.getX() + ":"+cell.getY()+":"+cell.getZ());
        CollisionBox[] tboxes = cell.getTranslatedCollisionBoxes();
        // System.out.println(tboxes.length);
        if (tboxes != null) {
            // Draw all their collision boxes
            for (CollisionBox box : tboxes) {
                if (cell.getVoxel().getDefinition().isSolid())
                    // Red if solid
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 0, 0, 1.0f));
                else
                    // Yellow otherwise
                    FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(1, 1, 0, 0.25f));
            }
        }
    }
    // Iterate over each entity
    Iterator<Entity> ie = world.getAllLoadedEntities();
    while (ie.hasNext()) {
        Entity e = ie.next();
        // Entities with hitboxes see all of those being drawn
        if (e instanceof EntityLiving) {
            EntityLiving eli = (EntityLiving) e;
            for (HitBox hitbox : eli.getHitBoxes()) {
                hitbox.draw(renderer);
            }
        }
        // Get the entity bounding box
        if (e.getTranslatedBoundingBox().lineIntersection(cameraPosition, new Vector3d(renderer.getCamera().getViewDirection())) != null)
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 0, 0.5f, 1.0f));
        else
            FakeImmediateModeDebugRenderer.renderCollisionBox(e.getTranslatedBoundingBox(), new Vector4f(0, 1f, 1f, 1.0f));
        // And the collision box
        for (CollisionBox box : e.getCollisionBoxes()) {
            box.translate(e.getLocation());
            FakeImmediateModeDebugRenderer.renderCollisionBox(box, new Vector4f(0, 1, 0.5f, 1.0f));
        }
    }
}
Also used : Vector3dc(org.joml.Vector3dc) Entity(io.xol.chunkstories.api.entity.Entity) HitBox(io.xol.chunkstories.api.entity.EntityLiving.HitBox) Vector4f(org.joml.Vector4f) EntityLiving(io.xol.chunkstories.api.entity.EntityLiving) Vector3d(org.joml.Vector3d) CellData(io.xol.chunkstories.api.world.cell.CellData) CollisionBox(io.xol.chunkstories.api.physics.CollisionBox)

Example 12 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class SpawnEntityCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Player player = (Player) emitter;
    if (!emitter.hasPermission("world.spawnEntity")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (arguments.length == 0) {
        emitter.sendMessage("Syntax: /spawnEntity <entityId> [x y z]");
        return false;
    }
    Location loc = player.getLocation();
    if (arguments.length >= 4) {
        loc = new Location(player.getWorld(), Double.parseDouble(arguments[1]), Double.parseDouble(arguments[2]), Double.parseDouble(arguments[3]));
    }
    EntityDefinition entityType;
    String entityName = arguments[0];
    entityType = server.getContent().entities().getEntityDefinition(entityName);
    if (entityType == null) {
        emitter.sendMessage("Entity type : " + arguments[0] + " not found in loaded content.");
        return true;
    }
    Entity entity = entityType.create(loc);
    entity.setLocation(loc);
    loc.getWorld().addEntity(entity);
    emitter.sendMessage("#00FFD0" + "Spawned " + entity.getClass().getSimpleName() + " at " + (arguments.length >= 4 ? loc.toString() : player.getName()));
    return true;
}
Also used : EntityDefinition(io.xol.chunkstories.api.entity.EntityDefinition) Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) Location(io.xol.chunkstories.api.Location)

Example 13 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class FoodCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Player player = (Player) emitter;
    if (!emitter.hasPermission("self.setfood")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (arguments.length < 1 || !isNumeric(arguments[0])) {
        emitter.sendMessage("Syntax: /food <hp>");
        return true;
    }
    float food = Float.parseFloat(arguments[0]);
    Entity controlledEntity = player.getControlledEntity();
    if (controlledEntity != null && controlledEntity instanceof EntityFeedable) {
        ((EntityFeedable) controlledEntity).setFoodLevel(food);
        player.sendMessage("Food set to: " + food);
        return true;
    }
    emitter.sendMessage("This action doesn't apply to your current entity.");
    return true;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Player(io.xol.chunkstories.api.player.Player) EntityFeedable(io.xol.chunkstories.api.entity.interfaces.EntityFeedable)

Example 14 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class EntitiesDebugCommands method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (command.getName().equals("entities") && emitter.hasPermission("server.debug")) {
        Iterator<Entity> entities = server.getWorld().getAllLoadedEntities();
        while (entities.hasNext()) {
            Entity entity = entities.next();
            emitter.sendMessage("#FFDD00" + entity);
        }
        return true;
    }
    return false;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity)

Example 15 with Entity

use of io.xol.chunkstories.api.entity.Entity in project chunkstories by Hugobros3.

the class LocalClientLoadingAgent method updateUsedWorldBits.

public void updateUsedWorldBits() {
    Entity controlledEntity = player.getControlledEntity();
    if (controlledEntity == null)
        return;
    try {
        lock.lock();
        // Subscribe to nearby wanted chunks
        int cameraChunkX = Math2.floor((controlledEntity.getLocation().x()) / 32);
        int cameraChunkY = Math2.floor((controlledEntity.getLocation().y()) / 32);
        int cameraChunkZ = Math2.floor((controlledEntity.getLocation().z()) / 32);
        int chunksViewDistance = (int) (world.getClient().getConfiguration().getIntOption("client.rendering.viewDistance") / 32);
        for (int chunkX = (cameraChunkX - chunksViewDistance - 1); chunkX <= cameraChunkX + chunksViewDistance + 1; chunkX++) {
            for (int chunkZ = (cameraChunkZ - chunksViewDistance - 1); chunkZ <= cameraChunkZ + chunksViewDistance + 1; chunkZ++) for (int chunkY = cameraChunkY - 3; chunkY <= cameraChunkY + 3; chunkY++) {
                WorldInfo worldInfo = world.getWorldInfo();
                WorldInfo.WorldSize size = worldInfo.getSize();
                int filteredChunkX = chunkX & (size.maskForChunksCoordinates);
                int filteredChunkY = Math2.clampi(chunkY, 0, 31);
                int filteredChunkZ = chunkZ & (size.maskForChunksCoordinates);
                int summed = ((filteredChunkX << size.bitlengthOfVerticalChunksCoordinates) | filteredChunkY) << size.bitlengthOfHorizontalChunksCoordinates | filteredChunkZ;
                if (fastChunksMask.contains(summed))
                    continue;
                ChunkHolder holder = world.aquireChunkHolder(player, chunkX, chunkY, chunkZ);
                assert holder != null;
                if (holder == null)
                    continue;
                usedChunks.add(holder);
                fastChunksMask.add(summed);
                if (world instanceof WorldClientRemote) {
                    WorldClientRemote remote = (WorldClientRemote) world;
                    remote.getConnection().pushPacket(PacketWorldUser.registerChunkPacket(world, filteredChunkX, filteredChunkY, filteredChunkZ));
                }
            }
        }
        // Unsubscribe for far ones
        Iterator<ChunkHolder> i = usedChunks.iterator();
        while (i.hasNext()) {
            ChunkHolder holder = i.next();
            if ((LoopingMathHelper.moduloDistance(holder.getChunkCoordinateX(), cameraChunkX, world.getSizeInChunks()) > chunksViewDistance + 1) || (LoopingMathHelper.moduloDistance(holder.getChunkCoordinateZ(), cameraChunkZ, world.getSizeInChunks()) > chunksViewDistance + 1) || (Math.abs(holder.getChunkCoordinateY() - cameraChunkY) > 4)) {
                WorldInfo worldInfo = world.getWorldInfo();
                WorldInfo.WorldSize size = worldInfo.getSize();
                int filteredChunkX = holder.getChunkCoordinateX() & (size.maskForChunksCoordinates);
                int filteredChunkY = Math2.clampi(holder.getChunkCoordinateY(), 0, 31);
                int filteredChunkZ = holder.getChunkCoordinateZ() & (size.maskForChunksCoordinates);
                int summed = ((filteredChunkX << size.bitlengthOfVerticalChunksCoordinates) | filteredChunkY) << size.bitlengthOfHorizontalChunksCoordinates | filteredChunkZ;
                fastChunksMask.remove(summed);
                i.remove();
                holder.unregisterUser(player);
                if (world instanceof WorldClientRemote) {
                    WorldClientRemote remote = (WorldClientRemote) world;
                    remote.getConnection().pushPacket(PacketWorldUser.unregisterChunkPacket(world, filteredChunkX, filteredChunkY, filteredChunkZ));
                }
            }
        }
        // We load the region summaries we fancy
        int summaryDistance = 32;
        for (int chunkX = (cameraChunkX - summaryDistance); chunkX < cameraChunkX + summaryDistance; chunkX++) for (int chunkZ = (cameraChunkZ - summaryDistance); chunkZ < cameraChunkZ + summaryDistance; chunkZ++) {
            if (chunkX % 8 == 0 && chunkZ % 8 == 0) {
                int regionX = chunkX / 8;
                int regionZ = chunkZ / 8;
                // TODO bad to aquire each time!!!
                Heightmap regionSummary = world.getRegionsSummariesHolder().aquireHeightmap(player, regionX, regionZ);
                if (regionSummary != null) {
                    if (usedRegionSummaries.add(regionSummary)) {
                        if (world instanceof WorldClientRemote) {
                            WorldClientRemote remote = (WorldClientRemote) world;
                            remote.getConnection().pushPacket(PacketWorldUser.registerSummary(world, regionX, regionZ));
                        }
                    }
                }
            }
        }
        int cameraRegionX = cameraChunkX / 8;
        int cameraRegionZ = cameraChunkZ / 8;
        int distInRegions = summaryDistance / 8;
        int sizeInRegions = world.getSizeInChunks() / 8;
        // And we unload the ones we no longer need
        Iterator<Heightmap> iterator = usedRegionSummaries.iterator();
        while (iterator.hasNext()) {
            Heightmap entry = iterator.next();
            int regionX = entry.getRegionX();
            int regionZ = entry.getRegionZ();
            int dx = LoopingMathHelper.moduloDistance(cameraRegionX, regionX, sizeInRegions);
            int dz = LoopingMathHelper.moduloDistance(cameraRegionZ, regionZ, sizeInRegions);
            if (dx > distInRegions || dz > distInRegions) {
                entry.unregisterUser(player);
                iterator.remove();
                if (world instanceof WorldClientRemote) {
                    WorldClientRemote remote = (WorldClientRemote) world;
                    remote.getConnection().pushPacket(PacketWorldUser.unregisterSummary(world, regionX, regionZ));
                }
            }
        }
    } finally {
        lock.unlock();
    }
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) Heightmap(io.xol.chunkstories.api.world.heightmap.Heightmap) ChunkHolder(io.xol.chunkstories.api.world.chunk.ChunkHolder) WorldClientRemote(io.xol.chunkstories.world.WorldClientRemote) WorldInfo(io.xol.chunkstories.api.world.WorldInfo)

Aggregations

Entity (io.xol.chunkstories.api.entity.Entity)44 Location (io.xol.chunkstories.api.Location)17 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)12 Vector3d (org.joml.Vector3d)11 Player (io.xol.chunkstories.api.player.Player)9 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)7 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)5 Voxel (io.xol.chunkstories.api.voxel.Voxel)4 World (io.xol.chunkstories.api.world.World)4 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)4 IOException (java.io.IOException)4 EntityBase (io.xol.chunkstories.api.entity.EntityBase)3 HitBox (io.xol.chunkstories.api.entity.EntityLiving.HitBox)3 EntityComponentInventory (io.xol.chunkstories.api.entity.components.EntityComponentInventory)3 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)3 ItemVoxel (io.xol.chunkstories.api.item.ItemVoxel)3 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)3 CellData (io.xol.chunkstories.api.world.cell.CellData)3 Vector3dc (org.joml.Vector3dc)3 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2