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;
}
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);
}
}
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);
}
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);
}
}
}
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();
}
}
Aggregations