net.querz.nbt.tag.Tag Java Examples
The following examples show how to use
net.querz.nbt.tag.Tag.
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: Anvil113ColorMapping.java From mcaselector with MIT License | 6 votes |
public int getColor(CompoundTag properties) { if (properties != null) { for (Map.Entry<String, Tag<?>> property : properties.entrySet()) { Map<Set<String>, Integer> clone = new HashMap<>(blockStateMapping); for (Map.Entry<Set<String>, Integer> blockState : blockStateMapping.entrySet()) { String value = property.getKey() + "=" + ((StringTag) property.getValue()).getValue(); if (!blockState.getKey().contains(value)) { clone.remove(blockState.getKey()); } } Iterator<Map.Entry<Set<String>, Integer>> it = clone.entrySet().iterator(); if (it.hasNext()) { return it.next().getValue(); } } } return 0x000000; }
Example #2
Source File: EntityFilter.java From mcaselector with MIT License | 6 votes |
@Override public boolean contains(List<String> value, FilterData data) { Tag<?> rawEntities = data.getChunk().getCompoundTag("Level").get("Entities"); if (rawEntities == null || rawEntities.getID() == LongArrayTag.ID) { return false; } ListTag<CompoundTag> entities = ((ListTag<?>) rawEntities).asCompoundTagList(); nameLoop: for (String name : getFilterValue()) { for (CompoundTag entity : entities) { String id = entity.getString("id"); if (name.equals(id)) { continue nameLoop; } } return false; } return true; }
Example #3
Source File: NBTTestCase.java From NBT with MIT License | 6 votes |
@SuppressWarnings("unchecked") protected <T> T invokeGetValue(Tag<T> tag) { try { Class<?> c = tag.getClass(); Method m; while (c != Object.class) { try { m = c.getDeclaredMethod("getValue"); m.setAccessible(true); return (T) m.invoke(tag); } catch (NoSuchMethodException ex) { c = c.getSuperclass(); } } } catch (IllegalAccessException | InvocationTargetException e) { fail("unable to invoke getValue() on " + tag.getClass().getSimpleName()); } fail("could not find getValue()"); return null; }
Example #4
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 #5
Source File: NBTTestCase.java From NBT with MIT License | 6 votes |
protected <T> void invokeSetValue(Tag<T> tag, T value) { try { Class<?> c = tag.getClass(); Method m; while (c != Object.class) { try { m = c.getDeclaredMethod("setValue", Object.class); m.setAccessible(true); m.invoke(tag, value); return; } catch (NoSuchMethodException ex) { c = c.getSuperclass(); } } } catch (IllegalAccessException | InvocationTargetException e) { fail("unable to invoke setValue() on " + tag.getClass().getSimpleName()); } fail("could not find setValue()"); }
Example #6
Source File: ReferenceField.java From mcaselector with MIT License | 6 votes |
@Override public void change(CompoundTag root) { if (!getNewValue()) { return; } // attempt to fix chunk coordinates of structure references CompoundTag references = root.getCompoundTag("Level").getCompoundTag("Structures").getCompoundTag("References"); int xPos = root.getCompoundTag("Level").getInt("xPos"); int zPos = root.getCompoundTag("Level").getInt("zPos"); for (Map.Entry<String, Tag<?>> entry : references) { if (entry.getValue() instanceof LongArrayTag) { long[] structureReferences = ((LongArrayTag) entry.getValue()).getValue(); for (int i = 0; i < structureReferences.length; i++) { int x = (int) (structureReferences[i]); int z = (int) (structureReferences[i] >> 32); if (Math.abs(x - xPos) > 8 || Math.abs(z - zPos) > 8) { structureReferences[i] = ((long) zPos & 0xFFFFFFFFL) << 32 | (long) xPos & 0xFFFFFFFFL; } } } } }
Example #7
Source File: SNBTParser.java From NBT with MIT License | 6 votes |
private ListTag<?> parseListTag(int maxDepth) throws ParseException { ptr.expectChar('['); ptr.skipWhitespace(); ListTag<?> list = ListTag.createUnchecked(EndTag.class); while (ptr.currentChar() != ']') { Tag<?> element = parseAnything(decrementMaxDepth(maxDepth)); try { list.addUnchecked(element); } catch (IllegalArgumentException ex) { throw ptr.parseException(ex.getMessage()); } if (!ptr.nextArrayElement()) { break; } } ptr.expectChar(']'); return list; }
Example #8
Source File: NBTOutputStream.java From NBT with MIT License | 5 votes |
private static void writeList(NBTOutputStream out, Tag<?> tag, int maxDepth) throws IOException { out.writeByte(idFromClass(((ListTag<?>) tag).getTypeClass())); out.writeInt(((ListTag<?>) tag).size()); for (Tag<?> t : ((ListTag<?>) tag)) { out.writeRawTag(t, out.decrementMaxDepth(maxDepth)); } }
Example #9
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 5 votes |
private static long readRandomSeed(CompoundTag dataTag) { Tag<?> randomSeed = dataTag.get(NBTTagKeys.TAG_KEY_RANDOM_SEED); if (randomSeed != null) { return NBTUtils.getLongValue(randomSeed); } // Minecraft 1.16 format CompoundTag worldGenSettings = dataTag.get(NBTTagKeys.TAG_KEY_WORLD_GEN_SETTINGS, CompoundTag.class); return NBTUtils.getLongValue(worldGenSettings.get(NBTTagKeys.TAG_KEY_SEED)); }
Example #10
Source File: NBTOutputStream.java From NBT with MIT License | 5 votes |
private static void writeCompound(NBTOutputStream out, Tag<?> tag, int maxDepth) throws IOException { for (Map.Entry<String, Tag<?>> entry : (CompoundTag) tag) { if (entry.getValue().getID() == 0) { throw new IOException("end tag not allowed"); } out.writeByte(entry.getValue().getID()); out.writeUTF(entry.getKey()); out.writeRawTag(entry.getValue(), out.decrementMaxDepth(maxDepth)); } out.writeByte(0); }
Example #11
Source File: NBTSerializer.java From NBT with MIT License | 5 votes |
@Override public void toStream(NamedTag object, OutputStream out) throws IOException { NBTOutputStream nbtOut; if (compressed) { nbtOut = new NBTOutputStream(new GZIPOutputStream(out, true)); } else { nbtOut = new NBTOutputStream(out); } nbtOut.writeTag(object, Tag.DEFAULT_MAX_DEPTH); nbtOut.flush(); }
Example #12
Source File: NBTDeserializer.java From NBT with MIT License | 5 votes |
@Override public NamedTag fromStream(InputStream stream) throws IOException { NBTInputStream nbtIn; if (compressed) { nbtIn = new NBTInputStream(new GZIPInputStream(stream)); } else { nbtIn = new NBTInputStream(stream); } return nbtIn.readTag(Tag.DEFAULT_MAX_DEPTH); }
Example #13
Source File: SNBTParser.java From NBT with MIT License | 5 votes |
public static Tag<?> parse(String string, int maxDepth) throws ParseException { SNBTParser parser = new SNBTParser(string); Tag<?> tag = parser.parseAnything(maxDepth); parser.ptr.skipWhitespace(); if (parser.ptr.hasNext()) { throw parser.ptr.parseException("invalid characters after end of snbt"); } return tag; }
Example #14
Source File: SNBTParser.java From NBT with MIT License | 5 votes |
private Tag<?> parseAnything(int maxDepth) throws ParseException { ptr.skipWhitespace(); switch (ptr.currentChar()) { case '{': return parseCompoundTag(maxDepth); case '[': if (ptr.hasCharsLeft(2) && ptr.lookAhead(1) != '"' && ptr.lookAhead(2) == ';') { return parseNumArray(); } return parseListTag(maxDepth); } return parseStringOrLiteral(); }
Example #15
Source File: NBTInputStream.java From NBT with MIT License | 5 votes |
private Tag<?> readTag(byte type, int maxDepth) throws IOException { ExceptionBiFunction<NBTInputStream, Integer, ? extends Tag<?>, IOException> f; if ((f = readers.get(type)) == null) { throw new IOException("invalid tag id \"" + type + "\""); } return f.accept(this, maxDepth); }
Example #16
Source File: NBTInputStream.java From NBT with MIT License | 5 votes |
private static CompoundTag readCompound(NBTInputStream in, int maxDepth) throws IOException { CompoundTag comp = new CompoundTag(); for (int id = in.readByte() & 0xFF; id != 0; id = in.readByte() & 0xFF) { String key = in.readUTF(); Tag<?> element = in.readTag((byte) id, in.decrementMaxDepth(maxDepth)); comp.put(key, element); } return comp; }
Example #17
Source File: NBTTestCase.java From NBT with MIT License | 5 votes |
protected byte[] serialize(Tag<?> tag) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (DataOutputStream dos = new DataOutputStream(baos)) { new NBTSerializer(false).toStream(new NamedTag(null, tag), dos); } catch (IOException ex) { ex.printStackTrace(); fail(ex.getMessage()); } return baos.toByteArray(); }
Example #18
Source File: NBTTestCase.java From NBT with MIT License | 5 votes |
protected Tag<?> deserialize(byte[] data) { try (DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data))) { return new NBTDeserializer(false).fromStream(dis).getTag(); } catch (IOException ex) { ex.printStackTrace(); fail(ex.getMessage()); return null; } }
Example #19
Source File: NBTTestCase.java From NBT with MIT License | 5 votes |
protected Tag<?> deserializeFromFile(String f) { try (DataInputStream dis = new DataInputStream(new FileInputStream(getResourceFile(f)))) { return new NBTDeserializer(false).fromStream(dis).getTag(); } catch (IOException ex) { ex.printStackTrace(); fail(ex.getMessage()); return null; } }
Example #20
Source File: LevelDatNbt.java From amidst with GNU General Public License v3.0 | 5 votes |
private static long readRandomSeed(CompoundTag dataTag) { Tag<?> randomSeed = dataTag.get(NBTTagKeys.TAG_KEY_RANDOM_SEED); if (randomSeed != null) { return NBTUtils.getLongValue(randomSeed); } // Minecraft 1.16 format CompoundTag worldGenSettings = dataTag.get(NBTTagKeys.TAG_KEY_WORLD_GEN_SETTINGS, CompoundTag.class); return NBTUtils.getLongValue(worldGenSettings.get(NBTTagKeys.TAG_KEY_SEED)); }
Example #21
Source File: Anvil113ChunkFilter.java From mcaselector with MIT License | 5 votes |
@Override public boolean matchBlockNames(CompoundTag data, String... names) { CompoundTag level = withDefault(() -> data.getCompoundTag("Level"), null); if (level == null) { return false; } Tag<?> rawSections = level.get("Sections"); if (rawSections == null || rawSections.getID() == LongArrayTag.ID) { return false; } ListTag<CompoundTag> sections = catchClassCastException(((ListTag<?>) rawSections)::asCompoundTagList); if (sections == null) { return false; } int c = 0; nameLoop: for (String name : names) { for (CompoundTag t : sections) { ListTag<?> rawPalette = withDefault(() -> t.getListTag("Palette"), null); if (rawPalette == null) { continue; } ListTag<CompoundTag> palette = catchClassCastException(rawPalette::asCompoundTagList); if (palette == null) { continue; } for (CompoundTag p : palette) { if (("minecraft:" + name).equals(withDefault(() -> p.getString("Name"), null))) { c++; continue nameLoop; } } } } return names.length == c; }
Example #22
Source File: EntityAmountFilter.java From mcaselector with MIT License | 5 votes |
@Override protected Integer getNumber(FilterData data) { Tag<?> rawEntities = data.getChunk().getCompoundTag("Level").get("Entities"); if (rawEntities == null || rawEntities.getID() == LongArrayTag.ID) { return 0; } return ((ListTag<?>) rawEntities).asCompoundTagList().size(); }
Example #23
Source File: TileEntityAmountFilter.java From mcaselector with MIT License | 5 votes |
@Override protected Integer getNumber(FilterData data) { Tag<?> rawTileEntities = data.getChunk().getCompoundTag("Level").get("TileEntities"); if (rawTileEntities == null || rawTileEntities.getID() == LongArrayTag.ID) { return 0; } return ((ListTag<?>) rawTileEntities).asCompoundTagList().size(); }
Example #24
Source File: DeleteEntitiesField.java From mcaselector with MIT License | 5 votes |
@Override public void change(CompoundTag root) { Tag<?> rawEntities = root.getCompoundTag("Level").get("Entities"); if (rawEntities == null || rawEntities.getID() == LongArrayTag.ID) { return; } ((ListTag<?>) rawEntities).asCompoundTagList().clear(); }
Example #25
Source File: NBTOutputStream.java From NBT with MIT License | 5 votes |
public void writeRawTag(Tag<?> tag, int maxDepth) throws IOException { ExceptionTriConsumer<NBTOutputStream, Tag<?>, Integer, IOException> f; if ((f = writers.get(tag.getID())) == null) { throw new IOException("invalid tag \"" + tag.getID() + "\""); } f.accept(this, tag, maxDepth); }
Example #26
Source File: NBTOutputStream.java From NBT with MIT License | 5 votes |
public void writeTag(Tag<?> tag, int maxDepth) throws IOException { writeByte(tag.getID()); if (tag.getID() != 0) { writeUTF(""); } writeRawTag(tag, maxDepth); }
Example #27
Source File: SNBTParser.java From NBT with MIT License | 4 votes |
public static Tag<?> parse(String string) throws ParseException { return parse(string, Tag.DEFAULT_MAX_DEPTH); }
Example #28
Source File: NBTOutputStream.java From NBT with MIT License | 4 votes |
private static void writeShort(NBTOutputStream out, Tag<?> tag) throws IOException { out.writeShort(((ShortTag) tag).asShort()); }
Example #29
Source File: NBTOutputStream.java From NBT with MIT License | 4 votes |
private static void writeByte(NBTOutputStream out, Tag<?> tag) throws IOException { out.writeByte(((ByteTag) tag).asByte()); }
Example #30
Source File: SNBTWriter.java From NBT with MIT License | 4 votes |
public static void write(Tag<?> tag, Writer writer, int maxDepth) throws IOException { new SNBTWriter(writer).writeAnything(tag, maxDepth); }