mirror of
https://github.com/CompeyDev/elytra-lock-fabric.git
synced 2025-04-07 03:10:55 +01:00
feat: fall flying prevention & allow manual equip
* User can manually drag the elytra into their chestplate slot even when it is locked, although this would display a log * Locking the elytra now prevents fall flying if the user has it equipped at the time of lock
This commit is contained in:
parent
6e9cb2c04a
commit
14dd54adb8
3 changed files with 44 additions and 20 deletions
|
@ -8,8 +8,11 @@ import net.minecraft.item.Items;
|
||||||
import xyz.devcomp.elytralock.ElytraLock;
|
import xyz.devcomp.elytralock.ElytraLock;
|
||||||
|
|
||||||
public class ClientTickEndHandler implements EndTick {
|
public class ClientTickEndHandler implements EndTick {
|
||||||
|
private static boolean hasWarned = false;
|
||||||
|
|
||||||
public void onEndTick(MinecraftClient client) {
|
public void onEndTick(MinecraftClient client) {
|
||||||
if (client.isWindowFocused() && ElytraLock.isLocked() && client.player != null) {
|
if (ElytraLock.isLocked()) {
|
||||||
|
if (!hasWarned && client.isWindowFocused() && client.player != null) {
|
||||||
PlayerInventory inventory = client.player.getInventory();
|
PlayerInventory inventory = client.player.getInventory();
|
||||||
|
|
||||||
// 0 -> boots
|
// 0 -> boots
|
||||||
|
@ -17,18 +20,13 @@ public class ClientTickEndHandler implements EndTick {
|
||||||
// 2 -> chestplate
|
// 2 -> chestplate
|
||||||
// 3 -> helmet
|
// 3 -> helmet
|
||||||
ItemStack chestArmor = inventory.armor.get(2);
|
ItemStack chestArmor = inventory.armor.get(2);
|
||||||
|
|
||||||
if (chestArmor.isOf(Items.ELYTRA)) {
|
if (chestArmor.isOf(Items.ELYTRA)) {
|
||||||
ElytraLock.LOGGER.info("Detected player wearing elytra even though it's locked");
|
ElytraLock.LOGGER.info("Detected player wearing elytra even though it's locked");
|
||||||
ItemStack elytra = chestArmor.copyAndEmpty();
|
hasWarned = true;
|
||||||
int inventorySlot = inventory.getSwappableHotbarSlot();
|
}
|
||||||
|
}
|
||||||
boolean ok = inventory.insertStack(inventorySlot, elytra);
|
} else {
|
||||||
|
hasWarned = false;
|
||||||
if (!ok) {
|
|
||||||
ElytraLock.LOGGER.warn("Failed to remove equipped elytra, which is locked");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package xyz.devcomp.elytralock.mixin;
|
||||||
|
|
||||||
|
import xyz.devcomp.elytralock.ElytraLock;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
|
||||||
|
// TODO: In the future, make fall flying prevention and elytra lock separate
|
||||||
|
// Fall flying prevention should be subset of elytra locking which should be
|
||||||
|
// individually toggleable
|
||||||
|
|
||||||
|
@Mixin(PlayerEntity.class)
|
||||||
|
public class PlayerEntityMixin {
|
||||||
|
@Inject(method = "checkFallFlying()Z", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void preventFallFlying(CallbackInfoReturnable<Boolean> info) {
|
||||||
|
if (ElytraLock.isLocked()) {
|
||||||
|
ElytraLock.LOGGER.info("Elytra is locked, so preventing fall flying");
|
||||||
|
info.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,7 +3,8 @@
|
||||||
"package": "xyz.devcomp.elytralock.mixin",
|
"package": "xyz.devcomp.elytralock.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_17",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ClientPlayerInteractionManagerMixin"
|
"ClientPlayerInteractionManagerMixin",
|
||||||
|
"PlayerEntityMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|
Loading…
Add table
Reference in a new issue