Пример #1
0
  @Override
  public void populate(Chunk source, Random random) {
    World world = source.getWorld();
    int[] iterations = new int[] {10, 20, 20, 2, 8, 1, 1, 1};
    int[] amount = new int[] {32, 16, 8, 8, 7, 7, 6};
    BlockMaterial[] type =
        new BlockMaterial[] {
          VanillaMaterials.GRAVEL,
          VanillaMaterials.COAL_ORE,
          VanillaMaterials.IRON_ORE,
          VanillaMaterials.GOLD_ORE,
          VanillaMaterials.REDSTONE_ORE,
          VanillaMaterials.DIAMOND_ORE,
          VanillaMaterials.LAPIS_LAZULI_ORE
        };

    int[] maxHeight = new int[] {128, 128, 128, 128, 128, 64, 32, 16, 16, 32};

    for (int i = 0; i < type.length; i++) {
      for (int j = 0; j < iterations[i]; j++) {
        generateOre(
            world,
            random,
            source.getX() * 16 + random.nextInt(16),
            random.nextInt(maxHeight[i]),
            source.getZ() * 16 + random.nextInt(16),
            amount[i],
            type[i]);
      }
    }
  }
 @Override
 protected boolean canSendChunk(Chunk c, Set<Chunk> unsendable) {
   if (!c.canSend()) {
     if (unsendable != null) {
       unsendable.add(c);
     }
     c.populate(true, true, true);
     return false;
   }
   if (activeChunks.contains(c.getX(), c.getZ())) {
     return true;
   }
   boolean canSend = true;
   Collection<Chunk> chunks = chunkInit.getChunks(c);
   for (Chunk cc : chunks) {
     if (!cc.canSend()) {
       if (unsendable != null) {
         unsendable.add(c);
       }
       canSend = false;
       cc.populate(true, true, true);
     }
   }
   return canSend;
 }
Пример #3
0
  @Override
  public void populate(Chunk chunk, Random random) {
    if (random.nextInt(PROBABILITY) == 0) {
      final int width = random.nextBoolean() ? 9 : 7;
      final int height = random.nextBoolean() ? 9 : 7;

      int cx = chunk.getX() * 16 + random.nextInt(16);
      int cy = chunk.getY() * 16 + random.nextInt(16);
      int cz = chunk.getZ() * 16 + random.nextInt(16);

      if (chunk.getWorld().getBlockId(cx, cy, cz) == 0) {
        return; // No dungeons in the air, plox!
      }

      for (int x = cx; x < cx + width; x++) {
        for (int y = cy; y < cy + HEIGHT; y++) {
          for (int z = cz; z < cz + height; z++) {
            short id = 0;
            if (x == cx || x == cx + width - 1 || z == cz || z == cz + height - 1) {
              id = VanillaMaterials.COBBLESTONE.getId();
            }
            if (y == cy || y == cy + HEIGHT - 1) {
              id =
                  random.nextBoolean()
                      ? VanillaMaterials.COBBLESTONE.getId()
                      : VanillaMaterials.MOSS_STONE.getId();
            }
            chunk.getWorld().setBlockId(x, y, z, id, chunk.getWorld());
          }
        }
      }

      chunk
          .getWorld()
          .setBlockMaterial(
              cx + width / 2,
              cy + 1,
              cz + height / 2,
              VanillaMaterials.MONSTER_SPAWNER,
              chunk.getWorld());

      chunk
          .getWorld()
          .setBlockMaterial(
              cx + 1, cy + 1, cz + height / 2, VanillaMaterials.CHEST, chunk.getWorld());

      chunk
          .getWorld()
          .setBlockMaterial(
              cx + width / 2, cy + 1, cz + 1, VanillaMaterials.CHEST, chunk.getWorld());

      // TODO Fill Chests with stuff, kinda waiting for inventories in worlds.
    }
  }
