Exemplo n.º 1
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.
    }
  }
Exemplo n.º 2
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final World world = chunk.getWorld();
   if (random.nextInt(WATER_ODD) == 0) {
     final int x = chunk.getBlockX(random);
     final int z = chunk.getBlockZ(random);
     final int y = random.nextInt(128);
     WATER_POND.setRandom(random);
     WATER_POND.randomize();
     if (WATER_POND.canPlaceObject(world, x, y, z)) {
       WATER_POND.placeObject(world, x, y, z);
     }
   }
   if (random.nextInt(LAVA_ODD) == 0) {
     final int x = chunk.getBlockX(random);
     final int z = chunk.getBlockZ(random);
     final int y = random.nextInt(120) + 8;
     if (y >= 63 && random.nextInt(LAVA_SURFACE_ODD) != 0) {
       return;
     }
     LAVA_POND.setRandom(random);
     LAVA_POND.randomize();
     if (LAVA_POND.canPlaceObject(world, x, y, z)) {
       LAVA_POND.placeObject(world, x, y, z);
     }
   }
 }
Exemplo n.º 3
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final World world = chunk.getWorld();
   final OreObject[] ores =
       new OreObject[] {
         new OreObject(OreType.DIRT),
         new OreObject(OreType.GRAVEL),
         new OreObject(OreType.COAL),
         new OreObject(OreType.IRON),
         new OreObject(OreType.REDSTONE),
         new OreObject(OreType.GOLD),
         new OreObject(OreType.LAPIS_LAZULI),
         new OreObject(OreType.DIAMOND)
       };
   for (OreObject ore : ores) {
     ore.setRandom(random);
     for (byte i = 0; i < ore.getAmount(); i++) {
       final int x = chunk.getBlockX(random);
       final int y = random.nextInt(ore.getMaxHeight());
       final int z = chunk.getBlockZ(random);
       if (ore.canPlaceObject(world, x, y, z)) {
         ore.placeObject(world, x, y, z);
       }
     }
   }
 }
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   if (random.nextInt(odd) != 0) {
     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 y = random.nextInt(NetherGenerator.HEIGHT);
     final int z = chunk.getBlockZ(random);
     final Mushroom mushroom =
         random.nextInt(4) == 0 ? VanillaMaterials.RED_MUSHROOM : VanillaMaterials.BROWN_MUSHROOM;
     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, y, zz);
       if (yy != -1
           && world.getBlockMaterial(xx, yy, zz) == VanillaMaterials.AIR
           && mushroom.isValidPosition(world.getBlock(xx, yy, zz), BlockFace.BOTTOM, false)) {
         world.setBlockMaterial(xx, yy, zz, mushroom, (short) 0, null);
       }
     }
   }
 }
Exemplo n.º 5
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]);
      }
    }
  }
