示例#1
0
  private void populateMCChunk(Chunk chunk, int dx, int dy, int dz) {
    if (chunk.isPopulated()) {
      return;
    }
    int chunkX = (chunk.getX() - shiftX + dx) >> 4;
    int chunkZ = (chunk.getZ() - shiftX + dz) >> 4;

    DataInputStream inputStream = RegionFileCache.getChunkDataInputStream(file, chunkX, chunkZ);
    if (inputStream != null) {
      try {
        NBTInputStream nbt = new NBTInputStream(inputStream);
        CompoundTag root = (CompoundTag) nbt.readTag();
        CompoundTag level = (CompoundTag) root.getValue().get("Level");
        ByteArrayTag blocks = (ByteArrayTag) level.getValue().get("Blocks");

        int maxY = dy + OctreeNode.CHUNK_SIZE;
        if (maxY > 128) maxY = 128;
        byte[] data = blocks.getValue();
        for (int x = 0; x < SIZE_X; x++) {
          for (int y = dy; y < maxY; y++) {
            for (int z = 0; z < SIZE_Z; z++) {
              int i = y + (z * SIZE_Y) + x * SIZE_Y * SIZE_Z;
              if (data[i] != 0) {
                chunk.setPixel(chunk.getX() + dx + x, y, chunk.getZ() + dz + z, data[i]);
              }
            }
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
示例#2
0
  public ChunkImpl(CompoundTag tag, int maxHeight, boolean readOnly) {
    super((CompoundTag) tag.getTag(TAG_LEVEL));
    this.maxHeight = maxHeight;
    this.readOnly = readOnly;

    blocks = getByteArray(TAG_BLOCKS);
    data = getByteArray(TAG_DATA);
    skyLight = getByteArray(TAG_SKY_LIGHT);
    blockLight = getByteArray(TAG_BLOCK_LIGHT);
    heightMap = getByteArray(TAG_HEIGHT_MAP);
    List<CompoundTag> entityTags = getList(TAG_ENTITIES);
    entities = new ArrayList<>(entityTags.size());
    entities.addAll(entityTags.stream().map(Entity::fromNBT).collect(toList()));
    List<CompoundTag> tileEntityTags = getList(TAG_TILE_ENTITIES);
    tileEntities = new ArrayList<>(tileEntityTags.size());
    tileEntities.addAll(tileEntityTags.stream().map(TileEntity::fromNBT).collect(toList()));
    // TODO: last update is ignored, is that correct?
    xPos = getInt(TAG_X_POS);
    zPos = getInt(TAG_Z_POS);
    terrainPopulated = getBoolean(TAG_TERRAIN_POPULATED);
  }
  /**
   * Reads a WorldEdit schematic file and writes the data to a CSV file. The dimensions of the
   * schematics are also stored for use by the room builder.
   *
   * @param fileStr the schematic file to read
   * @param s the schematic name
   * @param rotate whether to rotate the schematic 90 degrees counter-clockwise
   * @return true or false depending on whether the room is square or not
   */
  public boolean readAndMakeRoomCSV(String fileStr, String s, boolean rotate) {
    HashMap<String, Integer> blockIDs = new HashMap<String, Integer>();
    boolean square = true;
    plugin.debug("Loading schematic: " + fileStr + ".schematic");
    FileInputStream fis = null;
    try {
      File f = new File(fileStr + ".schematic");
      fis = new FileInputStream(f);
      NBTInputStream nbt = new NBTInputStream(fis);
      CompoundTag backuptag = (CompoundTag) nbt.readTag();
      Map<String, Tag> tagCollection = backuptag.getValue();

      short width = (Short) getChildTag(tagCollection, "Width", ShortTag.class).getValue();
      short height = (Short) getChildTag(tagCollection, "Height", ShortTag.class).getValue();
      short length = (Short) getChildTag(tagCollection, "Length", ShortTag.class).getValue();

      // check the room is square - should never fail on plugin enable as schematics are checked
      // when added
      if (width != length) {
        plugin.console.sendMessage(
            plugin.pluginName + "Load failed - schematic had unequal length sides!");
        square = false;
      } else {
        short[] dimensions = new short[3];
        dimensions[0] = height;
        dimensions[1] = width;
        dimensions[2] = length;
        plugin.room_dimensions.put(s, dimensions);

        byte[] blocks =
            (byte[]) getChildTag(tagCollection, "Blocks", ByteArrayTag.class).getValue();
        byte[] data = (byte[]) getChildTag(tagCollection, "Data", ByteArrayTag.class).getValue();

        nbt.close();
        fis.close();
        int i = 0;
        String[] blockdata = new String[width * height * length];
        int adjust = 256;
        for (byte b : blocks) {
          if (!ignoreBlocks.contains(b)) {
            Integer bid = (b < (byte) 0) ? b + adjust : b;
            if (blockConversion.containsKey(bid)) {
              bid = blockConversion.get(bid);
            }
            if (bid == 35 && (data[i] == 1 || data[i] == 8)) {
              String bstr = bid + ":" + data[i];
              if (blockIDs.containsKey(bstr)) {
                Integer count = blockIDs.get(bstr) + 1;
                blockIDs.put(bstr, count);
              } else {
                blockIDs.put(bstr, 1);
              }
            } else {
              if (blockIDs.containsKey(bid.toString())) {
                Integer count = blockIDs.get(bid.toString()) + 1;
                blockIDs.put(bid.toString(), count);
              } else {
                blockIDs.put(bid.toString(), 1);
              }
            }
          }
          blockdata[i] = b + ":" + data[i];
          i++;
        }
        plugin.roomBlockCounts.put(s, blockIDs);
        int j = 0;
        List<String[][]> layers = new ArrayList<String[][]>();
        for (int h = 0; h < height; h++) {
          String[][] strarr = new String[width][length];
          for (int w = 0; w < width; w++) {
            for (int l = 0; l < length; l++) {
              strarr[w][l] = blockdata[j];
              j++;
            }
          }
          if (rotate) {
            strarr = rotateSquareCCW(strarr);
          }
          layers.add(strarr);
        }
        try {
          String csvFile = (rotate) ? fileStr + "_EW.csv" : fileStr + ".csv";
          File file = new File(csvFile);
          BufferedWriter bw = new BufferedWriter(new FileWriter(file, false));
          for (String[][] l : layers) {
            for (String[] lines : l) {
              StringBuilder buf = new StringBuilder();
              for (String bd : lines) {
                buf.append(bd).append(",");
              }
              String commas = buf.toString();
              String strCommas = commas.substring(0, (commas.length() - 1));
              bw.write(strCommas);
              bw.newLine();
            }
          }
          bw.close();

        } catch (IOException io) {
          plugin.console.sendMessage(plugin.pluginName + "Could not save the room csv file!");
        }
      }
    } catch (IOException e) {
      plugin.console.sendMessage(plugin.pluginName + "Schematic read error: " + e);
    } finally {
      if (fis != null) {
        try {
          fis.close();
        } catch (IOException e) {
        }
      }
    }
    return square;
  }