Пример #4
0
  private SpoutChunk[][][] getChunks(int x, int y, int z, CuboidBlockMaterialBuffer buffer) {
    Vector3 size = buffer.getSize();

    int startX = x;
    int startY = y;
    int startZ = z;

    int endX = x + size.getFloorX();
    int endY = y + size.getFloorY();
    int endZ = z + size.getFloorZ();

    Chunk start = getChunkFromBlock(startX, startY, startZ);
    Chunk end = getChunkFromBlock(endX - 1, endY - 1, endZ - 1);

    int chunkStartX = start.getX();
    int chunkStartY = start.getY();
    int chunkStartZ = start.getZ();

    int chunkEndX = end.getX();
    int chunkEndY = end.getY();
    int chunkEndZ = end.getZ();

    int chunkSizeX = chunkEndX - chunkStartX + 1;
    int chunkSizeY = chunkEndY - chunkStartY + 1;
    int chunkSizeZ = chunkEndZ - chunkStartZ + 1;

    SpoutChunk[][][] chunks = new SpoutChunk[chunkSizeX][chunkSizeY][chunkSizeZ];
    for (int dx = chunkStartX; dx <= chunkEndX; dx++) {
      for (int dy = chunkStartY; dy <= chunkEndY; dy++) {
        for (int dz = chunkStartZ; dz <= chunkEndZ; dz++) {
          SpoutChunk chunk = getChunk(dx, dy, dz, LoadOption.LOAD_GEN);
          if (chunk == null) {
            throw new IllegalStateException("Null chunk loaded with LoadOption.LOAD_GEN");
          }
          chunks[dx - chunkStartX][dy - chunkStartY][dz - chunkStartZ] = chunk;
        }
      }
    }
    return chunks;
  }
 public Collection<Chunk> getChunks(Chunk c) {
   if (this.sendColumn()) {
     int x = c.getX();
     int z = c.getZ();
     int height = c.getWorld().getHeight() >> Chunk.BLOCKS.BITS;
     List<Chunk> chunks = new ArrayList<Chunk>(height);
     for (int y = 0; y < height; y++) {
       chunks.add(c.getWorld().getChunk(x, y, z));
     }
     return chunks;
   } else {
     List<Chunk> chunks = new ArrayList<Chunk>(1);
     chunks.add(c);
     return chunks;
   }
 }
  @Override
  public void sendChunk(Chunk c) {

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    if (y < 0 || y >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return;
    }

    initChunk(c.getBase());

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        packetChunkData[cube] = getChunkHeightMap(heights, materials, cube);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiomeType(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      CompressedChunkMessage CCMsg =
          new CompressedChunkMessage(x, z, true, new boolean[16], packetChunkData, biomeData);
      owner.getSession().send(false, CCMsg);
    }

    ChunkSnapshot snapshot =
        c.getSnapshot(SnapshotType.BOTH, EntityType.NO_ENTITIES, ExtraData.NO_EXTRA_DATA);
    short[] rawBlockIdArray = snapshot.getBlockIds();
    short[] rawBlockData = snapshot.getBlockData();
    byte[] rawBlockLight = snapshot.getBlockLight();
    byte[] rawSkyLight = snapshot.getSkyLight();
    byte[] fullChunkData = new byte[Chunk.BLOCKS.HALF_VOLUME * 5];

    int arrIndex = 0;
    for (int i = 0; i < rawBlockIdArray.length; i++) {
      short convert = getMinecraftId(rawBlockIdArray[i]);
      fullChunkData[arrIndex++] = (byte) (convert & 0xFF);
    }

    for (int i = 0; i < rawBlockData.length; i += 2) {
      fullChunkData[arrIndex++] = (byte) ((rawBlockData[i + 1] << 4) | (rawBlockData[i] & 0xF));
    }

    System.arraycopy(rawBlockLight, 0, fullChunkData, arrIndex, rawBlockLight.length);
    arrIndex += rawBlockLight.length;

    System.arraycopy(rawSkyLight, 0, fullChunkData, arrIndex, rawSkyLight.length);

    arrIndex += rawSkyLight.length;

    byte[][] packetChunkData = new byte[16][];
    packetChunkData[y] = fullChunkData;
    CompressedChunkMessage CCMsg =
        new CompressedChunkMessage(x, z, false, new boolean[16], packetChunkData, null);
    owner.getSession().send(false, CCMsg);
  }
  @Override
  public Collection<Chunk> sendChunk(Chunk c) {

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    if (y < 0 || y >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return null;
    }

    initChunk(c.getBase());

    Collection<Chunk> chunks = null;

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        Point pp =
            new Point(
                c.getWorld(),
                x << Chunk.BLOCKS.BITS,
                cube << Chunk.BLOCKS.BITS,
                z << Chunk.BLOCKS.BITS);
        packetChunkData[cube] = chunkInit.getChunkData(heights, materials, pp);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiome(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x, z, true, new boolean[16], packetChunkData, biomeData, player.getSession());
      player.getSession().send(false, CCMsg);

      chunks = chunkInit.getChunks(c);
    }

    byte[] fullChunkData = ChunkInit.getChunkFullData(c);

    byte[][] packetChunkData = new byte[16][];
    packetChunkData[y] = fullChunkData;
    ChunkDataMessage CCMsg =
        new ChunkDataMessage(
            x, z, false, new boolean[16], packetChunkData, null, player.getSession());
    player.getSession().send(false, CCMsg);

    return chunks;
  }
  @Override
  protected Collection<Chunk> sendChunk(Chunk c, boolean force) {

    if (!force) {
      return sendChunk(c);
    }

    int x = c.getX();
    int y = c.getY(); // + SEALEVEL_CHUNK;
    int z = c.getZ();

    RepositionManager rm = getRepositionManager();

    int cY = rm.convertChunkY(y);

    if (cY < 0 || cY >= c.getWorld().getHeight() >> Chunk.BLOCKS.BITS) {
      return null;
    }

    initChunkRaw(c.getBase());

    Collection<Chunk> chunks = null;

    List<ProtocolEvent> events = new ArrayList<ProtocolEvent>();

    if (activeChunks.add(x, z)) {
      Point p = c.getBase();
      int[][] heights = getColumnHeights(p);
      BlockMaterial[][] materials = getColumnTopmostMaterials(p);

      byte[][] packetChunkData = new byte[16][];

      for (int cube = 0; cube < 16; cube++) {
        int serverCube = rm.getInverse().convertChunkY(cube);
        Point pp =
            new Point(
                c.getWorld(),
                x << Chunk.BLOCKS.BITS,
                serverCube << Chunk.BLOCKS.BITS,
                z << Chunk.BLOCKS.BITS);
        packetChunkData[cube] = chunkInit.getChunkData(heights, materials, pp, events);
      }

      Chunk chunk = p.getWorld().getChunkFromBlock(p);
      byte[] biomeData = new byte[Chunk.BLOCKS.AREA];
      for (int dx = x; dx < x + Chunk.BLOCKS.SIZE; ++dx) {
        for (int dz = z; dz < z + Chunk.BLOCKS.SIZE; ++dz) {
          Biome biome = chunk.getBiome(dx & Chunk.BLOCKS.MASK, 0, dz & Chunk.BLOCKS.MASK);
          if (biome instanceof VanillaBiome) {
            biomeData[(dz & Chunk.BLOCKS.MASK) << 4 | (dx & Chunk.BLOCKS.MASK)] =
                (byte) ((VanillaBiome) biome).getBiomeId();
          }
        }
      }

      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x,
              z,
              true,
              new boolean[16],
              packetChunkData,
              biomeData,
              player.getSession(),
              getRepositionManager());
      player.getSession().send(false, CCMsg);

      chunks = chunkInit.getChunks(c);
    }

    if (chunks == null || !chunks.contains(c)) {

      byte[] fullChunkData = ChunkInit.getChunkFullData(c, events);

      byte[][] packetChunkData = new byte[16][];
      packetChunkData[cY] = fullChunkData;
      ChunkDataMessage CCMsg =
          new ChunkDataMessage(
              x,
              z,
              false,
              new boolean[16],
              packetChunkData,
              null,
              player.getSession(),
              getRepositionManager());
      player.getSession().send(false, CCMsg);

      if (chunks == null) {
        chunks = new ArrayList<Chunk>(1);
      }
      chunks.add(c);
    }

    for (ProtocolEvent e : events) {
      this.callProtocolEvent(e);
    }

    return chunks;
  }