Compare commits
9 Commits
3185cfb26d
...
ea798c9cd7
Author | SHA1 | Date | |
---|---|---|---|
ea798c9cd7 | |||
516baf4d29 | |||
4b36ec8748 | |||
e1ed1744ac | |||
c8190000f2 | |||
e3f7b1ae19 | |||
79c81d7772 | |||
2d12caf392 | |||
d98d040a64 |
@ -1,19 +1,14 @@
|
||||
package dev.c0de.minecraft;
|
||||
|
||||
import dev.c0de.minecraft.config.SimpleConfig;
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class c0deFoxMod implements ModInitializer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("c0defox");
|
||||
|
||||
public static SimpleConfig config;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
LOGGER.info("Hello world!");
|
||||
config = new SimpleConfig("c0defox");
|
||||
}
|
||||
}
|
||||
|
53
src/main/java/dev/c0de/minecraft/client/KeybindManager.java
Normal file
53
src/main/java/dev/c0de/minecraft/client/KeybindManager.java
Normal file
@ -0,0 +1,53 @@
|
||||
package dev.c0de.minecraft.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class KeybindManager {
|
||||
private final HashMap<String, Boolean> states = new HashMap<>();
|
||||
private final List<Module> modules;
|
||||
|
||||
public KeybindManager(List<Module> modules) {
|
||||
this.modules = modules;
|
||||
}
|
||||
|
||||
public void tick(MinecraftClient client) {
|
||||
// Execute the onTick function of each module
|
||||
modules.forEach(module -> module.onTick(this, client));
|
||||
|
||||
// Toggle the module state with keybind
|
||||
modules.stream().filter(module -> module.getKey() != null).forEach(module -> {
|
||||
if (module.getKey().wasPressed()) {
|
||||
final String name = module.getClass().getName();
|
||||
final boolean newState = states.get(name);
|
||||
|
||||
c0deFoxModClient.LOGGER.info(name);
|
||||
|
||||
states.put(name, !states.getOrDefault(name, false));
|
||||
|
||||
module.setState(newState);
|
||||
module.onToggle(this, client);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean getState(Class<?> cls) {
|
||||
return states.getOrDefault(cls.getName(), false);
|
||||
}
|
||||
|
||||
public TreeMap<String, Boolean> getSortedStates() {
|
||||
final TreeMap<String, Boolean> keyStates = new TreeMap<>();
|
||||
|
||||
states.forEach((key, value) -> {
|
||||
final Optional<Module> foundModule = modules.stream().filter(module -> module.getClass().getName().equals(key)).findFirst();
|
||||
|
||||
foundModule.ifPresent(module -> keyStates.put(module.getKey().getTranslationKey(), value));
|
||||
});
|
||||
|
||||
return keyStates;
|
||||
}
|
||||
}
|
30
src/main/java/dev/c0de/minecraft/client/Module.java
Normal file
30
src/main/java/dev/c0de/minecraft/client/Module.java
Normal file
@ -0,0 +1,30 @@
|
||||
package dev.c0de.minecraft.client;
|
||||
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
|
||||
public abstract class Module {
|
||||
|
||||
protected KeyBinding key;
|
||||
protected boolean state;
|
||||
|
||||
public void onTick(KeybindManager manager, MinecraftClient client) {
|
||||
|
||||
}
|
||||
|
||||
public void onToggle(KeybindManager manager, MinecraftClient client) {
|
||||
|
||||
}
|
||||
|
||||
public void setState(boolean state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public KeyBinding getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public boolean isState() {
|
||||
return state;
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
package dev.c0de.minecraft.client;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import dev.c0de.minecraft.client.modules.Fullbright;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class c0deFoxModClient implements ClientModInitializer {
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger("c0defox");
|
||||
|
||||
private static c0deFoxModClient self;
|
||||
private static KeybindManager keybindManager;
|
||||
|
||||
// Load in modules as independent parts of the mod
|
||||
private static List<Module> modules;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
ClientTickEvents.END_CLIENT_TICK.register(this::tick);
|
||||
|
||||
self = this;
|
||||
|
||||
// Add new modules here
|
||||
modules = List.of(
|
||||
new Fullbright()
|
||||
);
|
||||
|
||||
keybindManager = new KeybindManager(modules);
|
||||
|
||||
LOGGER.info("Ready");
|
||||
}
|
||||
|
||||
public static c0deFoxModClient getSelf() {
|
||||
return self;
|
||||
}
|
||||
|
||||
public static KeybindManager getKeybindManager() {
|
||||
return keybindManager;
|
||||
}
|
||||
|
||||
// Called on every game tick
|
||||
public void tick(MinecraftClient client) {
|
||||
keybindManager.tick(client);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package dev.c0de.minecraft.client.modules;
|
||||
|
||||
import dev.c0de.minecraft.c0deFoxMod;
|
||||
import dev.c0de.minecraft.client.Module;
|
||||
import dev.c0de.minecraft.client.c0deFoxModClient;
|
||||
import dev.c0de.minecraft.client.KeybindManager;
|
||||
|
||||
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;
|
||||
|
||||
public class Fullbright extends Module {
|
||||
double DEFAULT = 1.0;
|
||||
|
||||
public void FullBright() {
|
||||
this.key = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||
"key.c0defox.fullbright",
|
||||
InputUtil.Type.KEYSYM,
|
||||
GLFW.GLFW_KEY_B,
|
||||
"category.c0defox.default"
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(KeybindManager manager, MinecraftClient client) {
|
||||
update(client, DEFAULT);
|
||||
if (this.isState()) {
|
||||
c0deFoxModClient.LOGGER.warn("Active State");
|
||||
update(client, c0deFoxMod.config.getConfig().FULLBRIGHT_GAMMA);
|
||||
}
|
||||
}
|
||||
|
||||
private void update(MinecraftClient client, double value) {
|
||||
if (client == null) return;
|
||||
if (client.options.getGamma().getValue() == value) return;
|
||||
|
||||
c0deFoxModClient.LOGGER.warn("changing gamma");
|
||||
|
||||
client.options.getGamma().setValue(value);
|
||||
|
||||
if (client.player != null) client.player.sendMessage(Text.of(String.valueOf(value)), true);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package dev.c0de.minecraft.config;
|
||||
|
||||
// Configuration options for the client
|
||||
public class ClientConfig {
|
||||
public double FULLBRIGHT_GAMMA = 5.5;
|
||||
}
|
80
src/main/java/dev/c0de/minecraft/config/SimpleConfig.java
Normal file
80
src/main/java/dev/c0de/minecraft/config/SimpleConfig.java
Normal file
@ -0,0 +1,80 @@
|
||||
package dev.c0de.minecraft.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class SimpleConfig {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger("SimpleConfig");
|
||||
private boolean broken = false;
|
||||
private final File file;
|
||||
|
||||
private ClientConfig config = new ClientConfig();
|
||||
|
||||
public ClientConfig getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
public void createConfig() throws IOException {
|
||||
|
||||
// try creating missing files
|
||||
file.getParentFile().mkdirs();
|
||||
if (Files.notExists(file.toPath()))
|
||||
Files.createFile(file.toPath());
|
||||
|
||||
// write default config data
|
||||
Gson gson = new GsonBuilder()
|
||||
.enableComplexMapKeySerialization()
|
||||
.setPrettyPrinting()
|
||||
.create();
|
||||
|
||||
PrintWriter writer = new PrintWriter(file, StandardCharsets.UTF_8);
|
||||
gson.toJson(config, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void loadConfig() throws IOException {
|
||||
Gson gson = new Gson();
|
||||
Reader reader = Files.newBufferedReader(file.toPath());
|
||||
config = gson.fromJson(reader, ClientConfig.class);
|
||||
reader.close();
|
||||
}
|
||||
|
||||
public SimpleConfig(String modID) {
|
||||
Path path = FabricLoader.getInstance().getConfigDir();
|
||||
file = new File(path.toAbsolutePath().toString(), modID + ".json");
|
||||
|
||||
if (!file.exists()) {
|
||||
LOGGER.info(modID + " is missing, generating default one...");
|
||||
|
||||
try {
|
||||
createConfig();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error(modID + " failed to generate!");
|
||||
LOGGER.trace(e);
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!broken) {
|
||||
try {
|
||||
loadConfig();
|
||||
} catch (Exception e) {
|
||||
LOGGER.error(modID + " failed to load!");
|
||||
LOGGER.trace(e);
|
||||
broken = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
37
src/main/java/dev/c0de/minecraft/mixin/BrightnessMixin.java
Normal file
37
src/main/java/dev/c0de/minecraft/mixin/BrightnessMixin.java
Normal file
@ -0,0 +1,37 @@
|
||||
package dev.c0de.minecraft.mixin;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.client.option.SimpleOption;
|
||||
import net.minecraft.client.resource.language.I18n;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(SimpleOption.class)
|
||||
public class BrightnessMixin<T> {
|
||||
@Shadow @Final
|
||||
Text text;
|
||||
|
||||
@Shadow
|
||||
T value;
|
||||
|
||||
@Inject(method = "getCodec", at = @At("HEAD"), cancellable = true)
|
||||
private void returnFakeCodec(CallbackInfoReturnable<Codec<Double>> info) {
|
||||
if (text.getString().equals(I18n.translate("options.gamma"))) {
|
||||
info.setReturnValue(Codec.DOUBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "setValue", at = @At("HEAD"), cancellable = true)
|
||||
private void setRealValue(T value, CallbackInfo info) {
|
||||
if (text.getString().equals(I18n.translate("options.gamma"))) {
|
||||
this.value = value;
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package dev.c0de.minecraft.mixin;
|
||||
|
||||
import dev.c0de.minecraft.c0deFoxMod;
|
||||
// import dev.c0de.minecraft.c0deFoxMod;
|
||||
|
||||
import net.minecraft.client.gui.screen.TitleScreen;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
@ -11,7 +12,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public class c0deFoxMixin {
|
||||
@Inject(at = @At("HEAD"), method = "init()V")
|
||||
private void init(CallbackInfo info) {
|
||||
c0deFoxMod.LOGGER.info("This line is printed by an example mod mixin!");
|
||||
// c0deFoxMod.LOGGER.info("This line is printed by an example mod mixin!");
|
||||
}
|
||||
}
|
||||
|
||||
|
4
src/main/resources/assets/c0defox/lang/en_us.json
Normal file
4
src/main/resources/assets/c0defox/lang/en_us.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"category.c0defox.default": "c0de's mods",
|
||||
"key.c0defox.fullbright": "Fullbright"
|
||||
}
|
@ -6,6 +6,7 @@
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
"BrightnessMixin",
|
||||
"c0deFoxMixin"
|
||||
],
|
||||
"injectors": {
|
||||
|
@ -14,16 +14,19 @@
|
||||
},
|
||||
|
||||
"license": "MIT",
|
||||
"icon": "assets/modid/icon.png",
|
||||
"icon": "assets/c0defox/icon.png",
|
||||
|
||||
"environment": "*",
|
||||
"environment": "client",
|
||||
"entrypoints": {
|
||||
"main": [
|
||||
"dev.c0de.minecraft.c0deFoxMod"
|
||||
],
|
||||
"client": [
|
||||
"dev.c0de.minecraft.client.c0deFoxModClient"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"modid.mixins.json"
|
||||
"c0defox.mixins.json"
|
||||
],
|
||||
|
||||
"depends": {
|
||||
|
Loading…
Reference in New Issue
Block a user