From 0717f277ffb6641c3a83d5cc9905c322334151c9 Mon Sep 17 00:00:00 2001 From: quentin452 <42176772+quentin452@users.noreply.github.com> Date: Mon, 22 Jan 2024 05:48:44 +0100 Subject: [PATCH] Revert "MixinCompressedStreamTools : add experimental Thread" This reverts commit a4140e0c8f979e0c185937a3b7ea43a57ef78dae. --- .../core/MixinCompressedStreamTools.java | 25 ++++++----- .../vanilla/NBTReadThread.java | 45 ------------------- 2 files changed, 13 insertions(+), 57 deletions(-) delete mode 100644 src/main/java/fr/iamacat/optimizationsandtweaks/utils/optimizationsandtweaks/vanilla/NBTReadThread.java diff --git a/src/main/java/fr/iamacat/optimizationsandtweaks/mixins/common/core/MixinCompressedStreamTools.java b/src/main/java/fr/iamacat/optimizationsandtweaks/mixins/common/core/MixinCompressedStreamTools.java index 2f2bae69..08af3a89 100644 --- a/src/main/java/fr/iamacat/optimizationsandtweaks/mixins/common/core/MixinCompressedStreamTools.java +++ b/src/main/java/fr/iamacat/optimizationsandtweaks/mixins/common/core/MixinCompressedStreamTools.java @@ -2,9 +2,7 @@ import java.io.*; import java.lang.reflect.Method; -import java.nio.file.Files; -import fr.iamacat.optimizationsandtweaks.utils.optimizationsandtweaks.vanilla.NBTReadThread; import net.minecraft.crash.CrashReport; import net.minecraft.crash.CrashReportCategory; import net.minecraft.nbt.*; @@ -24,16 +22,18 @@ public abstract class MixinCompressedStreamTools { * Load the gzipped compound from the inputstream. */ @Overwrite - public static NBTTagCompound readCompressed(InputStream p_74796_0_) { - NBTReadThread thread = new NBTReadThread(p_74796_0_); - thread.start(); + public static NBTTagCompound readCompressed(InputStream p_74796_0_) throws IOException { + DataInputStream datainputstream = new DataInputStream( + new BufferedInputStream(new GZIPInputStream2(p_74796_0_))); + NBTTagCompound nbttagcompound; + try { - thread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); + nbttagcompound = func_152456_a(datainputstream, NBTSizeTracker.field_152451_a); + } finally { + datainputstream.close(); } - return thread.getResult(); + return nbttagcompound; } /** @@ -131,7 +131,8 @@ public static NBTTagCompound func_152456_a(DataInput dataInput, NBTSizeTracker n } @Shadow - private static NBTBase func_152455_a(DataInput p_152455_0_, int p_152455_1_, NBTSizeTracker p_152455_2_) { + private static NBTBase func_152455_a(DataInput p_152455_0_, int p_152455_1_, NBTSizeTracker p_152455_2_) + throws IOException { try { Method func_150284_a = NBTBase.class.getDeclaredMethod("func_150284_a", byte.class); Method func_152446_a = NBTBase.class @@ -176,7 +177,7 @@ public static void write(NBTTagCompound nbtTagCompound, DataOutput dataOutput) t } @Shadow - private static void func_150663_a(NBTBase p_150663_0_, DataOutput p_150663_1_) { + private static void func_150663_a(NBTBase p_150663_0_, DataOutput p_150663_1_) throws IOException { try { Method writeMethod = NBTBase.class.getDeclaredMethod("write", DataOutput.class); @@ -221,7 +222,7 @@ public static NBTTagCompound func_152458_a(File p_152458_0_, NBTSizeTracker p_15 if (!p_152458_0_.exists()) { return null; } else { - DataInputStream datainputstream = new DataInputStream(Files.newInputStream(p_152458_0_.toPath())); + DataInputStream datainputstream = new DataInputStream(new FileInputStream(p_152458_0_)); NBTTagCompound nbttagcompound; try { diff --git a/src/main/java/fr/iamacat/optimizationsandtweaks/utils/optimizationsandtweaks/vanilla/NBTReadThread.java b/src/main/java/fr/iamacat/optimizationsandtweaks/utils/optimizationsandtweaks/vanilla/NBTReadThread.java deleted file mode 100644 index 2b1982eb..00000000 --- a/src/main/java/fr/iamacat/optimizationsandtweaks/utils/optimizationsandtweaks/vanilla/NBTReadThread.java +++ /dev/null @@ -1,45 +0,0 @@ -package fr.iamacat.optimizationsandtweaks.utils.optimizationsandtweaks.vanilla; - -import fr.iamacat.optimizationsandtweaks.utils.optimizationsandtweaks.resources.GZIPInputStream2; -import net.minecraft.nbt.CompressedStreamTools; -import net.minecraft.nbt.NBTSizeTracker; -import net.minecraft.nbt.NBTTagCompound; - -import java.io.BufferedInputStream; -import java.io.DataInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.LinkedBlockingQueue; - -public class NBTReadThread extends Thread { - - private final InputStream inputStream; - private final BlockingQueue resultQueue; - - public NBTReadThread(InputStream inputStream) { - this.inputStream = inputStream; - this.resultQueue = new LinkedBlockingQueue<>(); - } - - @Override - public void run() { - try (DataInputStream datainputstream = new DataInputStream( - new BufferedInputStream(new GZIPInputStream2(inputStream)))) { - NBTTagCompound nbttagcompound = CompressedStreamTools.func_152456_a(datainputstream, - NBTSizeTracker.field_152451_a); - resultQueue.offer(nbttagcompound); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public NBTTagCompound getResult() { - try { - return resultQueue.take(); - } catch (InterruptedException e) { - e.printStackTrace(); - return null; - } - } -}