com.nukkitx.nbt.tag.Tag Java Examples
The following examples show how to use
com.nukkitx.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: SignBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); StringBuilder signText = new StringBuilder(); for(int i = 0; i < 4; i++) { int currentLine = i+1; String signLine = getOrDefault(tag.getValue().get("Text" + currentLine), ""); signLine = MessageUtils.getBedrockMessage(Message.fromString(signLine)); //Java allows up to 16+ characters on certain symbols. if(signLine.length() >= 15 && (signLine.contains("-") || signLine.contains("="))) { signLine = signLine.substring(0, 14); } signText.append(signLine); signText.append("\n"); } tags.add(new StringTag("Text", MessageUtils.getBedrockMessage(Message.fromString(signText.toString())))); return tags; }
Example #2
Source File: StructureTemplateDataExportResponseSerializer_v361.java From Protocol with Apache License 2.0 | 6 votes |
@Override public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { packet.setName(BedrockUtils.readString(buffer)); boolean save = buffer.readBoolean(); packet.setSave(save); if (save) { try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { Tag<?> tag = reader.readTag(); if (tag instanceof CompoundTag) { packet.setTag((CompoundTag) tag); } else { throw new IllegalArgumentException("Tag received was not a CompoundTag"); } } catch (IOException e) { throw new RuntimeException(e); } } }
Example #3
Source File: StructureTemplateDataExportResponseSerializer_v388.java From Protocol with Apache License 2.0 | 6 votes |
@Override public void deserialize(ByteBuf buffer, StructureTemplateDataExportResponsePacket packet) { packet.setName(BedrockUtils.readString(buffer)); boolean save = buffer.readBoolean(); packet.setSave(save); if (save) { try (NBTInputStream reader = NbtUtils.createNetworkReader(new ByteBufInputStream(buffer))) { Tag<?> tag = reader.readTag(); if (tag instanceof CompoundTag) { packet.setTag((CompoundTag) tag); } else { throw new IllegalArgumentException("Tag received was not a CompoundTag"); } } catch (IOException e) { throw new RuntimeException(e); } } }
Example #4
Source File: BannerBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); int bannerColor = BlockStateValues.getBannerColor(blockState); if (bannerColor != -1) { tags.add(new IntTag("Base", 15 - bannerColor)); } if (tag.contains("Patterns")) { ListTag patterns = tag.get("Patterns"); tags.add(BannerTranslator.convertBannerPattern(patterns)); } if (tag.contains("CustomName")) { tags.add(new StringTag("CustomName", (String) tag.get("CustomName").getValue())); } return tags; }
Example #5
Source File: EndGatewayBlockEntityTranslator.java From Geyser with MIT License | 6 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); tags.add(new IntTag("Age", (int) (long) tag.get("Age").getValue())); // Java sometimes does not provide this tag, but Bedrock crashes if it doesn't exist // Linked coordinates List<IntTag> tagsList = new ArrayList<>(); // Yes, the axis letters are capitalized tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "X"))); tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Y"))); tagsList.add(new IntTag("", getExitPortalCoordinate(tag, "Z"))); com.nukkitx.nbt.tag.ListTag<IntTag> exitPortal = new com.nukkitx.nbt.tag.ListTag<>("ExitPortal", IntTag.class, tagsList); tags.add(exitPortal); return tags; }
Example #6
Source File: BedBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); byte bedcolor = BlockStateValues.getBedColor(blockState); // Just in case... if (bedcolor == -1) bedcolor = 0; tags.add(new ByteTag("color", bedcolor)); return tags; }
Example #7
Source File: SkullBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); byte skullVariant = BlockStateValues.getSkullVariant(blockState); float rotation = BlockStateValues.getSkullRotation(blockState) * 22.5f; // Just in case... if (skullVariant == -1) skullVariant = 0; tags.add(new FloatTag("Rotation", rotation)); tags.add(new ByteTag("SkullType", skullVariant)); return tags; }
Example #8
Source File: CampfireBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); ListTag items = tag.get("Items"); int i = 1; for (com.github.steveice10.opennbt.tag.builtin.Tag itemTag : items.getValue()) { tags.add(getItem((CompoundTag) itemTag).toBuilder().build("Item" + i)); i++; } return tags; }
Example #9
Source File: ItemTranslator.java From Geyser with MIT License | 5 votes |
public CompoundTag translateNbtToBedrock(com.github.steveice10.opennbt.tag.builtin.CompoundTag tag) { Map<String, Tag<?>> javaValue = new HashMap<>(); if (tag.getValue() != null && !tag.getValue().isEmpty()) { for (String str : tag.getValue().keySet()) { com.github.steveice10.opennbt.tag.builtin.Tag javaTag = tag.get(str); com.nukkitx.nbt.tag.Tag<?> translatedTag = translateToBedrockNBT(javaTag); if (translatedTag == null) continue; javaValue.put(translatedTag.getName(), translatedTag); } } return new CompoundTag(tag.getName(), javaValue); }
Example #10
Source File: ProxyPass.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
public void saveNBT(String dataName, Tag<?> dataTag) { Path path = dataDir.resolve(dataName + ".dat"); try (OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); NBTOutputStream nbtOutputStream = NbtUtils.createNetworkWriter(outputStream)){ nbtOutputStream.write(dataTag); } catch (IOException e) { throw new RuntimeException(e); } }
Example #11
Source File: ProxyPass.java From ProxyPass with GNU Affero General Public License v3.0 | 5 votes |
public Tag<?> loadNBT(String dataName) { Path path = dataDir.resolve(dataName + ".dat"); try (InputStream inputStream = Files.newInputStream(path); NBTInputStream nbtInputStream = NbtUtils.createNetworkReader(inputStream)){ return nbtInputStream.readTag(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #12
Source File: DoubleChestBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); if (blockState != null && BlockStateValues.getDoubleChestValues().containsKey(blockState.getId())) { DoubleChestValue chestValues = BlockStateValues.getDoubleChestValues().get(blockState.getId()); if (chestValues != null) { int x = (int) tag.getValue().get("x").getValue(); int z = (int) tag.getValue().get("z").getValue(); // Calculate the position of the other chest based on the Java block state if (chestValues.isFacingEast) { if (chestValues.isDirectionPositive) { // East z = z + (chestValues.isLeft ? 1 : -1); } else { // West z = z + (chestValues.isLeft ? -1 : 1); } } else { if (chestValues.isDirectionPositive) { // South x = x + (chestValues.isLeft ? -1 : 1); } else { // North x = x + (chestValues.isLeft ? 1 : -1); } } tags.add(new IntTag("pairx", x)); tags.add(new IntTag("pairz", z)); if (!chestValues.isLeft) { tags.add(new ByteTag("pairlead", (byte) 1)); } } } return tags; }
Example #13
Source File: ShulkerBoxBlockEntityTranslator.java From Geyser with MIT License | 5 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { List<Tag<?>> tags = new ArrayList<>(); byte direction = BlockStateValues.getShulkerBoxDirection(blockState); // Just in case... if (direction == -1) direction = 1; tags.add(new ByteTag("facing", direction)); return tags; }
Example #14
Source File: BlockEntityTranslator.java From Geyser with MIT License | 4 votes |
@SuppressWarnings("unchecked") protected <T> T getOrDefault(com.github.steveice10.opennbt.tag.builtin.Tag tag, T defaultValue) { return (tag != null && tag.getValue() != null) ? (T) tag.getValue() : defaultValue; }
Example #15
Source File: EmptyBlockEntityTranslator.java From Geyser with MIT License | 4 votes |
@Override public List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState) { return new ArrayList<>(); }
Example #16
Source File: ItemTranslator.java From Geyser with MIT License | 4 votes |
private Tag<?> translateToBedrockNBT(com.github.steveice10.opennbt.tag.builtin.Tag tag) { if (tag instanceof ByteArrayTag) { ByteArrayTag byteArrayTag = (ByteArrayTag) tag; return new com.nukkitx.nbt.tag.ByteArrayTag(byteArrayTag.getName(), byteArrayTag.getValue()); } if (tag instanceof ByteTag) { ByteTag byteTag = (ByteTag) tag; return new com.nukkitx.nbt.tag.ByteTag(byteTag.getName(), byteTag.getValue()); } if (tag instanceof DoubleTag) { DoubleTag doubleTag = (DoubleTag) tag; return new com.nukkitx.nbt.tag.DoubleTag(doubleTag.getName(), doubleTag.getValue()); } if (tag instanceof FloatTag) { FloatTag floatTag = (FloatTag) tag; return new com.nukkitx.nbt.tag.FloatTag(floatTag.getName(), floatTag.getValue()); } if (tag instanceof IntArrayTag) { IntArrayTag intArrayTag = (IntArrayTag) tag; return new com.nukkitx.nbt.tag.IntArrayTag(intArrayTag.getName(), intArrayTag.getValue()); } if (tag instanceof IntTag) { IntTag intTag = (IntTag) tag; return new com.nukkitx.nbt.tag.IntTag(intTag.getName(), intTag.getValue()); } if (tag instanceof LongArrayTag) { LongArrayTag longArrayTag = (LongArrayTag) tag; return new com.nukkitx.nbt.tag.LongArrayTag(longArrayTag.getName(), longArrayTag.getValue()); } if (tag instanceof LongTag) { LongTag longTag = (LongTag) tag; return new com.nukkitx.nbt.tag.LongTag(longTag.getName(), longTag.getValue()); } if (tag instanceof ShortTag) { ShortTag shortTag = (ShortTag) tag; return new com.nukkitx.nbt.tag.ShortTag(shortTag.getName(), shortTag.getValue()); } if (tag instanceof StringTag) { StringTag stringTag = (StringTag) tag; return new com.nukkitx.nbt.tag.StringTag(stringTag.getName(), stringTag.getValue()); } if (tag instanceof ListTag) { ListTag listTag = (ListTag) tag; List<Tag<?>> tagList = new ArrayList<>(); for (com.github.steveice10.opennbt.tag.builtin.Tag value : listTag) { tagList.add(translateToBedrockNBT(value)); } Class<?> clazz = CompoundTag.class; if (!tagList.isEmpty()) { clazz = tagList.get(0).getClass(); } return new com.nukkitx.nbt.tag.ListTag(listTag.getName(), clazz, tagList); } if (tag instanceof com.github.steveice10.opennbt.tag.builtin.CompoundTag) { com.github.steveice10.opennbt.tag.builtin.CompoundTag compoundTag = (com.github.steveice10.opennbt.tag.builtin.CompoundTag) tag; return translateNbtToBedrock(compoundTag); } return null; }
Example #17
Source File: BlockEntityTranslator.java From Geyser with MIT License | votes |
public abstract List<Tag<?>> translateTag(CompoundTag tag, BlockState blockState);