Compare commits
No commits in common. "ea798c9cd713ce064e404a06b227b53c6a29a9bc" and "3185cfb26d0fe4d161a7d7dc8acb3b4da9cd9eb2" have entirely different histories.
ea798c9cd7
...
3185cfb26d
@ -1,14 +1,19 @@
|
|||||||
package dev.c0de.minecraft;
|
package dev.c0de.minecraft;
|
||||||
|
|
||||||
import dev.c0de.minecraft.config.SimpleConfig;
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
|
|
||||||
public class c0deFoxMod implements ModInitializer {
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public static SimpleConfig config;
|
public class c0deFoxMod implements ModInitializer {
|
||||||
|
public static final Logger LOGGER = LoggerFactory.getLogger("c0defox");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
config = new SimpleConfig("c0defox");
|
// 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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,56 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,47 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
package dev.c0de.minecraft.config;
|
|
||||||
|
|
||||||
// Configuration options for the client
|
|
||||||
public class ClientConfig {
|
|
||||||
public double FULLBRIGHT_GAMMA = 5.5;
|
|
||||||
}
|
|
@ -1,80 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
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,7 +1,6 @@
|
|||||||
package dev.c0de.minecraft.mixin;
|
package dev.c0de.minecraft.mixin;
|
||||||
|
|
||||||
// import dev.c0de.minecraft.c0deFoxMod;
|
import dev.c0de.minecraft.c0deFoxMod;
|
||||||
|
|
||||||
import net.minecraft.client.gui.screen.TitleScreen;
|
import net.minecraft.client.gui.screen.TitleScreen;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
@ -12,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
public class c0deFoxMixin {
|
public class c0deFoxMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "init()V")
|
@Inject(at = @At("HEAD"), method = "init()V")
|
||||||
private void init(CallbackInfo info) {
|
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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"category.c0defox.default": "c0de's mods",
|
|
||||||
"key.c0defox.fullbright": "Fullbright"
|
|
||||||
}
|
|
@ -6,7 +6,6 @@
|
|||||||
"mixins": [
|
"mixins": [
|
||||||
],
|
],
|
||||||
"client": [
|
"client": [
|
||||||
"BrightnessMixin",
|
|
||||||
"c0deFoxMixin"
|
"c0deFoxMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
@ -14,19 +14,16 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/c0defox/icon.png",
|
"icon": "assets/modid/icon.png",
|
||||||
|
|
||||||
"environment": "client",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"main": [
|
"main": [
|
||||||
"dev.c0de.minecraft.c0deFoxMod"
|
"dev.c0de.minecraft.c0deFoxMod"
|
||||||
],
|
|
||||||
"client": [
|
|
||||||
"dev.c0de.minecraft.client.c0deFoxModClient"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"c0defox.mixins.json"
|
"modid.mixins.json"
|
||||||
],
|
],
|
||||||
|
|
||||||
"depends": {
|
"depends": {
|
||||||
|
Loading…
Reference in New Issue
Block a user