diff --git a/gradle.properties b/gradle.properties index b8ca6c3c4b..852b8ab2b4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ author = masa mod_file_name = litematica-fabric # Current mod version -mod_version = 0.19.3-sakura.2 +mod_version = 0.19.3-sakura.3 # Required malilib version malilib_version = 0.20.0 diff --git a/src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetSchematicBrowser.java b/src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetSchematicBrowser.java index f0486ff358..a88c0c18ea 100644 --- a/src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetSchematicBrowser.java +++ b/src/main/java/fi/dy/masa/litematica/gui/widgets/WidgetSchematicBrowser.java @@ -6,6 +6,9 @@ import java.util.HashMap; import java.util.Map; import javax.annotation.Nullable; + +import fi.dy.masa.litematica.schematic.SchematicSchema; +import fi.dy.masa.litematica.util.DataFixerMode; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang3.tuple.Pair; @@ -32,6 +35,7 @@ public class WidgetSchematicBrowser extends WidgetFileBrowserBase protected static final FileFilter SCHEMATIC_FILTER = new FileFilterSchematics(); protected final Map cachedMetadata = new HashMap<>(); + protected final Map cachedVersion = new HashMap<>(); protected final Map> cachedPreviewImages = new HashMap<>(); protected final GuiSchematicBrowserBase parent; protected final int infoWidth; @@ -93,7 +97,20 @@ protected void drawSelectedSchematicInfo(@Nullable DirectoryEntry entry, DrawCon return; } - SchematicMetadata meta = this.getSchematicMetadata(entry); + Pair metaPair = this.getSchematicVersionAndMetadata(entry); + SchematicMetadata meta; + SchematicSchema version; + + if (metaPair != null) + { + meta = metaPair.getRight(); + version = metaPair.getLeft(); + } + else + { + return; + } + if (meta != null) { @@ -164,6 +181,19 @@ protected void drawSelectedSchematicInfo(@Nullable DirectoryEntry entry, DrawCon y += 12; } + if (version != null) + { + str = StringUtils.translate("litematica.gui.label.schematic_info.version", version.litematicVersion()); + this.drawString(drawContext, str, x, y, textColor); + y += 12; + + DataFixerMode.Schema schema = DataFixerMode.getSchemaByVersion(version.minecraftDataVersion()); + + str = StringUtils.translate("litematica.gui.label.schematic_info.schema", schema.getString(), version.minecraftDataVersion()); + this.drawString(drawContext, str, x, y, textColor); + y += 12; + } + /* str = StringUtils.translate("litematica.gui.label.schematic_info.description"); this.drawString(x, y, textColor, str); @@ -198,6 +228,7 @@ public void clearSchematicMetadataCache() this.clearPreviewImages(); this.cachedMetadata.clear(); this.cachedPreviewImages.clear(); + this.cachedVersion.clear(); } @Nullable @@ -224,6 +255,35 @@ protected SchematicMetadata getSchematicMetadata(DirectoryEntry entry) return meta; } + @Nullable + protected Pair getSchematicVersionAndMetadata(DirectoryEntry entry) + { + File file = new File(entry.getDirectory(), entry.getName()); + SchematicMetadata meta = this.cachedMetadata.get(file); + SchematicSchema version = this.cachedVersion.get(file); + + if (meta == null && this.cachedMetadata.containsKey(file) == false) + { + if (entry.getName().endsWith(LitematicaSchematic.FILE_EXTENSION)) + { + Pair pair = LitematicaSchematic.readMetadataAndVersionFromFile(entry.getDirectory(), entry.getName()); + + if (pair != null) + { + meta = pair.getRight(); + version = pair.getLeft(); + + this.createPreviewImage(file, meta); + } + } + + this.cachedMetadata.put(file, meta); + this.cachedVersion.put(file, version); + } + + return Pair.of(version, meta); + } + private void clearPreviewImages() { for (Pair pair : this.cachedPreviewImages.values()) diff --git a/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java b/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java index 113ef7bfc5..ca67f96eab 100644 --- a/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java +++ b/src/main/java/fi/dy/masa/litematica/schematic/LitematicaSchematic.java @@ -56,6 +56,7 @@ import fi.dy.masa.litematica.util.PositionUtils; import fi.dy.masa.litematica.util.WorldUtils; import fi.dy.masa.litematica.util.*; +import org.apache.commons.lang3.tuple.Pair; public class LitematicaSchematic { @@ -2342,6 +2343,54 @@ public static SchematicMetadata readMetadataFromFile(File dir, String fileName) return null; } + @Nullable + public static Pair readMetadataAndVersionFromFile(File dir, String fileName) + { + NbtCompound nbt = readNbtFromFile(fileFromDirAndName(dir, fileName, FileType.LITEMATICA_SCHEMATIC)); + + if (nbt != null) + { + SchematicMetadata metadata = new SchematicMetadata(); + + if (nbt.contains("Version", Constants.NBT.TAG_INT)) + { + final int version = nbt.getInt("Version"); + final int dataVersion = nbt.contains("MinecraftDataVersion") ? nbt.getInt("MinecraftDataVersion") : Configs.Generic.DATAFIXER_DEFAULT_SCHEMA.getIntegerValue(); + + if (version >= 1) + { + metadata.readFromNBT(nbt.getCompound("Metadata")); + + return Pair.of(new SchematicSchema(version, dataVersion), metadata); + } + } + } + + return null; + } + + @Nullable + public static SchematicSchema readDataVersionFromFile(File dir, String fileName) + { + NbtCompound nbt = readNbtFromFile(fileFromDirAndName(dir, fileName, FileType.LITEMATICA_SCHEMATIC)); + + if (nbt != null) + { + if (nbt.contains("Version", Constants.NBT.TAG_INT)) + { + final int version = nbt.getInt("Version"); + final int dataVersion = nbt.contains("MinecraftDataVersion") ? nbt.getInt("MinecraftDataVersion") : Configs.Generic.DATAFIXER_DEFAULT_SCHEMA.getIntegerValue(); + + if (version >= 1) + { + return new SchematicSchema(version, dataVersion); + } + } + } + + return null; + } + @Nullable public static LitematicaSchematic createFromFile(File dir, String fileName) { diff --git a/src/main/java/fi/dy/masa/litematica/schematic/SchematicSchema.java b/src/main/java/fi/dy/masa/litematica/schematic/SchematicSchema.java new file mode 100644 index 0000000000..ad5a5fd145 --- /dev/null +++ b/src/main/java/fi/dy/masa/litematica/schematic/SchematicSchema.java @@ -0,0 +1,10 @@ +package fi.dy.masa.litematica.schematic; + +public record SchematicSchema(int litematicVersion, int minecraftDataVersion) +{ + @Override + public String toString() + { + return "V" + this.litematicVersion() + " / DataVersion " + this.minecraftDataVersion(); + } +} diff --git a/src/main/java/fi/dy/masa/litematica/util/DataFixerMode.java b/src/main/java/fi/dy/masa/litematica/util/DataFixerMode.java index 6de4b265a0..87fc6974ab 100644 --- a/src/main/java/fi/dy/masa/litematica/util/DataFixerMode.java +++ b/src/main/java/fi/dy/masa/litematica/util/DataFixerMode.java @@ -177,48 +177,66 @@ public static Schema getSchemaByVersion(int dataVersion) public enum Schema { // Minecraft Data Versions - SCHEMA_24W37A (4065), - SCHEMA_1_21_01 (3955), - SCHEMA_1_21_00 (3953), - SCHEMA_1_20_05 (3837), - SCHEMA_1_20_04 (3700), - SCHEMA_1_20_02 (3578), - SCHEMA_1_20_01 (3465), - SCHEMA_1_20_00 (3463), - SCHEMA_1_19_04 (3337), - SCHEMA_1_19_00 (3105), - SCHEMA_1_18_02 (2975), - SCHEMA_1_18_00 (2860), - SCHEMA_1_17_01 (2730), - SCHEMA_1_17_00 (2724), - SCHEMA_1_16_05 (2586), - SCHEMA_1_16_00 (2566), - SCHEMA_1_15_02 (2230), - SCHEMA_1_15_00 (2225), - SCHEMA_1_14_04 (1976), - SCHEMA_1_14_00 (1952), - SCHEMA_1_13_02 (1631), - SCHEMA_1_13_00 (1519), - SCHEMA_1_12_02 (1343), - SCHEMA_1_12_00 (1139), - SCHEMA_1_11_02 (922), - SCHEMA_1_11_00 (819), - SCHEMA_1_10_02 (512), - SCHEMA_1_10_00 (510), - SCHEMA_1_09_04 (184), - SCHEMA_1_09_00 (169), - SCHEMA_15W32A (100); + SCHEMA_24W37A (4065, "24w37a"), + SCHEMA_1_21_01 (3955, "1.21.1"), + SCHEMA_1_21_00 (3953, "1.21"), + SCHEMA_1_20_05 (3837, "1.20.5"), + SCHEMA_24W10A (3821, "24w10a"), + SCHEMA_24W09A (3819, "24w09a"), // Data Components ( https://minecraft.wiki/w/Data_component_format ) + SCHEMA_24W07A (3817, "24w07a"), + SCHEMA_1_20_04 (3700, "1.20.4"), + SCHEMA_1_20_02 (3578, "1.20.2"), + SCHEMA_1_20_01 (3465, "1.20.1"), + SCHEMA_1_20_00 (3463, "1.20"), + SCHEMA_1_19_04 (3337, "1.19.4"), + SCHEMA_1_19_00 (3105, "1.19"), + SCHEMA_1_18_02 (2975, "1.18.2"), + SCHEMA_1_18_00 (2860, "1.18"), + SCHEMA_1_17_01 (2730, "1.17.1"), + SCHEMA_1_17_00 (2724, "1.17"), + SCHEMA_1_16_05 (2586, "1.16.5"), + SCHEMA_1_16_00 (2566, "1.16"), + SCHEMA_1_15_02 (2230, "1.15.2"), + SCHEMA_1_15_00 (2225, "1.15"), + SCHEMA_1_14_04 (1976, "1.14.4"), + SCHEMA_1_14_00 (1952, "1.14"), + SCHEMA_1_13_02 (1631, "1.13.2"), + SCHEMA_1_13_00 (1519, "1.13"), + SCHEMA_17W47A (1451, "17w47a"), // The Flattening ( https://minecraft.wiki/w/Java_Edition_1.13/Flattening ) + SCHEMA_17W46A (1449, "17w46a"), + SCHEMA_1_12_02 (1343, "1.12.2"), + SCHEMA_1_12_00 (1139, "1.12"), + SCHEMA_1_11_02 (922, "1.11.2"), + SCHEMA_1_11_00 (819, "1.11"), + SCHEMA_1_10_02 (512, "1.10.2"), + SCHEMA_1_10_00 (510, "1.10"), + SCHEMA_1_09_04 (184, "1.9.4"), + SCHEMA_1_09_00 (169, "1.9"), + SCHEMA_15W32A (100, "15w32a"); private final int schemaId; + private final String str; - Schema(int id) + Schema(int id, String ver) { this.schemaId = id; + this.str = ver; } public int getDataVersion() { return this.schemaId; } + + public String getString() + { + return this.str; + } + + @Override + public String toString() + { + return "MC: "+this.getString()+" [Schema: "+this.getDataVersion()+"]"; + } } } diff --git a/src/main/resources/assets/litematica/lang/en_us.json b/src/main/resources/assets/litematica/lang/en_us.json index 6c825fbe09..1c923ffc93 100644 --- a/src/main/resources/assets/litematica/lang/en_us.json +++ b/src/main/resources/assets/litematica/lang/en_us.json @@ -747,6 +747,8 @@ "litematica.gui.label.schematic_info.total_blocks": "Total blocks: §f%d§r", "litematica.gui.label.schematic_info.total_blocks_and_volume": "Blocks/Volume: §f%d§r/§f%d§r", "litematica.gui.label.schematic_info.total_volume": "Total volume: §f%d§r blocks", + "litematica.gui.label.schematic_info.version": "Litematic Version: §f%d§r", + "litematica.gui.label.schematic_info.schema": "Minecraft: §f%s§r [Schema §f%d§r]", "litematica.gui.label.schematic_load.checkbox.create_placement": "Create a placement", "litematica.gui.label.schematic_load.hoverinfo.create_placement": "Immediately create a new placement\nand select that placement", diff --git a/src/main/resources/assets/litematica/lang/it_it.json b/src/main/resources/assets/litematica/lang/it_it.json index 77be5fc6a6..26b508745d 100644 --- a/src/main/resources/assets/litematica/lang/it_it.json +++ b/src/main/resources/assets/litematica/lang/it_it.json @@ -744,6 +744,8 @@ "litematica.gui.label.schematic_info.total_blocks": "Totale blocchi: §f%d§r", "litematica.gui.label.schematic_info.total_blocks_and_volume": "Blocchi/Volume: §f%d§r/§f%d§r", "litematica.gui.label.schematic_info.total_volume": "Volume totale: §f%d§r blocchi", + "litematica.gui.label.schematic_info.version": "Versione Litematic: §f%d§r", + "litematica.gui.label.schematic_info.schema": "Minecraft: §f%s§r [Schema §f%d§r]", "litematica.gui.label.schematic_load.checkbox.create_placement": "Crea una posizione", "litematica.gui.label.schematic_load.hoverinfo.create_placement": "Crea immediatamente una nuova posizione\ned è selezionata quella posizione", diff --git a/src/main/resources/assets/litematica/lang/zh_cn.json b/src/main/resources/assets/litematica/lang/zh_cn.json index feaa065334..bb3747ed76 100644 --- a/src/main/resources/assets/litematica/lang/zh_cn.json +++ b/src/main/resources/assets/litematica/lang/zh_cn.json @@ -744,6 +744,8 @@ "litematica.gui.label.schematic_info.total_blocks": "方块总数: §f%d§r", "litematica.gui.label.schematic_info.total_blocks_and_volume": "方块/体积: §f%d§r/§f%d§r", "litematica.gui.label.schematic_info.total_volume": "总体积: §f%d§r 个方块", + "litematica.gui.label.schematic_info.version": "精简版: §f%d§r", + "litematica.gui.label.schematic_info.schema": "我的世界: §f%s§r [架构 §f%d§r]", "litematica.gui.label.schematic_load.checkbox.create_placement": "创建放置", "litematica.gui.label.schematic_load.hoverinfo.create_placement": "立即创建新位置并选择该位置", diff --git a/src/main/resources/assets/litematica/lang/zh_tw.json b/src/main/resources/assets/litematica/lang/zh_tw.json index c34a95ca4d..4867e89563 100644 --- a/src/main/resources/assets/litematica/lang/zh_tw.json +++ b/src/main/resources/assets/litematica/lang/zh_tw.json @@ -744,6 +744,8 @@ "litematica.gui.label.schematic_info.total_blocks": "總方塊數: §f%d§r", "litematica.gui.label.schematic_info.total_blocks_and_volume": "方塊/體積: §f%d§r/§f%d§r", "litematica.gui.label.schematic_info.total_volume": "總體積: §f%d§r 個方塊", + "litematica.gui.label.schematic_info.version": "精簡版: §f%d§r", + "litematica.gui.label.schematic_info.schema": "我的世界: §f%s§r [架构 §f%d§r]", "litematica.gui.label.schematic_load.checkbox.create_placement": "創建放置", "litematica.gui.label.schematic_load.hoverinfo.create_placement": "立即創建新位置\n並選擇該位置",