Package org.spout.api.geo.discrete

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


    int y = rmInverse.convertY(message.getY());
    int z = rmInverse.convertZ(message.getZ());
    int state = message.getState();

    World w = player.getWorld();
    Point point = new Point(w, x, y, z);
    Block block = w.getBlock(point);
    BlockMaterial blockMaterial = block.getMaterial();

    short minecraftID = VanillaMaterials.getMinecraftId(blockMaterial);
    BlockFace clickedFace = message.getFace();
    Human human = player.get(Human.class);
    if (human == null) {
      return;
    }
    Slot currentSlot = PlayerUtil.getHeldSlot(player);
    if (currentSlot == null) {
      return;
    }
    ItemStack heldItem = currentSlot.get();

    // Don't block protections if dropping an item, silly Notch...
    if (state != PlayerDiggingMessage.STATE_DROP_ITEM && state != PlayerDiggingMessage.STATE_SHOOT_ARROW_EAT_FOOD) {
      Collection<Protection> protections = player.getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(point);
      for (Protection p : protections) {
        if (p.contains(point) && !human.isOp()) {
          player.getNetwork().getSession().send(new BlockChangeMessage(x, y, z, minecraftID, block.getBlockData() & 0xF, rm));
          player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
          return;
        }
      }
    }

    if (state == PlayerDiggingMessage.STATE_DROP_ITEM && x == 0 && y == 0 && z == 0) {
      human.dropItem();
      return;
    }

    boolean isInteractable = true;
    if (blockMaterial == VanillaMaterials.AIR) {
      isInteractable = false;
    }
    // TODO VanillaPlayerInteractBlockEvent and add in Results to it (to
    // more indepthly take away durability).
    switch (state) {
      case PlayerDiggingMessage.STATE_START_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          final PlayerInteractBlockEvent event = new PlayerInteractBlockEvent(player, block, point, clickedFace, Action.LEFT_CLICK);
          if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
            if (human.isCreative() || blockMaterial.getHardness() == 0.0f) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
              }
            }
          } else {
            // Perform interactions
            if (heldItem == null) {
              // interacting using fist
            } else if (!isInteractable) {
              // interacting with nothing using item
              heldItem.getMaterial().onInteract(player, Action.LEFT_CLICK);
            } else {
              // interacting with block using item
              heldItem.getMaterial().onInteract(player, block, Action.LEFT_CLICK, clickedFace);
            }

            if (isInteractable) {
              Block neigh = block.translate(clickedFace);
              boolean fire = neigh.getMaterial().equals(VanillaMaterials.FIRE);
              if (fire) {
                // put out fire
                if (VanillaMaterials.FIRE.onDestroy(neigh, new PlayerBreakCause(player, neigh))) {
                  GeneralEffects.RANDOM_FIZZ.playGlobal(block.getPosition());
                }
              } else if (human.isSurvival() && blockMaterial.getHardness() != 0.0f) {
                ItemStack currentItem = PlayerUtil.getHeldSlot(player).get();
                if (currentItem != null) {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), currentItem.getMaterial());
                } else {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), VanillaMaterials.AIR);
                }
              } else {
                // insta-break
                if (breakBlock(blockMaterial, block, human, session)) {
                  GeneralEffects.BREAKBLOCK.playGlobal(block.getPosition(), blockMaterial, player);
                }
              }
            }
          }
        }
        break;
      case PlayerDiggingMessage.STATE_CANCEL_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          player.get(Digging.class).stopDigging(new Point(w, x, y, z), false);
        }
        break;
      case PlayerDiggingMessage.STATE_DONE_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          Digging diggingComponent = player.get(Digging.class);

          if (!diggingComponent.stopDigging(new Point(w, x, y, z), true) || !isInteractable) {
            if (!diggingComponent.isDigging()) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
View Full Code Here


    }
    return true;
  }

  private boolean isProtected(Player player, RepositionManager rm, int x, int y, int z, Block block, short minecraftID) {
    final Point point = new Point(block.getWorld(), x, y, z);
    Collection<Protection> protections = player.getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(point);
    for (Protection p : protections) {
      if (p.contains(point) && !player.get(Human.class).isOp()) {
        player.getNetwork().getSession().send(new BlockChangeMessage(x, y, z, minecraftID, block.getBlockData() & 0xF, rm));
        player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
View Full Code Here

  @Override
  public void handleClient(ClientSession session, PlayerPositionMessage message) {
    Player player = session.getPlayer();

    World world = session.getEngine().getDefaultWorld();
    player.getPhysics().setPosition(new Point(world, (float) message.getX(), (float) message.getY(), (float) message.getZ()));
    // TODO: player position isnt updated
    System.out.println(message.toString());
  }
View Full Code Here

    Ping ping = holder.get(Ping.class);
    if (ping != null) {
      ping.refresh();
    }

    final Point rawPosition = new Point(message.getPosition(), holder.getWorld());
    final Point newPosition = rmInverse.convert(rawPosition);
    final Point position = holder.getPhysics().getPosition();

    if (!(holder.getNetwork() instanceof VanillaPlayerNetworkComponent)) {
      throw new IllegalStateException("Using Vanilla Protocol without using VanillaNetworkSynchronizer");
    }
    if (!position.equals(newPosition)) {
      final Human human = holder.get(Human.class);
      // TODO: live?
      holder.getPhysics().setTransform(new Transform(newPosition, holder.getPhysics().getRotation(), holder.getPhysics().getScale()), false);

      //Don't use client onGround value, calculate ourselves
      //MC Client is on ground if y value is whole number, or half step (e.g 55.0, or 65.5)
      float yDiff = Math.abs(newPosition.getBlockY() - newPosition.getY());
      if (yDiff > 0.4) {
        yDiff -= 0.5F; //half blocks
      }
      final BlockMaterial ground = newPosition.getBlock().translate(BlockFace.BOTTOM).getMaterial();
      final boolean onGround = yDiff < 0.01 && (ground instanceof VanillaBlockMaterial && ground.getShape() != null);
      final boolean wasOnGround = human.isOnGround();
      human.setOnGround(onGround);

      //Update falling state
      final boolean wasFalling = human.isFalling();
      if (!onGround && newPosition.getY() < position.getY()) {
        human.setFalling(true);
      } else {
        human.setFalling(false);
      }

      //Hover tracking
      if (wasOnGround && !onGround) {
        human.getData().put("position_on_ground", position);
        human.getData().put("time_in_air", holder.getWorld().getAge());
      } else if (!wasOnGround && !onGround) {
        //Changed directions
        if (wasFalling && !human.isFalling() || human.isInWater()) {
          human.getData().remove("time_in_air");
        }
        float time = human.getData().get("time_in_air", holder.getWorld().getAge());
        //hovering or still rising
        if (time + 2000 < holder.getWorld().getAge() && newPosition.getY() - position.getY() >= 0) {
          if (!human.canFly()) {
            holder.sendMessage("Hover cheating?");
          }
        }
      } else if (!wasOnGround && onGround) {
View Full Code Here

  @Override
  public void handleClient(ClientSession session, PlayerSpawnPositionMessage message) {
    Player player = session.getPlayer();

    World world = player.getWorld();
    player.getPhysics().setPosition(new Point(world, message.getX(), message.getY(), message.getZ()));
    System.out.println(message.toString());
  }
View Full Code Here

  }

  @Override
  public void onTick(float dt) {
    Sky sky = getOwner().getWorld().get(Sky.class);
    Point point = getOwner().getPhysics().getPosition();
    if (sky != null && sky.hasWeather()) {
      if (sky.getWeatherSimulator().isRainingAt((int) point.getX(), (int) point.getY(), (int) point.getZ(), false)) {
        rainTimer += dt;
      } else {
        rainTimer = 0f;
      }
      if (rainTimer >= 2.0f) {
        setFireTick(0f);
        setFireHurting(false);
        rainTimer = 0f;
      }
    }
    if (point.getBlock().getMaterial() instanceof Water || health.isDead()) {
      setFireTick(0f);
      setFireHurting(false);
    }
    if (isFireHurting()) {
      if (internalTimer >= 1.0f) {
View Full Code Here

   * Generates a small description that helps identify where and what this Entity is
   *
   * @return Entity description
   */
  public String getDescription() {
    Point pos = getOwner().getPhysics().getPosition();
    StringBuilder desc = new StringBuilder();
    desc.append(getName()).append(' ');
    desc.append("[x=").append(pos.getBlockX());
    desc.append(",y=").append(pos.getBlockY());
    desc.append(",z=").append(pos.getBlockZ());
    desc.append(",ID=").append(getOwner().getId());
    return desc.toString();
  }
View Full Code Here

    final Set<BoundingBox> placed = new HashSet<BoundingBox>();
    final Queue<StructurePiece> activeBranches = new LinkedList<StructurePiece>();
    final Map<StructurePiece, BoundingBox> lastBoxes = new HashMap<StructurePiece, BoundingBox>();
    final StrongholdCorridor corridor = new StrongholdCorridor(this);
    corridor.setStartOfStronghold(true);
    corridor.setPosition(new Point(w, x, y, z));
    corridor.setRotation(Quaternionf.fromAngleDegAxis(random.nextInt(4) * 90, 0, 1, 0));
    corridor.randomize();
    activeBranches.add(corridor);
    final int size = random.nextInt(MAX_SIZE_RAND + 1) + MAX_SIZE_BASE;
    byte count = 0;
View Full Code Here

  @Override
  public void handleClient(ClientSession session, EntityTeleportMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();
    Entity entity = session.getPlayer();//world.getEntity(message.getEntityId());
    entity.getPhysics().setPosition(new Point(world, message.getX(), message.getY(), message.getZ()));
    entity.getPhysics().rotate(Quaternionf.fromAxesAnglesDeg(message.getPitch(), message.getRotation(), 0));
  }
View Full Code Here

import org.spout.vanilla.protocol.msg.entity.spawn.EntityThunderboltMessage;

public class LightningEntityProtocol extends VanillaEntityProtocol {
  @Override
  public List<Message> getSpawnMessages(Entity entity, RepositionManager rm) {
    Point pos = entity.getPhysics().getPosition();
    return Arrays.<Message>asList(new EntityThunderboltMessage(entity.getId(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), rm));
  }
View Full Code Here

TOP

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

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.