From f9fea9dfbff95608dcbfe3519f8cbe81ea2b79dd Mon Sep 17 00:00:00 2001 From: PeytonPlayz595 <106421860+PeytonPlayz595@users.noreply.github.com> Date: Sat, 3 Feb 2024 20:34:15 -0500 Subject: [PATCH] Fixed delete world button --- .../PeytonPlayz585/io/FileSystemUtils.java | 26 +++++++++++++++++++ .../net/minecraft/src/IProgressUpdate.java | 2 ++ .../minecraft/src/LoadingScreenRenderer.java | 17 ++++++++++++ src/main/java/net/minecraft/src/World.java | 6 ++--- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/PeytonPlayz585/io/FileSystemUtils.java b/src/main/java/net/PeytonPlayz585/io/FileSystemUtils.java index 2dfd258..d0867f5 100644 --- a/src/main/java/net/PeytonPlayz585/io/FileSystemUtils.java +++ b/src/main/java/net/PeytonPlayz585/io/FileSystemUtils.java @@ -3,6 +3,7 @@ package net.PeytonPlayz585.io; import java.util.Collection; import net.PeytonPlayz585.opengl.LWJGLMain; +import net.minecraft.src.IProgressUpdate; public class FileSystemUtils { @@ -21,4 +22,29 @@ public class FileSystemUtils { LWJGLMain.deleteFile(dir); } + public static void recursiveDeleteDirectoryWithProgress(String dir, String title, String subText, IProgressUpdate progress) { + progress.displayLoadingString(title, "(please wait)"); + Collection lst = LWJGLMain.listFiles(dir, true, true); + int totalDeleted = 0; + int lastTotalDeleted = 0; + for(LWJGLMain.FileEntry t : lst) { + if(!t.isDirectory) { + LWJGLMain.deleteFile(t.path); + ++totalDeleted; + if(totalDeleted - lastTotalDeleted >= 10) { + lastTotalDeleted = totalDeleted; + int percentage = (int) Math.ceil(((double) totalDeleted / lst.size()) * 100); + progress.displayLoadingString(title, subText.replace("%i", "" + totalDeleted)); + progress.setLoadingProgress(percentage); + } + } + } + for(LWJGLMain.FileEntry t : lst) { + if(t.isDirectory) { + LWJGLMain.deleteFile(t.path); + } + } + LWJGLMain.deleteFile(dir); + } + } \ No newline at end of file diff --git a/src/main/java/net/minecraft/src/IProgressUpdate.java b/src/main/java/net/minecraft/src/IProgressUpdate.java index 1fb3c60..9b640fe 100644 --- a/src/main/java/net/minecraft/src/IProgressUpdate.java +++ b/src/main/java/net/minecraft/src/IProgressUpdate.java @@ -5,5 +5,7 @@ public interface IProgressUpdate { void displayLoadingString(String var1); + void displayLoadingString(String var1, String var2); + void setLoadingProgress(int var1); } diff --git a/src/main/java/net/minecraft/src/LoadingScreenRenderer.java b/src/main/java/net/minecraft/src/LoadingScreenRenderer.java index 435c9ac..85fe8c9 100644 --- a/src/main/java/net/minecraft/src/LoadingScreenRenderer.java +++ b/src/main/java/net/minecraft/src/LoadingScreenRenderer.java @@ -57,6 +57,23 @@ public class LoadingScreenRenderer implements IProgressUpdate { } } + public void displayLoadingString(String s, String s1) { + if (!mc.running) { + if (printText) { + return; + } else { + throw new MinecraftError(); + } + } else { + systemTime = 0L; + currentlyDisplayedProgress = s1; + currentlyDisplayedText = s; + setLoadingProgress(-1); + systemTime = 0L; + return; + } + } + public void setLoadingProgress(int var1) { if(!this.mc.running) { if(!this.printText) { diff --git a/src/main/java/net/minecraft/src/World.java b/src/main/java/net/minecraft/src/World.java index 0745d21..fcf3db9 100644 --- a/src/main/java/net/minecraft/src/World.java +++ b/src/main/java/net/minecraft/src/World.java @@ -67,10 +67,8 @@ public class World implements IBlockAccess { } public static void deleteWorld(String var1) { - String dir = "saves/" + var1; - if(LWJGLMain.directoryExists(dir)) { - FileSystemUtils.recursiveDeleteDirectory(dir); - } + String dir = var1 + "/"; + FileSystemUtils.recursiveDeleteDirectoryWithProgress(dir, "Deleting World!", "Please Wait...", Minecraft.getMinecraft().loadingScreen); } public World(String var2) {