Search in sources :

Example 11 with Location

use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.

the class MultithreadedOfflineWorldConverter method stetFourTidbits.

protected void stetFourTidbits(MinecraftWorld mcWorld, WorldImplementation csWorld) {
    verbose("Entering step four: tidbits");
    int spawnX = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnX")).getData();
    int spawnY = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnY")).getData();
    int spawnZ = ((NBTInt) mcWorld.getLevelDotDat().getRoot().getTag("Data.SpawnZ")).getData();
    csWorld.setDefaultSpawnLocation(new Location(csWorld, spawnX, spawnY, spawnZ));
    csWorld.saveEverything().traverse();
    csWorld.destroy();
}
Also used : NBTInt(io.xol.enklume.nbt.NBTInt) Location(io.xol.chunkstories.api.Location)

Example 12 with Location

use of io.xol.chunkstories.api.Location 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 Location

use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.

the class SpawnCommand 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 (command.getName().equals("spawn")) {
        if (!emitter.hasPermission("world.spawn")) {
            emitter.sendMessage("You don't have the permission.");
            return true;
        }
        Location loc = player.getWorld().getDefaultSpawnLocation();
        player.setLocation(loc);
        emitter.sendMessage("#00FFD0Teleported to spawn");
        return true;
    } else if (command.getName().equals("setspawn")) {
        if (!emitter.hasPermission("world.spawn.set")) {
            emitter.sendMessage("You don't have the permission.");
            return true;
        }
        Location loc = player.getLocation();
        player.getWorld().setDefaultSpawnLocation(loc);
        emitter.sendMessage("#00FFD0Set default spawn to : " + loc);
        return true;
    }
    return false;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Location(io.xol.chunkstories.api.Location)

Example 14 with Location

use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.

the class TpCommand method handleCommand.

@Override
public boolean handleCommand(CommandEmitter emitter, Command command, String[] arguments) {
    if (!emitter.hasPermission("server.tp")) {
        emitter.sendMessage("You don't have the permission.");
        return true;
    }
    if (!(emitter instanceof Player)) {
        emitter.sendMessage("You need to be a player to use this command.");
        return true;
    }
    Player who = (Player) emitter;
    Location to = null;
    if (arguments.length == 1) {
        Player otherPlayer = server.getPlayerByName(arguments[0]);
        if (otherPlayer != null)
            to = otherPlayer.getLocation();
        else
            emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
    } else if (arguments.length == 2) {
        who = server.getPlayerByName(arguments[0]);
        if (who == null)
            emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
        Player otherPlayer = server.getPlayerByName(arguments[1]);
        if (otherPlayer != null)
            to = otherPlayer.getLocation();
        else
            emitter.sendMessage("#FF8966Player not found : " + arguments[1]);
    } else if (arguments.length == 3) {
        int x = Integer.parseInt(arguments[0]);
        int y = Integer.parseInt(arguments[1]);
        int z = Integer.parseInt(arguments[2]);
        to = new Location(who.getLocation().getWorld(), x, y, z);
    } else if (arguments.length == 4) {
        who = server.getPlayerByName(arguments[0]);
        if (who == null)
            emitter.sendMessage("#FF8966Player not found : " + arguments[0]);
        int x = Integer.parseInt(arguments[1]);
        int y = Integer.parseInt(arguments[2]);
        int z = Integer.parseInt(arguments[3]);
        to = new Location(who.getLocation().getWorld(), x, y, z);
    }
    if (who != null && to != null) {
        emitter.sendMessage("#FF8966Teleported to : " + to);
        who.setLocation(to);
        return true;
    }
    emitter.sendMessage("#FF8966Usage: /tp [who] (<x> <y> <z>)|(to)");
    return true;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Location(io.xol.chunkstories.api.Location)

Example 15 with Location

use of io.xol.chunkstories.api.Location in project chunkstories by Hugobros3.

the class EntitySerializer method readEntityFromStream.

public static Entity readEntityFromStream(DataInputStream dis, OfflineSerializedData source, World world) {
    try {
        int entityDataLength = dis.readInt();
        if (entityDataLength == -1)
            return null;
        DataInputStream in = LengthAwareBufferedIOHelper.getLengthAwareInput(entityDataLength, dis);
        long entityUUID = in.readLong();
        // Obsolete ?
        // When we reach id -1 in a stream of entities, it means we reached the end.
        // if(entityUUID == -1)
        // return null;
        short entityTypeID = in.readShort();
        /*System.out.println("world"+world);
			System.out.println("world.getGameContext()"+world.getGameContext());
			System.out.println("world.getGameContext().getContent().entities()"+world.getGameContext().getContent().entities());
			System.out.println("world.getGameContext().getContent().entities().getEntityTypeById(entityTypeID)"+world.getGameContext().getContent().entities().getEntityTypeById(entityTypeID));
			*/
        Entity entity = world.getContentTranslator().getEntityForId(entityTypeID).create(new Location(world, 0d, 0d, 0d));
        entity.setUUID(entityUUID);
        int componentId = in.readInt();
        // Loop throught all components
        while (true) {
            if (// End of components to read
            componentId == 0)
                break;
            else if (componentId == -1) {
                // Read UTF-8 component name
                String componentName = in.readUTF();
                try {
                    entity.getComponents().tryPullComponentInStream(componentName, source, in);
                } catch (UnknownComponentException e) {
                    logger().warn("Failure reading component " + componentName + " from " + source);
                    logger().warn(e.getMessage());
                }
            } else {
                // Read int32 component id
                try {
                    entity.getComponents().tryPullComponentInStream(componentId, source, in);
                } catch (UnknownComponentException e) {
                    logger().warn(e.getMessage());
                }
            }
            componentId = in.readInt();
        }
        return entity;
    } catch (NullPointerException | IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Entity(io.xol.chunkstories.api.entity.Entity) UnknownComponentException(io.xol.chunkstories.api.exceptions.UnknownComponentException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) Location(io.xol.chunkstories.api.Location)

Aggregations

Location (io.xol.chunkstories.api.Location)35 Entity (io.xol.chunkstories.api.entity.Entity)17 Player (io.xol.chunkstories.api.player.Player)12 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)12 Vector3d (org.joml.Vector3d)12 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)9 EntityLiving (io.xol.chunkstories.api.entity.EntityLiving)6 Vector3dc (org.joml.Vector3dc)6 CollisionBox (io.xol.chunkstories.api.physics.CollisionBox)5 World (io.xol.chunkstories.api.world.World)5 CellData (io.xol.chunkstories.api.world.cell.CellData)5 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)4 WorldClient (io.xol.chunkstories.api.world.WorldClient)4 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)3 WorldException (io.xol.chunkstories.api.exceptions.world.WorldException)3 Texture2D (io.xol.chunkstories.api.rendering.textures.Texture2D)3 FutureCell (io.xol.chunkstories.api.world.cell.FutureCell)3 EntityPlayer (io.xol.chunkstories.core.entity.EntityPlayer)3 Matrix4f (org.joml.Matrix4f)3 Vector2d (org.joml.Vector2d)3