Package org.spout.api.geo

Examples of org.spout.api.geo.World


  @Override
  public void populate(Chunk chunk, Random random) {
    if (chunk.getY() != 4) {
      return;
    }
    final World world = chunk.getWorld();
    final int amount = getAmount(random);
    for (byte count = 0; count < amount; count++) {
      final int x = chunk.getBlockX(random);
      final int z = chunk.getBlockZ(random);
      for (byte size = 5; size > 0; size--) {
        final int xx = x - 7 + random.nextInt(15);
        final int zz = z - 7 + random.nextInt(15);
        final int yy = getHighestWorkableBlock(world, xx, zz);
        if (yy != -1 && world.getBlockMaterial(xx, yy, zz) == VanillaMaterials.AIR
            && VanillaMaterials.LILY_PAD.canAttachTo(world.getBlock(xx, yy - 1, zz), BlockFace.TOP)) {
          world.setBlockMaterial(xx, yy, zz, VanillaMaterials.LILY_PAD, (short) 0, null);
        }
      }
    }
  }
View Full Code Here


    Player player = session.getPlayer();
    RepositionManager rm = player.getNetwork().getRepositionManager();
    RepositionManager rmInverse = rm.getInverse();
    message = message.convert(rmInverse);

    World world = player.getWorld();
    Slot currentSlot = PlayerUtil.getHeldSlot(player);
    if (currentSlot == null) {
      return;
    }
    ItemStack holding = currentSlot.get();
    Material holdingMat = holding == null ? null : holding.getMaterial();

    /*
     * The notch client's packet sending is weird. Here's how it works: If the client is clicking a block not in range, sends a packet with x=-1,y=255,z=-1 If the client is clicking a block in
     * range with an item in hand (id > 255) Sends both the normal block placement packet and a (-1,255,-1) one If the client is placing a block in range with a block in hand, only one normal
     * packet is sent That is how it usually happens. Sometimes it doesn't happen like that. Therefore, a hacky workaround.
     */
    final BlockFace clickedFace = message.getDirection();
    Hunger hunger = player.add(Hunger.class);
    if ((holdingMat instanceof Food && hunger.getHunger() != VanillaData.HUNGER.getDefaultValue()) || holdingMat instanceof Sword || (holdingMat instanceof PotionItem && !((PotionItem) holdingMat).isSplash())) {
      player.get(Living.class).setEatingBlocking(true);
      hunger.setEating(true, currentSlot);
      return;
    }
    if (clickedFace == BlockFace.THIS) {
      // Right clicked air with an item.
      PlayerInteractBlockEvent event = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, null, null, clickedFace, Action.RIGHT_CLICK));

      // May have been changed by the event
      holding = currentSlot.get();
      holdingMat = holding == null ? null : holding.getMaterial();

      if (holdingMat != null) {
        holdingMat.onInteract(player, Action.RIGHT_CLICK);
      }
    } else {
      // TODO: Validate the x/y/z coordinates of the message to check if it is in range of the player
      // This is an anti-hack requirement (else hackers can load far-away chunks and crash the server)

      // Get clicked block and validated face against it was placed
      final Block clickedBlock = world.getBlock(message.getX(), message.getY(), message.getZ());
      final BlockMaterial clickedMaterial = clickedBlock.getMaterial();

      // Perform interaction event
      PlayerInteractBlockEvent interactEvent = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, clickedBlock, clickedBlock.getPosition(), clickedFace, Action.RIGHT_CLICK));

View Full Code Here

      return;
    }
    if (random.nextInt(odd) != 0) {
      return;
    }
    final World world = chunk.getWorld();
    final int x = chunk.getBlockX(random);
    final int z = chunk.getBlockZ(random);
    for (int amount = getAmount(random); amount >= 0; amount--) {
      final int xx = x - 7 + random.nextInt(15);
      final int zz = z - 7 + random.nextInt(15);
      final int yy = getHighestWorkableBlock(world, xx, zz);
      if (yy != -1 && world.getBlockMaterial(xx, yy, zz) == VanillaMaterials.AIR) {
        world.setBlockMaterial(xx, yy, zz, VanillaMaterials.PUMPKIN_BLOCK, (short) random.nextInt(4), null);
      }
    }
  }
View Full Code Here

public class EntityRelativePositionHandler extends MessageHandler<EntityRelativePositionMessage> {
  @Override
  public void handleClient(ClientSession session, EntityRelativePositionMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();
    Entity entity = world.getEntity(message.getEntityId());
    entity.getPhysics().translate(new Vector3f(message.getDeltaX(), message.getDeltaY(), message.getDeltaZ()));
  }
View Full Code Here

public class EntityTeleportHandler extends MessageHandler<EntityTeleportMessage> {
  @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

TOP

Related Classes of org.spout.api.geo.World

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.