Package org.spout.api.geo

Examples of org.spout.api.geo.World


public class BlockBulkHandler extends MessageHandler<BlockBulkMessage> {
  @Override
  public void handleClient(ClientSession session, BlockBulkMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();
    RepositionManager rm = player.getNetwork().getRepositionManager();
    int baseX = message.getChunkX() << Chunk.BLOCKS.BITS;
    int baseZ = message.getChunkZ() << Chunk.BLOCKS.BITS;

    for (int i = 0; i < message.getChanges(); i++) {
      int x = rm.convertX(message.getCoordinates()[i * 3] + baseX);
      int y = rm.convertY(message.getCoordinates()[i * 3 + 1]);
      int z = rm.convertZ(message.getCoordinates()[i * 3 + 2] + baseZ);

      short type = message.getTypes()[i];
      byte data = message.getMetadata()[i];

      BlockMaterial material = (BlockMaterial) VanillaMaterials.getMaterial(type, data);
      world.getChunkFromBlock(x, y, z).getBlock(x, y, z).setMaterial(material);
    }

    //TODO: implement
    System.out.println(message.toString());
  }
View Full Code Here


public class ChunkBulkHandler extends MessageHandler<ChunkBulkMessage> {
  @Override
  public void handleClient(ClientSession session, ChunkBulkMessage message) {
    Player player = session.getPlayer();
    World world = player.getEngine().getDefaultWorld();//player.getWorld();
    RepositionManager rm = player.getNetwork().getRepositionManager();

    for (int c = 0; c < message.getX().length; c++) {
      int baseX = message.getX()[c] << Chunk.BLOCKS.BITS;
      int baseZ = message.getZ()[c] << Chunk.BLOCKS.BITS;

      final byte[][] data = message.getData()[c];

      for (int i = 0; i < 16; i++) {
        int baseY = i << Chunk.BLOCKS.BITS;

        int index = 0;
        for (int xx = 0; xx < Chunk.BLOCKS.SIZE; xx++) {
          for (int yy = 0; yy < Chunk.BLOCKS.SIZE; yy++) {
            for (int zz = 0; zz < Chunk.BLOCKS.SIZE; zz++) {
              int x = rm.convertX(xx + baseX);
              int y = rm.convertY(yy + baseY);
              int z = rm.convertZ(zz + baseZ);

              short type = data[i][index];
              byte dat;
              if (index % 2 == 0) {
                dat = (byte) (data[i][(index / 2) + 4096] >> 4);
              } else {
                dat = (byte) (data[i][(index / 2) + 4096] & 0xF);
              }
              index++;

              if (type > 0) {
                BlockMaterial material = (BlockMaterial) VanillaMaterials.getMaterial(type, dat);
                world.getChunkFromBlock(x, y, z).getBlock(x, y, z).setMaterial(material);
              }
            }
          }
        }
      }
View Full Code Here

public class BlockChangeHandler extends MessageHandler<BlockChangeMessage> {
  @Override
  public void handleClient(ClientSession session, BlockChangeMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();
    RepositionManager rm = player.getNetwork().getRepositionManager();

    int x = rm.convertX(message.getX());
    int y = rm.convertY(message.getY());
    int z = rm.convertZ(message.getZ());

    short type = message.getType();
    int data = message.getMetadata();

    BlockMaterial material = (BlockMaterial) VanillaMaterials.getMaterial(type, (short) data);
    world.getChunkFromBlock(x, y, z).getBlock(x, y, z).setMaterial(material);
  }
View Full Code Here

public final class EntityEquipmentHandler extends MessageHandler<EntityEquipmentMessage> {
  @Override
  public void handleClient(ClientSession session, EntityEquipmentMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();

    int entityId = message.getEntityId();

    Entity entity = world.getEntity(entityId);
    if (entity == null) {
      player.getEngine().getLogger().warning("EntityEquipmentHandler entity don't exist");
      return;
    }
View Full Code Here

    }
    if (random.nextInt(odd) != 0) {
      return;
    }
    BlockMaterial flower = VanillaMaterials.DANDELION;
    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 = 6; 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).isMaterial(VanillaMaterials.AIR)
            && canFlowerStay(world.getBlock(xx, yy, zz))) {
          world.setBlockMaterial(xx, yy, zz, flower, (short) 0, null);
        }
      }
      if (count == amount - 1 && random.nextInt(4) == 0) {
        flower = VanillaMaterials.ROSE;
        count--;
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);
    final int y = getHighestWorkableBlock(world, x, z);
    if (y == -1) {
      return;
View Full Code Here

  @Override
  public void populate(Chunk chunk, Random random) {
    if (chunk.getY() != 4) {
      return;
    }
    final World world = chunk.getWorld();
    final SugarCaneStackObject canes = new SugarCaneStackObject();
    canes.setRandom(random);
    byte successfulClusterCount = 0;
    for (byte count = 0; count < clusterPlaceAttempts; count++) {
      final int x = chunk.getBlockX(random);
View Full Code Here

public final class PlayerTimeHandler extends MessageHandler<PlayerTimeMessage> {
  @Override
  public void handleClient(ClientSession session, PlayerTimeMessage message) {
    Player player = session.getPlayer();
    World world = player.getWorld();

    Sky sky = world.add(Sky.class);
    sky.setTime(message.getTime());
  }
View Full Code Here

          lastPos = pos;
          return;
        }

        float exhaustion = getExhaustion();
        final World world = pos.getWorld();

        // Did not move 1 block pos
        if (lastPos.getBlockX() != pos.getBlockX() || lastPos.getBlockY() != pos.getBlockY() || lastPos.getBlockZ() != pos.getBlockZ()) {
          int dx = lastPos.getBlockX() - pos.getBlockX();
          int dy = lastPos.getBlockY() - pos.getBlockY();
          int dz = lastPos.getBlockZ() - pos.getBlockZ();

          final boolean sprinting = human.isSprinting();
          final boolean jumping = human.isJumping();
          if (world.getBlock(pos).getMaterial() instanceof Water && world.getBlock(lastPos).getMaterial() instanceof Water) {
            // swimming            ;
            exhaustion += 0.015F * Math.sqrt(dx * dx + dy * dy + dz * dz);
          } else if (sprinting && jumping) {
            // sprint jumping
            exhaustion += 0.8f;
View Full Code Here

  @Override
  public void onTick(float dt) {
    switch (getEngine().getPlatform()) {
      case PROXY:
      case SERVER:
        World world = head.getPosition().getWorld();
        if (!(world.getBlock(head.getPosition()).getMaterial() instanceof Water)) {
          setAir(MAX_AIR);
          return;
        }

        if (owner instanceof Player && !getOwner().get(Human.class).getGameMode().equals(GameMode.SURVIVAL)) {
          return;
        }

        setAir(getAir() - dt);
        if (getAir() < 0) {
          // out of air; damage one heart every second
          if (damageTimer-- < 0) {
            health.damage(2, new BlockDamageCause(world.getBlock(head.getPosition()), DamageType.DROWN));
            damageTimer = 20;
          }
        }
        break;
      case CLIENT:
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.