Search in sources :

Example 6 with Controller

use of io.xol.chunkstories.api.entity.Controller in project chunkstories-core by Hugobros3.

the class VoxelChest method handleInteraction.

@Override
public boolean handleInteraction(Entity entity, ChunkCell voxelContext, Input input) {
    if (input.getName().equals("mouse.right") && voxelContext.getWorld() instanceof WorldMaster) {
        // Only actual players can open that kind of stuff
        if (entity instanceof EntityControllable) {
            EntityControllable e = (EntityControllable) entity;
            Controller c = e.getController();
            if (c instanceof Player && ((Player) c).getLocation().distance(voxelContext.getLocation()) <= 5) {
                Player p = (Player) c;
                p.openInventory(getInventory(voxelContext));
            }
        }
    }
    return false;
}
Also used : Player(io.xol.chunkstories.api.player.Player) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 7 with Controller

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

the class EntityComponent method pushComponentEveryoneButController.

/**
 * Push the component to everyone but the controller, if such one exists
 */
public void pushComponentEveryoneButController() {
    // System.out.println("pushing2all");
    Iterator<Subscriber> iterator = entity.getAllSubscribers();
    Controller controller = null;
    if (entity instanceof EntityControllable) {
        controller = ((EntityControllable) entity).getControllerComponent().getController();
    }
    while (iterator.hasNext()) {
        Subscriber subscriber = iterator.next();
        // Don't push the update to the controller.
        if (controller != null && subscriber.equals(controller))
            continue;
        this.pushComponent(subscriber);
    }
}
Also used : Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 8 with Controller

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

the class EntityComponentController method setController.

public void setController(Controller controller) {
    // Checks we are entitled to do this
    if (!(entity.getWorld() instanceof WorldMaster))
        throw new UnauthorizedClientActionException("setController()");
    Controller formerController = this.controller;
    this.controller = controller;
    // Tell the new controller he his
    if (controller != null)
        pushComponent(controller);
    // Tell the former one he's no longer
    if (formerController != null && (controller == null || !controller.equals(formerController)))
        pushComponent(formerController);
}
Also used : UnauthorizedClientActionException(io.xol.chunkstories.api.exceptions.UnauthorizedClientActionException) Controller(io.xol.chunkstories.api.entity.Controller) WorldMaster(io.xol.chunkstories.api.world.WorldMaster)

Example 9 with Controller

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

the class EntityComponentVelocity method addVelocity.

public void addVelocity(Vector3dc delta) {
    this.velocity.add(delta);
    this.pushComponentEveryoneButController();
    // Notify the controller otherwise:
    if (entity instanceof EntityControllable) {
        Controller controller = ((EntityControllable) entity).getControllerComponent().getController();
        if (controller != null) {
            PacketVelocityDelta packet = new PacketVelocityDelta(entity.getWorld(), delta);
            controller.pushPacket(packet);
        }
    }
}
Also used : PacketVelocityDelta(io.xol.chunkstories.api.net.packets.PacketVelocityDelta) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Example 10 with Controller

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

the class ServerPlayer method unsubscribeAll.

@Override
public void unsubscribeAll() {
    Iterator<Entity> iterator = getSubscribedToList();
    while (iterator.hasNext()) {
        Entity entity = iterator.next();
        // If one of the entities is controllable ...
        if (entity instanceof EntityControllable) {
            EntityControllable controllableEntity = (EntityControllable) entity;
            Controller entityController = controllableEntity.getControllerComponent().getController();
            // If said entity is controlled by this subscriber/player
            if (entityController == this) {
                // Set the controller to null
                controllableEntity.getControllerComponent().setController(null);
            }
        }
        ((EntityBase) entity).unsubscribe(this);
        iterator.remove();
    }
}
Also used : EntityBase(io.xol.chunkstories.api.entity.EntityBase) Entity(io.xol.chunkstories.api.entity.Entity) Controller(io.xol.chunkstories.api.entity.Controller) EntityControllable(io.xol.chunkstories.api.entity.interfaces.EntityControllable)

Aggregations

Controller (io.xol.chunkstories.api.entity.Controller)11 EntityControllable (io.xol.chunkstories.api.entity.interfaces.EntityControllable)10 WorldMaster (io.xol.chunkstories.api.world.WorldMaster)6 Player (io.xol.chunkstories.api.player.Player)4 Vector3d (org.joml.Vector3d)3 Location (io.xol.chunkstories.api.Location)2 LocalPlayer (io.xol.chunkstories.api.client.LocalPlayer)2 WorldClient (io.xol.chunkstories.api.world.WorldClient)2 GameContext (io.xol.chunkstories.api.GameContext)1 ClientInterface (io.xol.chunkstories.api.client.ClientInterface)1 Entity (io.xol.chunkstories.api.entity.Entity)1 EntityBase (io.xol.chunkstories.api.entity.EntityBase)1 EntityComponentController (io.xol.chunkstories.api.entity.components.EntityComponentController)1 EntityCreative (io.xol.chunkstories.api.entity.interfaces.EntityCreative)1 EntityFlying (io.xol.chunkstories.api.entity.interfaces.EntityFlying)1 EntityWorldModifier (io.xol.chunkstories.api.entity.interfaces.EntityWorldModifier)1 EntityDeathEvent (io.xol.chunkstories.api.events.entity.EntityDeathEvent)1 PlayerDeathEvent (io.xol.chunkstories.api.events.player.PlayerDeathEvent)1 PlayerVoxelModificationEvent (io.xol.chunkstories.api.events.player.voxel.PlayerVoxelModificationEvent)1 UnauthorizedClientActionException (io.xol.chunkstories.api.exceptions.UnauthorizedClientActionException)1