Exemplo n.º 6
0
  @Override
  public void populate(Chunk source, Random random) {
    if (source.getY() < 4) {
      return;
    }
    if (random.nextInt(100) > chance) {
      return;
    }

    int x = source.getBlockX();
    int z = source.getBlockZ();
    int y;
    int numSteps = random.nextInt(maxSteps - minSteps + 1) + minSteps;
    for (int i = 0; i < numSteps; i++) {
      x += random.nextInt(3) - 1;
      z += random.nextInt(3) - 1;
      y = source.getBlockY() + 15;
      Block b = source.getWorld().getBlock(x, y, z);
      while (b.getMaterial() == VanillaMaterials.AIR) {
        b = b.translate(BlockFace.BOTTOM);
        if (--y < 0) {
          return;
        }
      }
      if (b.getMaterial() == VanillaMaterials.GRASS) {
        b = b.translate(BlockFace.TOP).setMaterial(VanillaMaterials.TALL_GRASS);
      }
    }
  }
 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;
   }
 }
    public static byte[] getChunkFullData(Chunk c, List<ProtocolEvent> updateEvents) {

      VanillaContainer container = new VanillaContainer();
      c.fillBlockContainer(container);
      container.setLightMode(true);
      c.fillBlockLightContainer(container);
      container.setLightMode(false);
      c.fillSkyLightContainer(container);
      c.fillBlockComponentContainer(container);

      int[] componentX = container.getXArray();
      int[] componentY = container.getYArray();
      int[] componentZ = container.getZArray();

      for (int i = 0; i < container.getBlockComponentCount(); i++) {
        BlockMaterial bm = c.getBlockMaterial(componentX[i], componentY[i], componentZ[i]);
        if (bm instanceof VanillaComplexMaterial) {
          ProtocolEvent event =
              ((VanillaComplexMaterial) bm)
                  .getUpdate(c.getWorld(), componentX[i], componentY[i], componentZ[i]);
          if (event != null) {
            updateEvents.add(event);
          }
        }
      }

      return container.getChunkFullData();
    }
 @Override
 public void updateBlock(Chunk chunk, int x, int y, int z, BlockMaterial material, short data) {
   short id = getMinecraftId(material);
   x += chunk.getBlockX();
   y += chunk.getBlockY();
   z += chunk.getBlockZ();
   if (y >= 0 && y < chunk.getWorld().getHeight()) {
     BlockChangeMessage BCM =
         new BlockChangeMessage(x, y, z, id, getMinecraftData(material, data));
     session.send(false, BCM);
   }
 }
Exemplo n.º 10
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final World world = chunk.getWorld();
   for (OreObject object : ORES) {
     object.setRandom(random);
     for (byte i = 0; i < object.getCount(); i++) {
       final int x = chunk.getBlockX(random);
       final int y = random.nextInt(object.getMaxHeight());
       final int z = chunk.getBlockZ(random);
       object.placeObject(world, x, y, z);
     }
   }
 }
Exemplo n.º 11
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     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;
   }
   if (well.canPlaceObject(world, x, y, z)) {
     well.placeObject(world, x, y, z);
   }
 }
Exemplo n.º 12
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final World world = chunk.getWorld();
   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, world), BlockFace.TOP)) {
         world.setBlockMaterial(xx, yy, zz, VanillaMaterials.LILY_PAD, (short) 0, world);
       }
     }
   }
 }
Exemplo n.º 13
0
 @Override
 public void populate(Chunk chunk, Random random) {
   if (chunk.getY() != 4) {
     return;
   }
   final int size = Chunk.BLOCKS.SIZE;
   final int x = chunk.getBlockX();
   final int z = chunk.getBlockZ();
   final World world = chunk.getWorld();
   final int seed = (int) (world.getSeed() * 73);
   SHIELD_BASE.setSeed(seed);
   SHIELD.setSeed(seed);
   final double[][] noise = WorldGeneratorUtils.fastNoise(SHIELD, size, size, 4, x, 63, z);
   for (int xx = 0; xx < size; xx++) {
     for (int zz = 0; zz < size; zz++) {
       if (noise[xx][zz] > 0.92) {
         final int y = world.getSurfaceHeight(x + xx, z + zz);
         for (int yy = 0; yy >= -7; yy--) {
           if (yy == 0) {
             final Block block = world.getBlock(x + xx, y + yy, z + zz, world);
             if (!canReplace(block.getMaterial())) {
               continue;
             }
             block.setMaterial(
                 block.getY() <= NormalGenerator.SEA_LEVEL
                     ? VanillaMaterials.STATIONARY_WATER
                     : VanillaMaterials.AIR);
           } else {
             if (canReplace(world.getBlockMaterial(x + xx, y + yy, z + zz))) {
               world.setBlockMaterial(
                   x + xx, y + yy, z + zz, VanillaMaterials.STONE, (short) 0, world);
             }
           }
         }
       }
     }
   }
 }
  @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;
  }
Exemplo n.º 16
0
  @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;
  }