Java Code Examples for net.querz.nbt.tag.ListTag#get()

The following examples show how to use net.querz.nbt.tag.ListTag#get() . 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: DeleteSectionsField.java    From mcaselector with MIT License 6 votes vote down vote up
@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 2
Source File: Anvil113ChunkDataProcessor.java    From mcaselector with MIT License 4 votes vote down vote up
@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;
					}
				}
			}
		}
	}
}