2020-12-20 04:19:55 +00:00
|
|
|
package pm.j4.kerosene;
|
2020-12-19 23:30:50 +00:00
|
|
|
|
2020-12-23 00:51:20 +00:00
|
|
|
import java.util.Map;
|
2020-12-19 23:30:50 +00:00
|
|
|
import java.util.Optional;
|
|
|
|
import net.fabricmc.api.ModInitializer;
|
|
|
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
|
|
|
import net.minecraft.client.options.KeyBinding;
|
2020-12-20 04:19:55 +00:00
|
|
|
import pm.j4.kerosene.modules.ExampleModule;
|
|
|
|
import pm.j4.kerosene.modules.bindings.BindingManager;
|
|
|
|
import pm.j4.kerosene.util.config.ConfigHolder;
|
|
|
|
import pm.j4.kerosene.util.config.ConfigManager;
|
2020-12-22 21:19:02 +00:00
|
|
|
import pm.j4.kerosene.util.config.Module;
|
2020-12-22 19:32:27 +00:00
|
|
|
import pm.j4.kerosene.util.data.ModInfoProvider;
|
2020-12-20 04:19:55 +00:00
|
|
|
import pm.j4.kerosene.util.module.ModuleBase;
|
2020-12-23 00:51:20 +00:00
|
|
|
import pm.j4.kerosene.util.module.ModuleFunction;
|
2020-12-20 04:19:55 +00:00
|
|
|
|
|
|
|
|
2020-12-19 23:30:50 +00:00
|
|
|
/**
|
2020-12-20 04:19:55 +00:00
|
|
|
* The type Kerosene mod.
|
2020-12-19 23:30:50 +00:00
|
|
|
*/
|
2020-12-22 21:19:02 +00:00
|
|
|
|
|
|
|
@Module(ExampleModule.class)
|
|
|
|
@Module(BindingManager.class)
|
2020-12-20 04:19:55 +00:00
|
|
|
public class KeroseneMod implements ModInitializer {
|
2020-12-19 23:30:50 +00:00
|
|
|
@Override
|
|
|
|
public void onInitialize() {
|
|
|
|
|
2020-12-22 21:19:02 +00:00
|
|
|
ConfigManager.initConfig("kerosene", KeroseneMod.class);
|
2020-12-19 23:30:50 +00:00
|
|
|
|
2020-12-20 04:19:55 +00:00
|
|
|
Optional<ConfigHolder> conf = ConfigManager.getConfig("kerosene");
|
|
|
|
|
2020-12-19 23:30:50 +00:00
|
|
|
|
|
|
|
//initialize any keybinds, data, etc.
|
2020-12-22 19:32:27 +00:00
|
|
|
ModInfoProvider.getRegisteredMods().forEach(ModuleBase::init);
|
2020-12-19 23:30:50 +00:00
|
|
|
|
|
|
|
//initialize keybind handler
|
2020-12-23 00:51:20 +00:00
|
|
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
2020-12-22 19:32:27 +00:00
|
|
|
if (ModInfoProvider.client != client) {
|
|
|
|
ModInfoProvider.client = client;
|
2020-12-19 23:30:50 +00:00
|
|
|
}
|
2020-12-23 00:51:20 +00:00
|
|
|
Map<KeyBinding, ModuleFunction> binds = BindingManager.getActiveKeybinds();
|
|
|
|
binds.forEach((bind, func) -> {
|
|
|
|
while (bind.wasPressed()) {
|
|
|
|
Optional<ConfigHolder> config = ConfigManager.getConfig(func.getParent().getParent());
|
|
|
|
config.ifPresent(configHolder -> {
|
|
|
|
Map<KeyBinding, ModuleFunction> bindings = configHolder.globalConfig.bindings;
|
|
|
|
if (bindings.containsKey(bind)) {
|
|
|
|
bindings.get(bind).activate(client);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
System.out.println("binding function no longer present");
|
|
|
|
BindingManager.removeBind(bind);
|
|
|
|
}
|
|
|
|
});
|
2020-12-19 23:30:50 +00:00
|
|
|
}
|
2020-12-23 00:51:20 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//save any defaults that have been set
|
|
|
|
ConfigManager.saveEverything();
|
2020-12-19 23:30:50 +00:00
|
|
|
}
|
|
|
|
}
|