From 666d4fc03e65ab68a6d400253f735762853b7d26 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Tue, 18 Jun 2024 19:16:16 +0200 Subject: [PATCH] add config backups --- .../client/feature/modules/client/Client.java | 29 +++++++++++++++++++ .../feature/modules/movement/ElytraFly.java | 4 +-- .../feature/modules/render/NoRender.java | 6 ++-- .../client/util/interact/BlockUtils.java | 1 - 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java index 6a02d7d..4281a02 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/client/Client.java @@ -14,6 +14,8 @@ import de.com.baseband.client.registry.annotation.Trigger; import de.com.baseband.client.util.interact.Chat; import de.com.baseband.client.util.interact.RotationManager; import de.com.baseband.client.util.interact.ServerDataManager; +import de.tudbut.io.StreamReader; +import de.tudbut.parsing.JSON; import net.minecraft.entity.EntityLivingBase; import net.minecraft.network.Packet; import net.minecraft.network.play.server.SPacketPlayerPosLook; @@ -22,6 +24,10 @@ import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; + @ClientCategory public class Client extends Feature { @@ -60,6 +66,29 @@ public class Client extends Feature { BaseBand.notify("Config saved to disk"); } + @Trigger("Save backup") + public void saveBackup() { + try(FileOutputStream stream = new FileOutputStream("baseband.db.bak")) { + stream.write(JSON.writeReadable(Configuration.asTCN()).getBytes()); + BaseBand.notify("§aCreated backup of config"); + } catch (IOException e) { + e.printStackTrace(); + BaseBand.notify("§cFailed to back up config"); + } + } + + @Trigger("Load backup") + public void loadBackup() { + try(FileInputStream stream = new FileInputStream("baseband.db.bak")) { + String s = new StreamReader(stream).readAllAsString(); + Configuration.cloneConfigFrom(JSON.read(s)); + BaseBand.notify("§aLoaded backup of config"); + } catch (IOException | JSON.JSONFormatException e) { + e.printStackTrace(); + BaseBand.notify("§cFailed to load backup of config"); + } + } + public GuiTheme.ITheme getTheme() { return theme; diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/movement/ElytraFly.java b/Client/src/main/java/de/com/baseband/client/feature/modules/movement/ElytraFly.java index ad84479..8aacb9b 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/movement/ElytraFly.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/movement/ElytraFly.java @@ -57,7 +57,7 @@ public class ElytraFly extends Feature { "With correct settings, this should only require a single normal-height jump at normal speed to take off.\n" + "With okay ping, this can also take off in 1x2 tunnels.") @Marker(1) - public boolean autoTakeoff = false; + public boolean autoTakeoff = true; @Config("Post-Takeoff Motion") @Description("Applies some amount of motion to the player after takeoff is complete, just in case the server resets the elytra again due to bad ping.\n" + @@ -71,7 +71,7 @@ public class ElytraFly extends Feature { "and higher ones might be more forgiving to bad Gate settings.") @Range("1..40") @Gate(1) - public int takeoffTicks = 1; + public int takeoffTicks = 5; @Config("Takeoff Gate Mode") @Description("Advanced: How the begin of a fall should be detected. Packet is almost always the better option and can't be misconfigured. Only try changing if something doesn't work.") diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/render/NoRender.java b/Client/src/main/java/de/com/baseband/client/feature/modules/render/NoRender.java index d12de8b..f2aa569 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/render/NoRender.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/render/NoRender.java @@ -34,8 +34,8 @@ public class NoRender extends Feature { @Config("ItemFrame") public boolean itemFrame; - @Config("NoPotionIcon") - public boolean noPotion; + @Config("PotionIcon") + public boolean potionIcon; @SubscribeEvent @@ -48,7 +48,7 @@ public class NoRender extends Feature { @SubscribeEvent public void overlayGameRenderEvent(RenderGameOverlayEvent event) { - if (noPotion && event.getType() == RenderGameOverlayEvent.ElementType.POTION_ICONS) + if (potionIcon && event.getType() == RenderGameOverlayEvent.ElementType.POTION_ICONS) event.setCanceled(true); } diff --git a/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java b/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java index 484745e..a1c4f27 100644 --- a/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java +++ b/Client/src/main/java/de/com/baseband/client/util/interact/BlockUtils.java @@ -12,7 +12,6 @@ public class BlockUtils { Vec3i size = selection.size(); int selSideLength = selection.longestSideH(); int sectionSideLength = (selSideLength - 1) / amount + 1; // rounded up - System.out.println(sectionSideLength); Selection[] selections = new Selection[(int) ((selSideLength - 1) / sectionSideLength + 1)]; // rounded up int xSideLength = 0; int zSideLength = 0;