-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1.19.x-dev' into 1.19.x-main
- Loading branch information
Showing
23 changed files
with
435 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/main/java/io/github/amerebagatelle/fabricskyboxes/config/FabricSkyBoxesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package io.github.amerebagatelle.fabricskyboxes.config; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import io.github.amerebagatelle.fabricskyboxes.FabricSkyBoxesClient; | ||
import io.github.amerebagatelle.fabricskyboxes.SkyboxManager; | ||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.text.Text; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.lang.reflect.Modifier; | ||
|
||
public class FabricSkyBoxesConfig { | ||
private static final Gson GSON = new GsonBuilder() | ||
.setPrettyPrinting() | ||
.excludeFieldsWithModifiers(Modifier.PRIVATE) | ||
.create(); | ||
public final GeneralSettings generalSettings = new GeneralSettings(); | ||
private final KeyBindingImpl keyBinding = new KeyBindingImpl(); | ||
private File file; | ||
|
||
public static FabricSkyBoxesConfig load(File file) { | ||
FabricSkyBoxesConfig config; | ||
if (file.exists()) { | ||
try (FileReader reader = new FileReader(file)) { | ||
config = GSON.fromJson(reader, FabricSkyBoxesConfig.class); | ||
} catch (Exception e) { | ||
FabricSkyBoxesClient.getLogger().error("Could not parse config, falling back to defaults!", e); | ||
config = new FabricSkyBoxesConfig(); | ||
} | ||
} else { | ||
config = new FabricSkyBoxesConfig(); | ||
} | ||
config.file = file; | ||
config.save(); | ||
|
||
return config; | ||
} | ||
|
||
public KeyBindingImpl getKeyBinding() { | ||
return this.keyBinding; | ||
} | ||
|
||
public void save() { | ||
File dir = this.file.getParentFile(); | ||
|
||
if (!dir.exists()) { | ||
if (!dir.mkdirs()) { | ||
throw new RuntimeException("Could not create parent directories"); | ||
} | ||
} else if (!dir.isDirectory()) { | ||
throw new RuntimeException("The parent file is not a directory"); | ||
} | ||
|
||
try (FileWriter writer = new FileWriter(this.file)) { | ||
GSON.toJson(this, writer); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Could not save configuration file", e); | ||
} | ||
} | ||
|
||
public static class GeneralSettings { | ||
public boolean enable = true; | ||
public int unexpectedTransitionDuration = 20; | ||
|
||
public boolean debugMode = false; | ||
} | ||
|
||
|
||
public static class KeyBindingImpl implements ClientTickEvents.EndTick { | ||
|
||
public final KeyBinding toggleFabricSkyBoxes; | ||
|
||
public KeyBindingImpl() { | ||
this.toggleFabricSkyBoxes = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_KP_0, "category.fabricskyboxes")); | ||
} | ||
|
||
@Override | ||
public void onEndTick(MinecraftClient client) { | ||
while (this.toggleFabricSkyBoxes.wasPressed()) { | ||
FabricSkyBoxesClient.config().generalSettings.enable = !FabricSkyBoxesClient.config().generalSettings.enable; | ||
FabricSkyBoxesClient.config().save(); | ||
SkyboxManager.getInstance().setEnabled(FabricSkyBoxesClient.config().generalSettings.enable); | ||
|
||
assert client.player != null; | ||
if (SkyboxManager.getInstance().isEnabled()) { | ||
client.player.sendMessage(Text.translatable("fabricskyboxes.message.enabled"), false); | ||
} else { | ||
client.player.sendMessage(Text.translatable("fabricskyboxes.message.disabled"), false); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.