Skip to content

Commit b635f0e

Browse files
authored
1.5.0
use less intrusive mixins (replaced some redirects with modifyconstant/-variable) fix the "still saving the last world" screen never actually rendering remove/replace unused and unnecessary code and some more stuff
1 parent 06612af commit b635f0e

10 files changed

Lines changed: 147 additions & 110 deletions

build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@ dependencies {
2525

2626
processResources {
2727
inputs.property "version", project.version
28+
filteringCharset "UTF-8"
2829

29-
// from(sourceSets.main.resources.srcDirs) {
30-
// include "fabric.mod.json"
31-
// expand "version": project.version
32-
// }
33-
//
34-
// from(sourceSets.main.resources.srcDirs) {
35-
// exclude "fabric.mod.json"
36-
// }
30+
filesMatching("fabric.mod.json") {
31+
expand "version": project.version
32+
}
3733
}
3834

3935
// ensure that the encoding is set to UTF-8, no matter what the system default is

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ minecraft_version=1.16.1
66
yarn_mappings=1.16.1+build.21
77
loader_version=0.11.3
88
# Mod Properties
9-
mod_version=1.4.1
9+
mod_version=1.5
1010
maven_group=fast-reset-1.16.1-v
1111
archives_base_name=fast-reset-1.16.1-v
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package fast_reset.client;
2+
3+
import net.fabricmc.api.ClientModInitializer;
4+
import net.fabricmc.loader.api.FabricLoader;
5+
import org.apache.logging.log4j.LogManager;
6+
import org.apache.logging.log4j.Logger;
7+
8+
import java.io.*;
9+
import java.nio.file.Files;
10+
11+
public class FastReset implements ClientModInitializer {
12+
13+
public static final Logger LOGGER = LogManager.getLogger();
14+
private static final File configurationFile = FabricLoader.getInstance().getConfigDir().resolve("fastReset").resolve("settings.txt").toFile();
15+
16+
public static boolean saveOnQuit = true;
17+
public static final Object saveLock = new Object();
18+
19+
public static int buttonLocation = 0;
20+
21+
public static void updateButtonLocation() {
22+
buttonLocation = (buttonLocation + 1) % 3;
23+
save();
24+
}
25+
26+
private static void save() {
27+
try {
28+
Files.write(configurationFile.toPath(), String.valueOf(buttonLocation).getBytes());
29+
} catch (IOException e) {
30+
LOGGER.error("Failed to save FastReset config", e);
31+
}
32+
}
33+
34+
@Override
35+
public void onInitializeClient() {
36+
LOGGER.info("Using Fast Reset");
37+
38+
if (!configurationFile.exists()) {
39+
try {
40+
if (!configurationFile.getParentFile().mkdirs()) {
41+
throw new IOException("couldn't make config folder");
42+
}
43+
if (!configurationFile.createNewFile()) {
44+
throw new IOException("couldn't make config file");
45+
}
46+
save();
47+
} catch (IOException e) {
48+
LOGGER.error("Failed to create FastReset config", e);
49+
}
50+
return;
51+
}
52+
53+
try {
54+
BufferedReader reader = new BufferedReader(new FileReader(configurationFile));
55+
buttonLocation = Integer.parseInt(reader.readLine()) % 3;
56+
reader.close();
57+
} catch (IOException | NumberFormatException e) {
58+
LOGGER.error("Failed to load FastReset config", e);
59+
}
60+
}
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package fast_reset.client.mixin;
2+
3+
import fast_reset.client.FastReset;
4+
import net.minecraft.client.gui.screen.SaveLevelScreen;
5+
import net.minecraft.client.gui.screen.Screen;
6+
import net.minecraft.client.gui.screen.world.CreateWorldScreen;
7+
import net.minecraft.text.Text;
8+
import net.minecraft.text.TranslatableText;
9+
import org.spongepowered.asm.mixin.Mixin;
10+
import org.spongepowered.asm.mixin.injection.At;
11+
import org.spongepowered.asm.mixin.injection.Inject;
12+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
13+
14+
@Mixin(CreateWorldScreen.class)
15+
public class CreateWorldScreenMixin extends Screen {
16+
17+
protected CreateWorldScreenMixin(Text title) {
18+
super(title);
19+
}
20+
21+
@Inject(method = "createLevel", at = @At("HEAD"))
22+
private void worldWait(CallbackInfo ci) {
23+
this.client.method_29970(new SaveLevelScreen(new TranslatableText("still saving the last world")));
24+
synchronized(FastReset.saveLock) {
25+
FastReset.LOGGER.info("done waiting for save lock");
26+
}
27+
}
28+
29+
}
Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
package fast_reset.client.mixin;
22

3-
import fast_reset.client.Client;
3+
import fast_reset.client.FastReset;
44
import net.minecraft.client.gui.screen.GameMenuScreen;
5-
import net.minecraft.client.gui.screen.SaveLevelScreen;
65
import net.minecraft.client.gui.screen.Screen;
7-
import net.minecraft.client.gui.screen.TitleScreen;
8-
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
96
import net.minecraft.client.gui.widget.ButtonWidget;
10-
import net.minecraft.realms.RealmsBridge;
117
import net.minecraft.text.Text;
128
import net.minecraft.text.TranslatableText;
139
import org.spongepowered.asm.mixin.Mixin;
1410
import org.spongepowered.asm.mixin.injection.At;
15-
import org.spongepowered.asm.mixin.injection.Inject;
16-
import org.spongepowered.asm.mixin.injection.Redirect;
17-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
11+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
1812

1913
@Mixin(GameMenuScreen.class)
2014
public class GameMenuMixin extends Screen {
@@ -23,26 +17,17 @@ protected GameMenuMixin(Text title) {
2317
super(title);
2418
}
2519

26-
private static final int bottomRightWidth = 102;
27-
28-
// kill save on the shutdown
29-
@Redirect(method = "initWidgets", at = @At(value = "NEW", target = "net/minecraft/client/gui/widget/ButtonWidget", ordinal=7))
30-
private ButtonWidget createExitButton(int defaultX, int defaultY, int defaultWidth, int height, Text message, ButtonWidget.PressAction onPress){
31-
int x = Client.buttonLocation == 2 ? (int) (this.width - (bottomRightWidth * 1.5) - 4) : defaultX;
32-
int y = Client.buttonLocation == 2 ? this.height - 24 : defaultY;
33-
int width = Client.buttonLocation == 2 ? (int) (bottomRightWidth * 1.5) : defaultWidth;
34-
35-
return new ButtonWidget(x, y, width, height, message, onPress);
36-
}
20+
@ModifyVariable(method = "initWidgets", at = @At(value = "STORE", ordinal = 1))
21+
private ButtonWidget createExitButton(ButtonWidget saveButton) {
22+
if (!this.client.isInSingleplayer()) {
23+
return saveButton;
24+
}
3725

38-
@Inject(method = "initWidgets", at=@At(value ="TAIL"))
39-
private void createSaveButton(CallbackInfo ci){
4026
int height = 20;
41-
4227
int width;
4328
int x;
4429
int y;
45-
switch(Client.buttonLocation){
30+
switch (FastReset.buttonLocation){
4631
// bottom right build
4732
case 0:
4833
width = 102;
@@ -52,40 +37,27 @@ private void createSaveButton(CallbackInfo ci){
5237
// center build
5338
case 1:
5439
width = 204;
55-
x = this.width / 2 - width/2;
40+
x = this.width / 2 - width / 2;
5641
y = this.height / 4 + 148 - height;
5742
break;
43+
// replace s&q build
5844
case 2:
5945
default:
6046
width = 204;
61-
x = this.width / 2 - width/2;
47+
x = this.width / 2 - width / 2;
6248
y = this.height / 4 + 124 - height;
49+
50+
saveButton.x = (int) (this.width - (102 * 1.5) - 4);
51+
saveButton.y = this.height - 24;
52+
saveButton.setWidth((int) (102 * 1.5));
6353
break;
6454
}
6555

66-
6756
this.addButton(new ButtonWidget(x, y, width, height, new TranslatableText("menu.quitWorld"), (buttonWidgetX) -> {
68-
Client.saveOnQuit = false;
69-
70-
boolean bl = this.client.isInSingleplayer();
71-
boolean bl2 = this.client.isConnectedToRealms();
72-
buttonWidgetX.active = false;
73-
this.client.world.disconnect();
74-
if (bl) {
75-
this.client.disconnect(new SaveLevelScreen(new TranslatableText("menu.savingLevel")));
76-
} else {
77-
this.client.disconnect();
78-
}
79-
80-
if (bl) {
81-
this.client.openScreen(new TitleScreen());
82-
} else if (bl2) {
83-
RealmsBridge realmsBridge = new RealmsBridge();
84-
realmsBridge.switchToRealms(new TitleScreen());
85-
} else {
86-
this.client.openScreen(new MultiplayerScreen(new TitleScreen()));
87-
}
88-
Client.saveOnQuit = true;
57+
FastReset.saveOnQuit = false;
58+
saveButton.onPress();
59+
FastReset.saveOnQuit = true;
8960
}));
61+
return saveButton;
9062
}
9163
}
Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package fast_reset.client.mixin;
22

3-
import fast_reset.client.Client;
3+
import fast_reset.client.FastReset;
44
import net.minecraft.client.gui.screen.Screen;
5-
import net.minecraft.client.gui.screen.ScreenTexts;
65
import net.minecraft.client.gui.screen.options.OptionsScreen;
76
import net.minecraft.client.gui.widget.ButtonWidget;
87
import net.minecraft.text.LiteralText;
@@ -19,23 +18,23 @@ protected OptionsScreenMixin(Text title) {
1918
super(title);
2019
}
2120

22-
private static Text getButtonText(){
23-
switch(Client.buttonLocation){
21+
private static String getButtonText() {
22+
switch (FastReset.buttonLocation) {
2423
case 0:
25-
return new LiteralText("bottom right");
24+
return "bottom right";
2625
case 1:
27-
return new LiteralText("center");
26+
return "center";
2827
case 2:
2928
default:
30-
return new LiteralText("replace s&q");
29+
return "replace s&q";
3130
}
3231
}
3332

3433
@Inject(method = "init", at=@At("TAIL"))
35-
public void initInject(CallbackInfo ci){
36-
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 142 - 4, 150, 20, getButtonText(), (buttonWidget) -> {
37-
Client.updateButtonLocation();
38-
buttonWidget.setMessage(getButtonText());
34+
public void initInject(CallbackInfo ci) {
35+
this.addButton(new ButtonWidget(this.width / 2 - 155, this.height / 6 + 142 - 4, 150, 20, new LiteralText(getButtonText()), (buttonWidget) -> {
36+
FastReset.updateButtonLocation();
37+
buttonWidget.setMessage(new LiteralText(getButtonText()));
3938
}));
4039
}
4140
}
Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fast_reset.client.mixin;
22

3-
import fast_reset.client.Client;
3+
import fast_reset.client.FastReset;
44
import net.minecraft.server.MinecraftServer;
55
import net.minecraft.server.PlayerManager;
66
import net.minecraft.server.world.ServerWorld;
@@ -9,68 +9,54 @@
99
import org.spongepowered.asm.mixin.Mixin;
1010
import org.spongepowered.asm.mixin.Shadow;
1111
import org.spongepowered.asm.mixin.injection.At;
12+
import org.spongepowered.asm.mixin.injection.Constant;
13+
import org.spongepowered.asm.mixin.injection.ModifyConstant;
1214
import org.spongepowered.asm.mixin.injection.Redirect;
1315

1416
import java.io.IOException;
17+
import java.util.ConcurrentModificationException;
1518
import java.util.Iterator;
1619

1720
@Mixin(MinecraftServer.class)
1821
public class ResetMixin {
1922
@Shadow @Final protected LevelStorage.Session session;
2023

2124
// kill save on the shutdown
22-
@Redirect(method = "shutdown", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z", ordinal = 0))
23-
private boolean getWorldsInjectOne(Iterator<ServerWorld> iterator){
24-
if(Client.saveOnQuit){
25-
return iterator.hasNext();
26-
}
27-
while(iterator.hasNext()){
28-
iterator.next().savingDisabled = true;
29-
}
30-
return false;
25+
@ModifyConstant(method = "shutdown", constant = @Constant(intValue = 0, ordinal = 0))
26+
private int disableWorldSaving(int savingDisabled) {
27+
return FastReset.saveOnQuit ? savingDisabled : 1;
3128
}
3229

3330
@Redirect(method = "shutdown", at = @At(value = "INVOKE", target = "Ljava/util/Iterator;hasNext()Z", ordinal = 1))
34-
private boolean getWorldsInjectTwo(Iterator<ServerWorld> iterator){
35-
if(Client.saveOnQuit){
31+
private boolean closeWorldsRedirect(Iterator<ServerWorld> iterator) {
32+
if (FastReset.saveOnQuit) {
3633
return iterator.hasNext();
3734
}
3835

3936
new Thread(() -> {
40-
synchronized(Client.saveLock){
41-
while(iterator.hasNext()){
37+
synchronized(FastReset.saveLock) {
38+
while(iterator.hasNext()) {
4239
ServerWorld world = iterator.next();
4340
if (world != null) {
4441
try {
4542
world.close();
46-
} catch (IOException ignored) {
47-
43+
} catch (ConcurrentModificationException | IOException ignored) {
4844
}
4945
}
5046
}
5147
try {
5248
this.session.deleteSessionLock();
53-
} catch (IOException e) {
54-
e.printStackTrace();
49+
} catch (IllegalStateException | IOException ignored) {
5550
}
5651
}
5752
}).start();
5853
return false;
5954
}
6055

6156
@Redirect(method = "shutdown", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;saveAllPlayerData()V"))
62-
private void shutdownPlayerSaveInject(PlayerManager playerManager){
63-
if(Client.saveOnQuit){
57+
private void disablePlayerSaving(PlayerManager playerManager) {
58+
if (FastReset.saveOnQuit) {
6459
playerManager.saveAllPlayerData();
6560
}
6661
}
67-
68-
// kill all things auto save things
69-
// @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;save(ZZZ)Z"))
70-
// private boolean autoSaveInject(MinecraftServer server, boolean a, boolean b, boolean c){
71-
// return false;
72-
// }
73-
//
74-
// @Redirect(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/PlayerManager;saveAllPlayerData()V"))
75-
// private void shutdownPlayerDataSaveInject(PlayerManager server){}
7662
}

src/main/java/fast_reset/client/mixin/ServerChunkManagerMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
package fast_reset.client.mixin;
22

3-
import fast_reset.client.Client;
3+
import fast_reset.client.FastReset;
44
import net.minecraft.server.world.ServerChunkManager;
55
import org.spongepowered.asm.mixin.Mixin;
66
import org.spongepowered.asm.mixin.injection.At;
77
import org.spongepowered.asm.mixin.injection.Redirect;
88

99
@Mixin(ServerChunkManager.class)
10-
public abstract class ServerChunkManagerMixin {
10+
public class ServerChunkManagerMixin {
1111

1212
@Redirect(method = "close", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;save(Z)V"))
1313
private void closeRedirect(ServerChunkManager serverChunkManager, boolean flush) {
14-
if(Client.saveOnQuit){
14+
if (FastReset.saveOnQuit) {
1515
serverChunkManager.save(flush);
1616
}
1717
}

0 commit comments

Comments
 (0)