Java Code Examples for net.querz.nbt.tag.ListTag#size()
The following examples show how to use
net.querz.nbt.tag.ListTag#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Anvil112ChunkDataProcessor.java From mcaselector with MIT License | 6 votes |
private void mergeListTagLists(CompoundTag source, CompoundTag destination, List<Range> ranges, String name) { ListTag<ListTag<?>> sourceList = withDefault(() -> source.getCompoundTag("Level").getListTag(name).asListTagList(), new ListTag<>(ListTag.class)); ListTag<ListTag<?>> destinationList = withDefault(() -> destination.getCompoundTag("Level").getListTag(name).asListTagList(), sourceList); if (sourceList.size() != destinationList.size()) { return; } for (Range range : ranges) { int m = Math.min(range.getTo(), sourceList.size() - 1); for (int i = Math.max(range.getFrom(), 0); i <= m; i++) { destinationList.set(i, sourceList.get(i)); } } initLevel(destination).put(name, destinationList); }
Example 2
Source File: DeleteSectionsField.java From mcaselector with MIT License | 6 votes |
@Override public void change(CompoundTag root) { Tag<?> rawSections = root.getCompoundTag("Level").get("Sections"); if (rawSections == null || rawSections.getID() == LongArrayTag.ID) { return; } ListTag<CompoundTag> sections = ((ListTag<?>) rawSections).asCompoundTagList(); for (int i = 0; i < sections.size(); i++) { CompoundTag section = sections.get(i); for (Range range : getNewValue()) { if (range.contains(section.getByte("Y"))) { sections.remove(i); i--; } } } }
Example 3
Source File: Anvil113ChunkDataProcessor.java From mcaselector with MIT License | 4 votes |
@Override public void drawChunk(CompoundTag root, ColorMapping colorMapping, int x, int z, int[] pixelBuffer, int[] waterPixels, byte[] terrainHeights, byte[] waterHeights, boolean water) { CompoundTag level = withDefault(() -> root.getCompoundTag("Level"), null); if (level == null) { return; } String status = withDefault(() -> level.getString("Status"), null); if (status == null || "empty".equals(status)) { return; } Tag<?> rawSections = level.get("Sections"); if (rawSections == null || rawSections.getID() == LongArrayTag.ID) { return; } ListTag<CompoundTag> sections = catchClassCastException(((ListTag<?>) rawSections)::asCompoundTagList); if (sections == null) { return; } sections.sort(this::filterSections); int[] biomes = withDefault(() -> level.getIntArray("Biomes"), null); for (int cx = 0; cx < Tile.CHUNK_SIZE; cx++) { zLoop: for (int cz = 0; cz < Tile.CHUNK_SIZE; cz++) { int biome = getBiomeAtBlock(biomes, cx, 255, cz); //loop over sections boolean waterDepth = false; for (int i = 0; i < sections.size(); i++) { final int si = i; CompoundTag section; ListTag<?> rawPalette; ListTag<CompoundTag> palette; if ((section = sections.get(si)) == null || (rawPalette = section.getListTag("Palette")) == null || (palette = rawPalette.asCompoundTagList()) == null) { continue; } long[] blockStates = withDefault(() -> sections.get(si).getLongArray("BlockStates"), null); if (blockStates == null) { continue; } Byte height = withDefault(() -> sections.get(si).getByte("Y"), null); if (height == null) { continue; } int sectionHeight = height * 16; int bits = blockStates.length / 64; int clean = ((int) Math.pow(2, bits) - 1); for (int cy = Tile.CHUNK_SIZE - 1; cy >= 0; cy--) { int paletteIndex = getPaletteIndex(getIndex(cx, cy, cz), blockStates, bits, clean); CompoundTag blockData = palette.get(paletteIndex); //ignore bedrock and netherrack until 75 if (isIgnoredInNether(biome, blockData, sectionHeight + cy)) { continue; } if (!isEmpty(paletteIndex, blockData)) { int regionIndex = (z + cz) * Tile.SIZE + (x + cx); if (water) { if (!waterDepth) { pixelBuffer[regionIndex] = colorMapping.getRGB(blockData) | 0xFF000000; // water color waterHeights[regionIndex] = (byte) (sectionHeight + cy); // height of highest water or terrain block } if (isWater(blockData)) { waterDepth = true; continue; } else { waterPixels[regionIndex] = colorMapping.getRGB(blockData) | 0xFF000000; // color of block at bottom of water } } else { pixelBuffer[regionIndex] = colorMapping.getRGB(blockData) | 0xFF000000; } terrainHeights[regionIndex] = (byte) (sectionHeight + cy); // height of bottom of water continue zLoop; } } } } } }
Example 4
Source File: Anvil112ChunkDataProcessor.java From mcaselector with MIT License | 4 votes |
@Override public void drawChunk(CompoundTag root, ColorMapping colorMapping, int x, int z, int[] pixelBuffer, int[] waterPixels, byte[] terrainHeights, byte[] waterHeights, boolean water) { ListTag<CompoundTag> sections = withDefault(() -> root.getCompoundTag("Level").getListTag("Sections").asCompoundTagList(), null); if (sections == null) { return; } sections.sort(this::filterSections); //loop over x / z for (int cx = 0; cx < Tile.CHUNK_SIZE; cx++) { zLoop: for (int cz = 0; cz < Tile.CHUNK_SIZE; cz++) { byte[] biomes = withDefault(() -> root.getCompoundTag("Level").getByteArray("Biomes"), null); int biome = -1; if (biomes != null && biomes.length != 0) { biome = biomes[getBlockIndex(cx, 0, cz)]; } boolean waterDepth = false; //loop over sections for (int i = 0; i < sections.size(); i++) { final int si = i; byte[] blocks = withDefault(() -> sections.get(si).getByteArray("Blocks"), null); if (blocks == null) { continue; } byte[] data = withDefault(() -> sections.get(si).getByteArray("Data"), null); if (data == null) { continue; } Byte height = withDefault(() -> sections.get(si).getByte("Y"), null); if (height == null) { continue; } int sectionHeight = height * 16; //loop over y value in section from top to bottom for (int cy = Tile.CHUNK_SIZE - 1; cy >= 0; cy--) { int index = getBlockIndex(cx, cy, cz); short block = (short) (blocks[index] & 0xFF); //ignore bedrock and netherrack until 75 if (isIgnoredInNether(biome, block, sectionHeight + cy)) { continue; } byte blockData = (byte) (index % 2 == 0 ? data[index / 2] & 0x0F : (data[index / 2] >> 4) & 0x0F); if (!isEmpty(block)) { int regionIndex = (z + cz) * Tile.SIZE + (x + cx); if (water) { if (!waterDepth) { pixelBuffer[regionIndex] = colorMapping.getRGB(((block << 4) + blockData)) | 0xFF000000; waterHeights[regionIndex] = (byte) (sectionHeight + cy); } if (isWater(block)) { waterDepth = true; continue; } else { waterPixels[regionIndex] = colorMapping.getRGB(((block << 4) + blockData)) | 0xFF000000; } } else { pixelBuffer[regionIndex] = colorMapping.getRGB(((block << 4) + blockData)) | 0xFF000000; } terrainHeights[regionIndex] = (byte) (sectionHeight + cy); continue zLoop; } } } } } }
Example 5
Source File: MCAChunkData.java From mcaselector with MIT License | 4 votes |
private void applyOffsetToIntListPos(ListTag<IntTag> pos, Point2i offset) { if (pos != null && pos.size() == 3) { pos.set(0, new IntTag(pos.get(0).asInt() + offset.getX())); pos.set(2, new IntTag(pos.get(2).asInt() + offset.getY())); } }