mirror of
https://github.com/CompeyDev/elytra-lock-fabric.git
synced 2024-12-12 12:50:42 +00:00
feat: configuration & HUD indicator
This commit is contained in:
parent
365fe32645
commit
3f3a3088fa
13 changed files with 172 additions and 20 deletions
32
build.gradle
32
build.gradle
|
@ -3,7 +3,7 @@ plugins {
|
||||||
id 'maven-publish'
|
id 'maven-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
version = project.mod_version
|
version = "${project.mod_version}+${project.minecraft_version}"
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
base {
|
base {
|
||||||
|
@ -11,11 +11,24 @@ base {
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
// Add repositories to retrieve artifacts from in here.
|
mavenCentral()
|
||||||
// You should only use this when depending on other mods because
|
maven {
|
||||||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
|
// For ImageIO
|
||||||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
|
name "SonaType Maven"
|
||||||
// for more information about repositories.
|
url "https://oss.sonatype.org/content/repositories/snapshots"
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
// For YACL
|
||||||
|
name "Xander Maven"
|
||||||
|
url "https://maven.isxander.dev/releases"
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
// For modmenu
|
||||||
|
name "TerraformersMC Maven"
|
||||||
|
url "https://maven.terraformersmc.com/releases"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
|
@ -30,12 +43,13 @@ loom {
|
||||||
dependencies {
|
dependencies {
|
||||||
// To change the versions see the gradle.properties file
|
// To change the versions see the gradle.properties file
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
|
|
||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
|
||||||
|
modImplementation "dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_version}"
|
||||||
|
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|
|
@ -14,4 +14,6 @@ maven_group=xyz.devcomp
|
||||||
archives_base_name=elytra-lock
|
archives_base_name=elytra-lock
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
fabric_version=0.97.0+1.20.4
|
fabric_version=0.97.0+1.20.4
|
||||||
|
yacl_version=3.3.2+1.20.4
|
||||||
|
modmenu_version=9.0.0
|
|
@ -1,5 +1,9 @@
|
||||||
package xyz.devcomp.elytralock;
|
package xyz.devcomp.elytralock;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.config.ConfigHandler;
|
||||||
|
import xyz.devcomp.elytralock.config.Util;
|
||||||
|
import xyz.devcomp.elytralock.events.HudRenderHandler;
|
||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -7,16 +11,19 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import net.fabricmc.api.ClientModInitializer;
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.option.KeyBinding;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.client.util.InputUtil;
|
||||||
import net.minecraft.text.Text;
|
|
||||||
|
|
||||||
public class ElytraLock implements ClientModInitializer {
|
public class ElytraLock implements ClientModInitializer {
|
||||||
public static final Logger LOGGER = LoggerFactory.getLogger("Elytra Lock");
|
public static final Logger LOGGER = LoggerFactory.getLogger("Elytra Lock");
|
||||||
|
public static final FabricLoader LOADER = FabricLoader.getInstance();
|
||||||
private static KeyBinding lockKeybind;
|
private static KeyBinding lockKeybind;
|
||||||
private static boolean locked = false;
|
private static boolean locked = false;
|
||||||
private static MinecraftClient client;
|
public static MinecraftClient client;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitializeClient() {
|
public void onInitializeClient() {
|
||||||
|
@ -24,9 +31,18 @@ public class ElytraLock implements ClientModInitializer {
|
||||||
|
|
||||||
lockKeybind = KeyBindingHelper.registerKeyBinding(
|
lockKeybind = KeyBindingHelper.registerKeyBinding(
|
||||||
new KeyBinding("key.elytralock.lock", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_J, "category.elytralock"));
|
new KeyBinding("key.elytralock.lock", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_J, "category.elytralock"));
|
||||||
LOGGER.info("Registered keybind for elytra lock");
|
LOGGER.info("Registered keybind for locking elytra");
|
||||||
|
|
||||||
client = MinecraftClient.getInstance();
|
client = MinecraftClient.getInstance();
|
||||||
|
|
||||||
|
if (Util.isYaclLoaded()) {
|
||||||
|
LOGGER.info("YACL_v3 is loaded, loading elytra toggle");
|
||||||
|
locked = new ConfigHandler().getInstance().toggle;
|
||||||
|
} else {
|
||||||
|
LOGGER.warn("YACL_v3 is not loaded, not persisting elytra toggle");
|
||||||
|
}
|
||||||
|
|
||||||
|
HudRenderCallback.EVENT.register(new HudRenderHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLocked() {
|
public static boolean isLocked() {
|
||||||
|
@ -34,8 +50,6 @@ public class ElytraLock implements ClientModInitializer {
|
||||||
locked = !locked;
|
locked = !locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.inGameHud.getChatHud().addMessage(Text.translatable("elytralock.chat.lockedMessage"));
|
|
||||||
|
|
||||||
return locked;
|
return locked;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package xyz.devcomp.elytralock.config;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.ElytraLock;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
|
||||||
|
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
|
||||||
|
|
||||||
|
public class ConfigHandler {
|
||||||
|
private boolean isLoaded = false;
|
||||||
|
public static final ConfigClassHandler<ConfigModel> HANDLER = ConfigClassHandler.createBuilder(ConfigModel.class)
|
||||||
|
.id(new Identifier("elytralock", "config"))
|
||||||
|
.serializer(config -> GsonConfigSerializerBuilder.create(config)
|
||||||
|
.setPath(ElytraLock.LOADER.getConfigDir().resolve("elytra-lock.json"))
|
||||||
|
.setJson5(true)
|
||||||
|
.build())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
private void loadConfig() {
|
||||||
|
if (!this.isLoaded) {
|
||||||
|
ElytraLock.LOGGER.info("ElytraLock config not loaded, loading");
|
||||||
|
this.isLoaded = HANDLER.load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Screen showGui(Screen parent) {
|
||||||
|
this.loadConfig();
|
||||||
|
return HANDLER.generateGui().generateScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigModel getInstance() {
|
||||||
|
this.loadConfig();
|
||||||
|
return HANDLER.instance();
|
||||||
|
}
|
||||||
|
}
|
11
src/main/java/xyz/devcomp/elytralock/config/ConfigModel.java
Normal file
11
src/main/java/xyz/devcomp/elytralock/config/ConfigModel.java
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
package xyz.devcomp.elytralock.config;
|
||||||
|
|
||||||
|
import dev.isxander.yacl3.config.v2.api.SerialEntry;
|
||||||
|
import dev.isxander.yacl3.config.v2.api.autogen.*;
|
||||||
|
|
||||||
|
public class ConfigModel {
|
||||||
|
@SerialEntry(comment = "The status of the lock toggle")
|
||||||
|
@AutoGen(category = "elytralock")
|
||||||
|
@TickBox
|
||||||
|
public boolean toggle = false;
|
||||||
|
}
|
9
src/main/java/xyz/devcomp/elytralock/config/Util.java
Normal file
9
src/main/java/xyz/devcomp/elytralock/config/Util.java
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package xyz.devcomp.elytralock.config;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.ElytraLock;
|
||||||
|
|
||||||
|
public class Util {
|
||||||
|
public static boolean isYaclLoaded() {
|
||||||
|
return ElytraLock.LOADER.isModLoaded("yet_another_config_lib_v3");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package xyz.devcomp.elytralock.events;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
|
||||||
|
public class ClientTickEndEvent {
|
||||||
|
public void callbackHandler(MinecraftClient client) {
|
||||||
|
// Check if guy wearing elytra, if so, then remove
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package xyz.devcomp.elytralock.events;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.ElytraLock;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.util.Window;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class HudRenderHandler implements HudRenderCallback {
|
||||||
|
public static final int WIDTH = 16;
|
||||||
|
public static final int HEIGHT = 16;
|
||||||
|
|
||||||
|
public void onHudRender(DrawContext context, float delta) {
|
||||||
|
// FIXME: Perhaps don't check whether the elytra is locked on every frame
|
||||||
|
Identifier icon = new Identifier("elytra-lock",
|
||||||
|
"textures/gui/" + (ElytraLock.isLocked() ? "locked" : "unlocked") + ".png");
|
||||||
|
|
||||||
|
Window window = ElytraLock.client.getWindow();
|
||||||
|
int width = window.getScaledWidth(), height = window.getScaledHeight();
|
||||||
|
|
||||||
|
context.drawGuiTexture(icon, (width / 2) + 95, height - HEIGHT - 3, WIDTH, HEIGHT);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package xyz.devcomp.elytralock.integrations;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.config.ConfigHandler;
|
||||||
|
import xyz.devcomp.elytralock.config.Util;
|
||||||
|
|
||||||
|
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
|
||||||
|
import com.terraformersmc.modmenu.api.ModMenuApi;
|
||||||
|
|
||||||
|
public class ModMenuIntegration implements ModMenuApi {
|
||||||
|
@Override
|
||||||
|
public ConfigScreenFactory<?> getModConfigScreenFactory() {
|
||||||
|
return (parent) -> {
|
||||||
|
if (!Util.isYaclLoaded())
|
||||||
|
return parent;
|
||||||
|
return new ConfigHandler().showGui(parent);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ import net.minecraft.client.network.ClientPlayerInteractionManager;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.Hand;
|
import net.minecraft.util.Hand;
|
||||||
|
|
||||||
|
@ -28,6 +29,7 @@ public class ClientPlayerInteractionManagerMixin {
|
||||||
ItemStack itemStack = player.getStackInHand(hand);
|
ItemStack itemStack = player.getStackInHand(hand);
|
||||||
if (itemStack.isOf(Items.ELYTRA) && ElytraLock.isLocked()) {
|
if (itemStack.isOf(Items.ELYTRA) && ElytraLock.isLocked()) {
|
||||||
ElytraLock.LOGGER.info("Skipping sending PlayerInteractItemC2SPacket for locked elytra");
|
ElytraLock.LOGGER.info("Skipping sending PlayerInteractItemC2SPacket for locked elytra");
|
||||||
|
ElytraLock.client.inGameHud.getChatHud().addMessage(Text.translatable("elytralock.chat.lockedMessage"));
|
||||||
|
|
||||||
mutableObject.setValue(ActionResult.FAIL);
|
mutableObject.setValue(ActionResult.FAIL);
|
||||||
info.setReturnValue((ActionResult) mutableObject.getValue());
|
info.setReturnValue((ActionResult) mutableObject.getValue());
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
{
|
{
|
||||||
"category.elytralock": "Elytra Lock Keybinds",
|
"category.elytralock": "Elytra Lock Keybinds",
|
||||||
"key.elytralock.lock": "Lock elytra",
|
"key.elytralock.lock": "Lock elytra",
|
||||||
"elytralock.chat.lockedMessage": "[elytra-lock] Elytra is locked!"
|
|
||||||
|
"elytralock.chat.lockedMessage": "[elytra-lock] Elytra is locked!",
|
||||||
|
|
||||||
|
"yacl3.config.elytralock:config.toggle": "Toggle Elytra Lock",
|
||||||
|
"yacl3.config.elytralock:config.category.elytralock": "Elytra Lock"
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
"name": "elytra-lock",
|
"name": "elytra-lock",
|
||||||
"description": "A simple mod which registers a keybind to lock your elytra from usage when not required.",
|
"description": "A simple mod which registers a keybind to lock your elytra from usage when not required.",
|
||||||
"authors": [
|
"authors": [
|
||||||
"CompeyDev <hi@devcomp.xyz>"
|
"DevComp"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://fabricmc.net/",
|
"homepage": "https://fabricmc.net/",
|
||||||
|
@ -17,15 +17,22 @@
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"client": [
|
"client": [
|
||||||
"xyz.devcomp.elytralock.ElytraLock"
|
"xyz.devcomp.elytralock.ElytraLock"
|
||||||
|
],
|
||||||
|
"modmenu": [
|
||||||
|
"xyz.devcomp.elytralock.integrations.ModMenuIntegration"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"elytra-lock.mixins.json"
|
"elytra-lock.mixins.json"
|
||||||
],
|
],
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": "${loader_version}",
|
|
||||||
"minecraft": "${minecraft_version}",
|
|
||||||
"java": "${java_version}",
|
"java": "${java_version}",
|
||||||
"fabric-api": "*"
|
|
||||||
|
"minecraft": "${minecraft_version}",
|
||||||
|
|
||||||
|
"fabricloader": "${loader_version}",
|
||||||
|
"fabric-api": "*",
|
||||||
|
|
||||||
|
"yet_another_config_lib_v3": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue