]> git.lizzy.rs Git - BoundingBoxOutlineReloaded.git/blobdiff - src/main/java/com/irtimaled/bbor/client/gui/WorldSaveRow.java
Setup for 1.16.3 Fabric
[BoundingBoxOutlineReloaded.git] / src / main / java / com / irtimaled / bbor / client / gui / WorldSaveRow.java
index 3d88eccc4b72ce04834f91c15c01db986fe3999d..3c8aca227e191840dd12cfa5ab7f0bb5c851e2c1 100644 (file)
@@ -7,9 +7,11 @@ import net.minecraft.client.MinecraftClient;
 import net.minecraft.client.gui.DrawableHelper;
 import net.minecraft.client.texture.NativeImage;
 import net.minecraft.client.texture.NativeImageBackedTexture;
+import net.minecraft.client.util.math.MatrixStack;
+import net.minecraft.nbt.NbtIo;
 import net.minecraft.util.Identifier;
 import net.minecraft.util.Util;
-import net.minecraft.world.level.LevelProperties;
+import net.minecraft.util.WorldSavePath;
 import net.minecraft.world.level.storage.LevelStorage;
 import net.minecraft.world.level.storage.LevelSummary;
 import org.apache.logging.log4j.LogManager;
@@ -17,6 +19,7 @@ import org.apache.logging.log4j.Logger;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
@@ -44,7 +47,7 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
         this.setSelectedEntry = setSelectedEntry;
         this.client = MinecraftClient.getInstance();
         this.iconLocation = new Identifier("worlds/" + Hashing.sha1().hashUnencodedChars(worldSummary.getName()) + "/icon");
-        this.iconFile = saveLoader.resolveFile(worldSummary.getName(), "icon.png");
+        this.iconFile = worldSummary.getFile();
         if (!this.iconFile.isFile()) {
             this.iconFile = null;
         }
@@ -76,9 +79,20 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
     @Override
     public void done() {
         String fileName = this.worldSummary.getName();
-        LevelProperties worldInfo = saveLoader.getLevelProperties(fileName);
-        long seed = worldInfo.getSeed();
-        ClientInterop.saveLoaded(fileName, seed);
+        LevelStorage.Session worldInfo = null;
+        try {
+            worldInfo = saveLoader.createSession(fileName);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        try {
+            long seed = NbtIo.readCompressed(new FileInputStream(worldInfo.getDirectory(WorldSavePath.LEVEL_DAT).toFile()))
+                    .getCompound("Data")
+                    .getCompound("WorldGenSettings").getLong("seed");
+            worldInfo.close();
+            ClientInterop.saveLoaded(fileName, seed);
+        } catch (IOException ignored) {
+        }
     }
 
     private NativeImageBackedTexture loadIcon() {
@@ -99,17 +113,17 @@ public class WorldSaveRow extends ControlListEntry implements Comparable<WorldSa
     }
 
     @Override
-    public void render(int mouseX, int mouseY) {
+    public void render(MatrixStack matrixStack, int mouseX, int mouseY) {
         String displayName = this.worldSummary.getDisplayName();
         String details = this.worldSummary.getName() + " (" + DATE_FORMAT.format(new Date(this.worldSummary.getLastPlayed())) + ")";
 
         int x = this.getX();
         int y = this.getY();
-        this.client.textRenderer.draw(displayName, (float) (x + ICON_SIZE + 3), (float) (y + 1), 16777215);
-        this.client.textRenderer.draw(details, (float) (x + ICON_SIZE + 3), (float) (y + 1 + this.client.textRenderer.fontHeight + 1), 8421504);
+        this.client.textRenderer.draw(matrixStack, displayName, (float) (x + ICON_SIZE + 3), (float) (y + 1), 16777215);
+        this.client.textRenderer.draw(matrixStack, details, (float) (x + ICON_SIZE + 3), (float) (y + 1 + this.client.textRenderer.fontHeight + 1), 8421504);
         this.client.getTextureManager().bindTexture(this.icon != null ? this.iconLocation : ICON_MISSING);
         RenderHelper.enableBlend();
-        DrawableHelper.blit(x, y, 0.0F, 0.0F, ICON_SIZE, ICON_SIZE, 32, 32);
+        DrawableHelper.drawTexture(matrixStack, x, y, 0.0F, 0.0F, ICON_SIZE, ICON_SIZE, 32, 32);
         RenderHelper.disableBlend();
     }