Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add 1.21.1 support #7

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,34 @@ plugins {
}

group = "io.masel"
version = "1.5.0"
version = "2.0.0"

labyMod {
defaultPackageName = "io.masel.nbtviewer"
addonInfo {
namespace = "nbt-viewer"
displayName = "NBT Viewer"
author = "ByteException_"
description = "LabyMod addon to view item nbt data in minecraft. Enable Advanced Tooltips (F3+H), hover over an item and press SHIFT. Magic starts..."
minecraftVersion = "1.17.1<1.21"
version = System.getenv().getOrDefault("VERSION", "1.5.0")
description =
"LabyMod addon to view item nbt data in minecraft. Enable Advanced Tooltips (F3+H), hover over an item and press SHIFT. Magic starts..."
minecraftVersion = "1.17.1<1.21.1"
version = System.getenv().getOrDefault("VERSION", "2.0.0")
}

minecraft {
registerVersions(
"1.17.1",
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4",
"1.20.5",
"1.20.6",
"1.21"
"1.17.1",
"1.18.2",
"1.19.2",
"1.19.3",
"1.19.4",
"1.20.1",
"1.20.2",
"1.20.4",
"1.20.5",
"1.20.6",
"1.21",
"1.21.1"
) { version, provider ->
configureRun(provider, version)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -52,7 +52,7 @@ public String prettyPrint(DataComponentContainer components) {
private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case IntTag value -> new JsonPrimitive(value.getAsInt());
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package io.masel.nbtviewer.v1_21_1;

import com.google.gson.*;
import io.masel.nbtviewer.api.INBTApi;
import net.labymod.api.component.data.DataComponentContainer;
import net.labymod.api.component.data.DataComponentKey;
import net.labymod.api.models.Implements;
import net.minecraft.client.Minecraft;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.NumericTag;
import net.minecraft.nbt.StringTag;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

@Implements(INBTApi.class)
public class NBTApiImpl implements INBTApi {

private final Gson gson = new GsonBuilder()
.serializeNulls()
.disableHtmlEscaping()
.setPrettyPrinting()
.create();

@Override
public boolean hasAdvancedToolsTips() {
return Minecraft.getInstance().options.advancedItemTooltips;
}

@Override
public String prettyPrint(DataComponentContainer components) {
JsonObject jsonObject = new JsonObject();

List<DataComponentKey> dataComponentKeys = new ArrayList<>(components.keySet());
dataComponentKeys.sort(Comparator.comparing(DataComponentKey::name));

for (DataComponentKey dataComponentKey : dataComponentKeys) {
Object value = components.get(dataComponentKey);

if (value == null)
continue;

jsonObject.add(dataComponentKey.name(), this.parseValue(value));
}

return this.gson.toJson(jsonObject);
}

private JsonElement parseValue(@NotNull Object content) {
try {
return switch (content) {
case NumericTag value -> new JsonPrimitive(value.getAsString());
case StringTag value -> {
try {
yield JsonParser.parseString(value.getAsString());
} catch (Throwable ignored) {
yield new JsonPrimitive(value.getAsString());
}
}
case CompoundTag value -> this.gson.fromJson(value.getAsString(), JsonObject.class);
case ListTag value -> {
JsonArray jsonArray = new JsonArray();

for (Object element : value.toArray()) {
jsonArray.add(this.parseValue(element));
}

yield jsonArray;
}
default -> new JsonPrimitive(content.toString());
};
} catch (Throwable cause) {
cause.printStackTrace();
}

return JsonNull.INSTANCE;
}

}
Loading