forked from Rashnain/SaveMod
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveMod.java
More file actions
47 lines (40 loc) · 1.94 KB
/
SaveMod.java
File metadata and controls
47 lines (40 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package com.github.rashnain.savemod;
import com.github.rashnain.savemod.config.SaveModConfig;
import com.github.rashnain.savemod.gui.NameSaveScreen;
import com.github.rashnain.savemod.gui.SelectSaveScreen;
import com.mojang.blaze3d.platform.InputConstants;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.minecraft.client.KeyMapping;
import net.minecraft.resources.Identifier;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.file.Path;
public class SaveMod implements ClientModInitializer {
private static final String MOD_ID = "savemod";
public static final Logger LOGGER = LoggerFactory.getLogger("SaveMod");
public static final Path DIR = Path.of("savemod");
public static String worldDir;
@Override
public void onInitializeClient() {
KeyMapping.Category key_category = KeyMapping.Category.register(Identifier.fromNamespaceAndPath("savemod", "main"));
KeyMapping openList = KeyMappingHelper.registerKeyMapping(new KeyMapping("key.savemod.open_list", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, key_category));
KeyMapping save = KeyMappingHelper.registerKeyMapping(new KeyMapping("key.savemod.save", InputConstants.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, key_category));
ClientTickEvents.END_CLIENT_TICK.register(client -> {
if (openList.isDown() && client.hasSingleplayerServer())
client.setScreen(new SelectSaveScreen(null));
if (save.isDown() && client.hasSingleplayerServer())
client.setScreen(new NameSaveScreen(null, "", SaveMod.worldDir, saveName -> {
SelectSaveScreen saveScreen = new SelectSaveScreen(null);
client.setScreen(saveScreen);
saveScreen.save(saveName);
}));
});
SaveModConfig.load();
}
public static Identifier id(String path) {
return Identifier.fromNamespaceAndPath(MOD_ID, path);
}
}