Java Code Examples for net.querz.nbt.tag.CompoundTag#containsKey()
The following examples show how to use
net.querz.nbt.tag.CompoundTag#containsKey() .
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: Anvil115ChunkDataProcessor.java From mcaselector with MIT License | 6 votes |
@Override protected void fixEntityUUID(CompoundTag entity) { if (entity.containsKey("UUID")) { int[] uuid = entity.getIntArray("UUID"); if (uuid.length == 4) { for (int i = 0; i < 4; i++) { uuid[i] = random.nextInt(); } } } if (entity.containsKey("Passengers")) { ListTag<CompoundTag> passengers = withDefault(() -> entity.getListTag("Passengers").asCompoundTagList(), null); if (passengers != null) { passengers.forEach(this::fixEntityUUID); } } }
Example 2
Source File: Anvil113ChunkFilter.java From mcaselector with MIT License | 6 votes |
@Override public boolean matchBiomeIDs(CompoundTag data, int... ids) { if (!data.containsKey("Level") || withDefault(() -> data.getCompoundTag("Level").getIntArrayTag("Biomes"), null) == null) { return false; } filterLoop: for (int filterID : ids) { for (int dataID : data.getCompoundTag("Level").getIntArray("Biomes")) { if (filterID == dataID) { continue filterLoop; } } return false; } return true; }
Example 3
Source File: Anvil113ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public void changeBiome(CompoundTag data, int id) { if (!data.containsKey("Level") || withDefault(() -> data.getCompoundTag("Level").getIntArrayTag("Biomes"), null) == null) { return; } Arrays.fill(data.getCompoundTag("Level").getIntArray("Biomes"), id); }
Example 4
Source File: Anvil113ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public void forceBiome(CompoundTag data, int id) { if (data.containsKey("Level")) { int[] biomes = new int[256]; Arrays.fill(biomes, id); data.getCompoundTag("Level").putIntArray("Biomes", biomes); } }
Example 5
Source File: Anvil112ChunkDataProcessor.java From mcaselector with MIT License | 5 votes |
protected void fixEntityUUID(CompoundTag entity) { if (entity.containsKey("UUIDMost")) { entity.putLong("UUIDMost", random.nextLong()); } if (entity.containsKey("UUIDLeast")) { entity.putLong("UUIDLeast", random.nextLong()); } if (entity.containsKey("Passengers")) { ListTag<CompoundTag> passengers = withDefault(() -> entity.getListTag("Passengers").asCompoundTagList(), null); if (passengers != null) { passengers.forEach(this::fixEntityUUID); } } }
Example 6
Source File: Anvil112ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public boolean matchBiomeIDs(CompoundTag data, int... ids) { if (!data.containsKey("Level") || withDefault(() -> data.getCompoundTag("Level").getByteArray("Biomes"), null) == null) { return false; } filterLoop: for (int filterID : ids) { for (byte dataID : data.getCompoundTag("Level").getByteArray("Biomes")) { if (filterID == dataID) { continue filterLoop; } } return false; } return true; }
Example 7
Source File: Anvil112ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public void changeBiome(CompoundTag data, int id) { if (!data.containsKey("Level") || withDefault(() -> data.getCompoundTag("Level").getByteArray("Biomes"), null) == null) { return; } Arrays.fill(data.getCompoundTag("Level").getByteArray("Biomes"), (byte) id); }
Example 8
Source File: Anvil112ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public void forceBiome(CompoundTag data, int id) { if (data.containsKey("Level")) { byte[] biomes = new byte[256]; Arrays.fill(biomes, (byte) id); data.getCompoundTag("Level").putByteArray("Biomes", biomes); } }
Example 9
Source File: Anvil115ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public void forceBiome(CompoundTag data, int id) { if (data.containsKey("Level")) { int[] biomes = new int[1024]; Arrays.fill(biomes, id); data.getCompoundTag("Level").putIntArray("Biomes", biomes); } }
Example 10
Source File: MCAChunkData.java From mcaselector with MIT License | 5 votes |
private void applyOffsetToItem(CompoundTag item, Point2i offset) { if (item != null) { String id = catchClassCastException(() -> item.getString("id")); CompoundTag tag = catchClassCastException(() -> item.getCompoundTag("tag")); if (id != null && tag != null) { // using a switch-case here for the future // noinspection SwitchStatementWithTooFewBranches switch (id) { case "minecraft:compass": CompoundTag lodestonePos = catchClassCastException(() -> tag.getCompoundTag("LodestonePos")); applyIntOffsetIfRootPresent(lodestonePos, "X", "Z", offset); break; } // recursively update all items in child containers CompoundTag blockEntityTag = catchClassCastException(() -> tag.getCompoundTag("BlockEntityTag")); if (blockEntityTag != null) { if (blockEntityTag.containsKey("Items")) { ListTag<CompoundTag> items = catchClassCastException(() -> blockEntityTag.getListTag("Items").asCompoundTagList()); if (items != null) { items.forEach(i -> applyOffsetToItem(i, offset)); } } } } } }
Example 11
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 4 votes |
private static boolean hasPlayerTag(CompoundTag dataTag) { return dataTag.containsKey(NBTTagKeys.TAG_KEY_PLAYER); }
Example 12
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 4 votes |
private static boolean hasGeneratorName(CompoundTag dataTag) { return dataTag.containsKey(NBTTagKeys.TAG_KEY_GENERATOR_NAME); }
Example 13
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 4 votes |
private static boolean hasPlayerTag(CompoundTag dataTag) { return dataTag.containsKey(NBTTagKeys.TAG_KEY_PLAYER); }
Example 14
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 4 votes |
private static boolean hasGeneratorName(CompoundTag dataTag) { return dataTag.containsKey(NBTTagKeys.TAG_KEY_GENERATOR_NAME); }
Example 15
Source File: Chunk.java From NBT with MIT License | 4 votes |
private void initReferences(long loadFlags) { if (data == null) { throw new NullPointerException("data cannot be null"); } CompoundTag level; if ((level = data.getCompoundTag("Level")) == null) { throw new IllegalArgumentException("data does not contain \"Level\" tag"); } dataVersion = data.getInt("DataVersion"); inhabitedTime = level.getLong("InhabitedTime"); lastUpdate = level.getLong("LastUpdate"); if ((loadFlags & BIOMES) != 0) { biomes = level.getIntArray("Biomes"); } if ((loadFlags & HEIGHTMAPS) != 0) { heightMaps = level.getCompoundTag("Heightmaps"); } if ((loadFlags & CARVING_MASKS) != 0) { carvingMasks = level.getCompoundTag("CarvingMasks"); } if ((loadFlags & ENTITIES) != 0) { entities = level.containsKey("Entities") ? level.getListTag("Entities").asCompoundTagList() : null; } if ((loadFlags & TILE_ENTITIES) != 0) { tileEntities = level.containsKey("TileEntities") ? level.getListTag("TileEntities").asCompoundTagList() : null; } if ((loadFlags & TILE_TICKS) != 0) { tileTicks = level.containsKey("TileTicks") ? level.getListTag("TileTicks").asCompoundTagList() : null; } if ((loadFlags & LIQUID_TICKS) != 0) { liquidTicks = level.containsKey("LiquidTicks") ? level.getListTag("LiquidTicks").asCompoundTagList() : null; } if ((loadFlags & LIGHTS) != 0) { lights = level.containsKey("Lights") ? level.getListTag("Lights").asListTagList() : null; } if ((loadFlags & LIQUIDS_TO_BE_TICKED) != 0) { liquidsToBeTicked = level.containsKey("LiquidsToBeTicked") ? level.getListTag("LiquidsToBeTicked").asListTagList() : null; } if ((loadFlags & TO_BE_TICKED) != 0) { toBeTicked = level.containsKey("ToBeTicked") ? level.getListTag("ToBeTicked").asListTagList() : null; } if ((loadFlags & POST_PROCESSING) != 0) { postProcessing = level.containsKey("PostProcessing") ? level.getListTag("PostProcessing").asListTagList() : null; } status = level.getString("Status"); if ((loadFlags & STRUCTURES) != 0) { structures = level.getCompoundTag("Structures"); } if ((loadFlags & (BLOCK_LIGHTS|BLOCK_STATES|SKY_LIGHT)) != 0 && level.containsKey("Sections")) { for (CompoundTag section : level.getListTag("Sections").asCompoundTagList()) { int sectionIndex = section.getByte("Y"); if (sectionIndex > 15 || sectionIndex < 0) { continue; } Section newSection = new Section(section, dataVersion, loadFlags); if (newSection.isEmpty()) { continue; } sections[sectionIndex] = newSection; } } // If we haven't requested the full set of data we can drop the underlying raw data to let the GC handle it. if (loadFlags != ALL_DATA) { data = null; partial = true; } else { partial = false; } }
Example 16
Source File: MCAChunkData.java From mcaselector with MIT License | 4 votes |
private void applyIntIfPresent(CompoundTag root, String key, int offset) { Integer value; if (root.containsKey(key) && (value = catchClassCastException(() -> root.getInt(key))) != null) { root.putInt(key, value + offset); } }
Example 17
Source File: MCAChunkData.java From mcaselector with MIT License | 4 votes |
private void applyOffsetToTileEntity(CompoundTag tileEntity, Point2i offset) { if (tileEntity == null) { return; } applyIntIfPresent(tileEntity, "x", offset.getX()); applyIntIfPresent(tileEntity, "z", offset.getY()); String id = catchClassCastException(() -> tileEntity.getString("id")); if (id != null) { switch (id) { case "minecraft:bee_nest": case "minecraft:beehive": CompoundTag flowerPos = catchClassCastException(() -> tileEntity.getCompoundTag("FlowerPos")); applyIntOffsetIfRootPresent(flowerPos, "X", "Z", offset); if (tileEntity.containsKey("Bees")) { ListTag<CompoundTag> bees = catchClassCastException(() -> tileEntity.getListTag("Bees").asCompoundTagList()); if (bees != null) { for (CompoundTag bee : bees) { if (bee.containsKey("EntityData")) { applyOffsetToEntity(catchClassCastException(() -> bee.getCompoundTag("EntityData")), offset); } } } } break; case "minecraft:end_gateway": CompoundTag exitPortal = catchClassCastException(() -> tileEntity.getCompoundTag("ExitPortal")); applyIntOffsetIfRootPresent(exitPortal, "X", "Z", offset); break; case "minecraft:structure_block": applyIntIfPresent(tileEntity, "posX", offset.getX()); applyIntIfPresent(tileEntity, "posX", offset.getY()); break; case "minecraft:jukebox": CompoundTag recordItem = catchClassCastException(() -> tileEntity.getCompoundTag("RecordItem")); applyOffsetToItem(recordItem, offset); break; case "minecraft:lectern": CompoundTag book = catchClassCastException(() -> tileEntity.getCompoundTag("Book")); applyOffsetToItem(book, offset); break; case "minecraft:mob_spawner": if (tileEntity.containsKey("SpawnPotentials")) { ListTag<CompoundTag> spawnPotentials = catchClassCastException(() -> tileEntity.getListTag("SpawnPotentials").asCompoundTagList()); if (spawnPotentials != null) { for (CompoundTag spawnPotential : spawnPotentials) { CompoundTag entity = catchClassCastException(() -> spawnPotential.getCompoundTag("Entity")); if (entity != null) { applyOffsetToEntity(entity, offset); } } } } } } if (tileEntity.containsKey("Items")) { ListTag<CompoundTag> items = catchClassCastException(() -> tileEntity.getListTag("Items").asCompoundTagList()); if (items != null) { items.forEach(i -> applyOffsetToItem(i, offset)); } } }
Example 18
Source File: MCAChunkData.java From mcaselector with MIT License | 4 votes |
public boolean relocate(Point2i offset) { if (data == null || !data.containsKey("Level")) { return false; } CompoundTag level = catchClassCastException(() -> data.getCompoundTag("Level")); if (level == null) { return true; } // adjust or set chunk position level.putInt("xPos", level.getInt("xPos") + offset.blockToChunk().getX()); level.putInt("zPos", level.getInt("zPos") + offset.blockToChunk().getY()); // adjust entity positions if (level.containsKey("Entities")) { ListTag<CompoundTag> entities = catchClassCastException(() -> level.getListTag("Entities").asCompoundTagList()); if (entities != null) { entities.forEach(v -> applyOffsetToEntity(v, offset)); } } // adjust tile entity positions if (level.containsKey("TileEntities")) { ListTag<CompoundTag> tileEntities = catchClassCastException(() -> level.getListTag("TileEntities").asCompoundTagList()); if (tileEntities != null) { tileEntities.forEach(v -> applyOffsetToTileEntity(v, offset)); } } // adjust tile ticks if (level.containsKey("TileTicks")) { ListTag<CompoundTag> tileTicks = catchClassCastException(() -> level.getListTag("TileTicks").asCompoundTagList()); if (tileTicks != null) { tileTicks.forEach(v -> applyOffsetToTick(v, offset)); } } // adjust liquid ticks if (level.containsKey("LiquidTicks")) { ListTag<CompoundTag> liquidTicks = catchClassCastException(() -> level.getListTag("LiquidTicks").asCompoundTagList()); if (liquidTicks != null) { liquidTicks.forEach(v -> applyOffsetToTick(v, offset)); } } // adjust structures if (level.containsKey("Structures")) { CompoundTag structures = catchClassCastException(() -> level.getCompoundTag("Structures")); if (structures != null) { applyOffsetToStructures(structures, offset); } } return true; }