Package org.spout.api.geo.discrete

Examples of org.spout.api.geo.discrete.Transform


   * Drops the item specified into the direction the player looks, with slight randomness
   *
   * @param item to drop
   */
  public void dropItem(ItemStack item) {
    final Transform dropFrom;
    EntityHead head = getHead();
    if (head != null) {
      dropFrom = head.getHeadTransform();
    } else {
      dropFrom = getOwner().getPhysics().getTransform();
    }
    // Some constants
    final double impulseForce = 0.3;
    final float maxXZForce = 0.02f;
    final float maxYForce = 0.1f;

    // Create a velocity vector using the transform, apply (random) force
    Vector3f impulse = dropFrom.getRotation().getDirection().mul(impulseForce);

    // Random rotational offset to avoid dropping at the same position
    Random rand = GenericMath.getRandom();
    float xzLength = maxXZForce * rand.nextFloat();
    float yLength = maxYForce * (rand.nextFloat() - rand.nextFloat());
    impulse = impulse.add(Vector2f.createRandomDirection(rand).mul(xzLength).toVector3(yLength));

    // Slightly dropping upwards
    impulse = impulse.add(0.0, 0.1, 0.0);

    // Conversion factor, some sort of unit problem
    //TODO: This needs an actual value and this value might change when gravity changes!
    impulse = impulse.mul(100);

    // Finally drop using a 4 second pickup delay
    Item spawnedItem = Item.drop(dropFrom.getPosition(), item, impulse);
    spawnedItem.setUncollectableDelay(4000);
  }
View Full Code Here


        final Point spawn;

        // Grab safe spawn if newly created world and generator is vanilla generator, else get old one.
        if (newWorld && generator instanceof VanillaGenerator) {
          spawn = ((VanillaGenerator) generator).getSafeSpawn(world);
          world.setSpawnPoint(new Transform(spawn, Quaternionf.IDENTITY, Vector3f.ONE));
        } else {
          spawn = world.getSpawnPoint().getPosition();
        }

        // Start the protection for the spawn
View Full Code Here

  @Permissible ("vanilla.command.debug")
  @CommandDescription (aliases = "resetpos", desc = "Resets players position")
  @Filter (PlayerFilter.class)
  public void resetPosition(Player player, CommandArguments args) throws CommandException {
    args.assertCompletelyParsed();
    player.getNetwork().callProtocolEvent(new EntityUpdateEvent(player, new Transform(player.getPhysics().getPosition(), player.getPhysics().getRotation(), Vector3f.ONE), EntityUpdateEvent.UpdateAction.TRANSFORM, player.getNetwork().getRepositionManager()), player);
  }
View Full Code Here

  @EventHandler (order = Order.MONITOR)
  public void onPositionSend(EntityUpdateEvent event) {
    if (event.getAction() != EntityUpdateEvent.UpdateAction.TRANSFORM || event.isFullSync() || event.getEntity() != getOwner()) {
      return;
    }
    Transform live = event.getTransform();
    if (first) {
      PlayerSpawnPositionMessage pspMsg = new PlayerSpawnPositionMessage((int) live.getPosition().getX(), (int) live.getPosition().getY(), (int) live.getPosition().getZ(), getRepositionManager());
      event.getMessages().add(pspMsg);
      first = false;
    }
    Point p = event.getTransform().getPosition();
    Quaternionf rot = event.getTransform().getRotation();
View Full Code Here

    }
    Entity e = event.getEntity();
    if (e != null && !(e.getNetwork() instanceof VanillaNetworkProtocol)) {
      return;
    }
    Transform liveTransform = event.getTransform();
    boolean self = (e == getOwner());
    boolean spawn = event.getAction() == EntityUpdateEvent.UpdateAction.ADD;
    boolean destroy = event.getAction() == EntityUpdateEvent.UpdateAction.REMOVE;
    boolean update = !spawn && !destroy;
    EntityProtocol ep = ((VanillaNetworkProtocol) e.getNetwork()).getEntityProtocol();
View Full Code Here

  // TODO: vanilla input
  @Override
  public void onTick(float dt) {
    Player player = (Player) getOwner();
    Transform ts = player.getPhysics().getTransform();
    PlayerInputState inputState = player.input();
    PhysicsComponent sc = player.getPhysics();

    Vector3f offset = Vector3f.ZERO;
    float speed = 50;
    if (inputState.getForward()) {
      offset = offset.sub(ts.forwardVector().mul(speed * dt));
    }
    if (inputState.getBackward()) {
      offset = offset.add(ts.forwardVector().mul(speed * dt));
    }
    if (inputState.getLeft()) {
      offset = offset.sub(ts.rightVector().mul(speed * dt));
    }
    if (inputState.getRight()) {
      offset = offset.add(ts.rightVector().mul(speed * dt));
    }
    if (inputState.getJump()) {
      offset = offset.add(ts.upVector().mul(speed * dt));
    }
    if (inputState.getCrouch()) {
      offset = offset.sub(ts.upVector().mul(speed * dt));
    }

    player.get(EntityHead.class).setOrientation(Quaternionf.fromAxesAnglesDeg(inputState.pitch(), inputState.yaw(), ts.getRotation().getAxesAngleDeg().getZ()));
    player.getPhysics().translate(offset);
    player.getPhysics().setRotation(Quaternionf.fromAxesAnglesDeg(inputState.pitch(), inputState.yaw(), ts.getRotation().getAxesAngleDeg().getZ()));
  }
View Full Code Here

public class PlayerInteract extends InteractComponent {
  @Override
  public BlockIterator getAlignedBlocks() {
    Player player = (Player) getOwner();
    Transform ptr = player.get(PlayerHead.class).getHeadTransform();
    Transform tr = new Transform();
    tr.setRotation(Quaternionf.fromRotationTo(Vector3f.FORWARD, ptr.getRotation().getDirection().mul(-1)));
    tr.setPosition(ptr.getPosition());
    return new BlockIterator(player.getWorld(), tr, getRange());
  }
View Full Code Here

    return view;
  }

  @Override
  public void updateView() {
    Transform transform = getOwner().getPhysics().getTransform();
    Point point = transform.getPosition().add(0.0f, getHeight(), 0.0f);
    Matrix4f pos = Matrix4f.createTranslation(point.mul(-1));
    Matrix4f rot = getRotation();
    view = pos.mul(rot);
    frustum.update(projection, view, transform.getPosition());
  }
View Full Code Here

    frustum.update(projection, view, transform.getPosition());
  }

  @Override
  public void updateReflectedView() {
    Transform transform = getOwner().getPhysics().getTransform();
    Point point = transform.getPosition().add(0.0f, getHeight(), 0.0f);
    Matrix4f pos = Matrix4f.createTranslation(point.mul(-1));
    Matrix4f rot = getRotation();
    view = Matrix4f.createScaling(new Vector4f(1, -1, 1, 1)).mul(pos).mul(rot);
    frustum.update(projection, view, transform.getPosition());
  }
View Full Code Here

      player.getPhysics().setPosition(point);
      player.getNetwork().forceRespawn();
      Human human = player.add(Human.class);
      human.getHealth().setHealth(human.getHealth().getMaxHealth(), HealthChangeCause.SPAWN);

      final Transform spawn = new Transform(player.getPhysics().getTransform());
      spawn.setPosition(point);
    }
  }
View Full Code Here

TOP

Related Classes of org.spout.api.geo.discrete.Transform

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.