feat: elytra unequip when locked but equipped

* Made the elytra get removed from the chestplate slot when it is
  locked, prevents user for dragging it into their chestplate when
  locked too
* Renamed config.Util to config.ConfigUtil
* Added placeholder locked & unlocked elytra textures to resources
This commit is contained in:
Erica Marigold 2024-05-21 16:50:00 +05:30
parent 3f3a3088fa
commit 2891b6ad51
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1
7 changed files with 45 additions and 16 deletions

View file

@ -1,7 +1,8 @@
package xyz.devcomp.elytralock;
import xyz.devcomp.elytralock.config.ConfigHandler;
import xyz.devcomp.elytralock.config.Util;
import xyz.devcomp.elytralock.config.ConfigUtil;
import xyz.devcomp.elytralock.events.ClientTickEndHandler;
import xyz.devcomp.elytralock.events.HudRenderHandler;
import org.lwjgl.glfw.GLFW;
@ -10,6 +11,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.loader.api.FabricLoader;
@ -27,7 +29,7 @@ public class ElytraLock implements ClientModInitializer {
@Override
public void onInitializeClient() {
LOGGER.info("Elytra lock initializing!");
LOGGER.info("ElytraLock initializing!");
lockKeybind = KeyBindingHelper.registerKeyBinding(
new KeyBinding("key.elytralock.lock", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_J, "category.elytralock"));
@ -35,7 +37,7 @@ public class ElytraLock implements ClientModInitializer {
client = MinecraftClient.getInstance();
if (Util.isYaclLoaded()) {
if (ConfigUtil.isYaclLoaded()) {
LOGGER.info("YACL_v3 is loaded, loading elytra toggle");
locked = new ConfigHandler().getInstance().toggle;
} else {
@ -43,6 +45,9 @@ public class ElytraLock implements ClientModInitializer {
}
HudRenderCallback.EVENT.register(new HudRenderHandler());
ClientTickEvents.END_CLIENT_TICK.register(new ClientTickEndHandler());
LOGGER.info("Registered HUD_RENDER & END_CLIENT_TICK events successfully!");
}
public static boolean isLocked() {

View file

@ -2,7 +2,7 @@ package xyz.devcomp.elytralock.config;
import xyz.devcomp.elytralock.ElytraLock;
public class Util {
public class ConfigUtil {
public static boolean isYaclLoaded() {
return ElytraLock.LOADER.isModLoaded("yet_another_config_lib_v3");
}

View file

@ -1,10 +0,0 @@
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
}
}

View file

@ -0,0 +1,34 @@
package xyz.devcomp.elytralock.events;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents.EndTick;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import xyz.devcomp.elytralock.ElytraLock;
public class ClientTickEndHandler implements EndTick {
public void onEndTick(MinecraftClient client) {
if (client.isWindowFocused() && ElytraLock.isLocked() && client.player != null) {
PlayerInventory inventory = client.player.getInventory();
// 0 -> boots
// 1 -> leggings
// 2 -> chestplate
// 3 -> helmet
ItemStack chestArmor = inventory.armor.get(2);
if (chestArmor.isOf(Items.ELYTRA)) {
ElytraLock.LOGGER.info("Detected player wearing elytra even though it's locked");
ItemStack elytra = chestArmor.copyAndEmpty();
int inventorySlot = inventory.getSwappableHotbarSlot();
boolean ok = inventory.insertStack(inventorySlot, elytra);
if (!ok) {
ElytraLock.LOGGER.warn("Failed to remove equipped elytra, which is locked");
}
}
}
}
}

View file

@ -1,7 +1,7 @@
package xyz.devcomp.elytralock.integrations;
import xyz.devcomp.elytralock.config.ConfigHandler;
import xyz.devcomp.elytralock.config.Util;
import xyz.devcomp.elytralock.config.ConfigUtil;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
import com.terraformersmc.modmenu.api.ModMenuApi;
@ -10,7 +10,7 @@ public class ModMenuIntegration implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return (parent) -> {
if (!Util.isYaclLoaded())
if (!ConfigUtil.isYaclLoaded())
return parent;
return new ConfigHandler().showGui(parent);
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB