Beispiel #1
0
 @Override
 public void setBlockMetadataAt(int metadata, BlockLocation blockLocation) {
   ChunkLocation location = new ChunkLocation(blockLocation);
   BlockLocation chunkBlockOffset = new BlockLocation(location);
   Chunk chunk = getChunkAt(location);
   if (chunk == null) return;
   chunk.setBlockMetadataAt(
       metadata,
       blockLocation.getX() - chunkBlockOffset.getX(),
       blockLocation.getY() - chunkBlockOffset.getY(),
       blockLocation.getZ() - chunkBlockOffset.getZ());
 }
Beispiel #2
0
 @Override
 public Block getBlockAt(BlockLocation location) {
   ChunkLocation chunkLocation = new ChunkLocation(location);
   Chunk chunk = getChunkAt(chunkLocation);
   if (chunk == null) return null;
   BlockLocation chunkBlockOffset = new BlockLocation(chunkLocation);
   int chunkOffsetX = location.getX() - chunkBlockOffset.getX();
   int chunkOffsetY = location.getY() - chunkBlockOffset.getY();
   int chunkOffsetZ = location.getZ() - chunkBlockOffset.getZ();
   int id = chunk.getBlockIdAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ);
   int metadata = chunk.getBlockMetadataAt(chunkOffsetX, chunkOffsetY, chunkOffsetZ);
   return new Block(this, chunk, location, id, metadata);
 }
Beispiel #3
0
 @Override
 public int getBlockMetadataAt(BlockLocation blockLocation) {
   ChunkLocation location = new ChunkLocation(blockLocation);
   BlockLocation chunkBlockOffset = new BlockLocation(location);
   Chunk chunk = getChunkAt(location);
   if (chunk == null) return 0;
   int metadata =
       chunk.getBlockMetadataAt(
           blockLocation.getX() - chunkBlockOffset.getX(),
           blockLocation.getY() - chunkBlockOffset.getY(),
           blockLocation.getZ() - chunkBlockOffset.getZ());
   return metadata;
 }
Beispiel #4
0
  public static NetworkChunkData chunksToData(ParsedChunkData chunks) {
    int chunkMask = 0;
    boolean fullChunk = chunks.getBiomes() != null;
    boolean sky = false;
    int length = fullChunk ? chunks.getBiomes().length : 0;
    byte[] data = null;
    int pos = 0;
    ShortBuffer buf = null;
    // 0 = Determine length and masks.
    // 1 = Add blocks.
    // 2 = Add block light.
    // 3 = Add sky light.
    for (int pass = 0; pass < 4; pass++) {
      for (int ind = 0; ind < chunks.getChunks().length; ++ind) {
        Chunk chunk = chunks.getChunks()[ind];
        if (chunk != null && (!fullChunk || !chunk.isEmpty())) {
          if (pass == 0) {
            chunkMask |= 1 << ind;
            length += chunk.getBlocks().getData().length * 2;
            length += chunk.getBlockLight().getData().length;
            if (chunk.getSkyLight() != null) {
              length += chunk.getSkyLight().getData().length;
            }
          }

          if (pass == 1) {
            short blocks[] = chunk.getBlocks().getData();
            buf.position(pos / 2);
            buf.put(blocks, 0, blocks.length);
            pos += blocks.length * 2;
          }

          if (pass == 2) {
            byte blocklight[] = chunk.getBlockLight().getData();
            System.arraycopy(blocklight, 0, data, pos, blocklight.length);
            pos += blocklight.length;
          }

          if (pass == 3 && chunk.getSkyLight() != null) {
            byte skylight[] = chunk.getSkyLight().getData();
            System.arraycopy(skylight, 0, data, pos, skylight.length);
            pos += skylight.length;
            sky = true;
          }
        }
      }

      if (pass == 0) {
        data = new byte[length];
        buf = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
      }
    }

    // Add biomes.
    if (fullChunk) {
      System.arraycopy(chunks.getBiomes(), 0, data, pos, chunks.getBiomes().length);
      pos += chunks.getBiomes().length;
    }

    return new NetworkChunkData(chunkMask, fullChunk, sky, data);
  }
Beispiel #5
0
  /** Reads a WAVE Chunk. */
  protected boolean readChunk(RepInfo info) throws IOException {
    Chunk chunk = null;
    ChunkHeader chunkh = new ChunkHeader(this, info);
    if (!chunkh.readHeader(_dstream)) {
      return false;
    }
    int chunkSize = (int) chunkh.getSize();
    bytesRemaining -= chunkSize + 8;

    if (bytesRemaining < 0) {
      info.setMessage(new ErrorMessage("Invalid chunk size", _nByte));
      return false;
    }

    String id = chunkh.getID();
    if ("fmt ".equals(id)) {
      if (formatChunkSeen) {
        dupChunkError(info, "Format");
      }
      chunk = new FormatChunk(this, chunkh, _dstream);
      formatChunkSeen = true;
    } else if ("data".equals(id)) {
      if (dataChunkSeen) {
        dupChunkError(info, "Data");
      }
      chunk = new DataChunk(this, chunkh, _dstream);
      dataChunkSeen = true;
    } else if ("fact".equals(id)) {
      chunk = new FactChunk(this, chunkh, _dstream);
      factChunkSeen = true;
      // Are multiple 'fact' chunks allowed?
    } else if ("note".equals(id)) {
      chunk = new NoteChunk(this, chunkh, _dstream);
      // Multiple note chunks are allowed
    } else if ("labl".equals(id)) {
      chunk = new LabelChunk(this, chunkh, _dstream);
      // Multiple label chunks are allowed
    } else if ("list".equals(id)) {
      chunk = new AssocDataListChunk(this, chunkh, _dstream, info);
      // Are multiple chunks allowed?  Who knows?
    } else if ("LIST".equals(id)) {
      chunk = new ListInfoChunk(this, chunkh, _dstream, info);
      // Multiple list chunks must be OK, since there can
      // be different types, e.g., an INFO list and an exif list.
    } else if ("smpl".equals(id)) {
      chunk = new SampleChunk(this, chunkh, _dstream);
      // Multiple sample chunks are allowed -- I think
    } else if ("inst".equals(id)) {
      if (instrumentChunkSeen) {
        dupChunkError(info, "Instrument");
      }
      chunk = new InstrumentChunk(this, chunkh, _dstream);
      // Only one instrument chunk is allowed
      instrumentChunkSeen = true;
    } else if ("mext".equals(id)) {
      if (mpegChunkSeen) {
        dupChunkError(info, "MPEG");
      }
      chunk = new MpegChunk(this, chunkh, _dstream);
      // I think only one MPEG chunk is allowed
      mpegChunkSeen = true;
    } else if ("cart".equals(id)) {
      if (cartChunkSeen) {
        dupChunkError(info, "Cart");
      }
      chunk = new CartChunk(this, chunkh, _dstream);
      cartChunkSeen = true;
    } else if ("bext".equals(id)) {
      if (broadcastExtChunkSeen) {
        dupChunkError(info, "Broadcast Audio Extension");
      }
      chunk = new BroadcastExtChunk(this, chunkh, _dstream);
      broadcastExtChunkSeen = true;
    } else if ("levl".equals(id)) {
      if (peakChunkSeen) {
        dupChunkError(info, "Peak Envelope");
      }
      chunk = new PeakEnvelopeChunk(this, chunkh, _dstream);
      peakChunkSeen = true;
    } else if ("link".equals(id)) {
      if (linkChunkSeen) {
        dupChunkError(info, "Link");
      }
      chunk = new LinkChunk(this, chunkh, _dstream);
      linkChunkSeen = true;
    } else if ("cue ".equals(id)) {
      if (cueChunkSeen) {
        dupChunkError(info, "Cue");
      }
      chunk = new CueChunk(this, chunkh, _dstream);
      cueChunkSeen = true;
    } else {
      info.setMessage(new InfoMessage("Chunk type '" + id + "' ignored", _nByte));
    }

    if (chunk != null) {
      if (!chunk.readChunk(info)) {
        return false;
      }
    } else {
      // Other chunk types are legal, just skip over them
      skipBytes(_dstream, chunkSize, this);
    }

    if ((chunkSize & 1) != 0) {
      // Must come out to an even byte boundary
      skipBytes(_dstream, 1, this);
      --bytesRemaining;
    }
    return true;
  }