mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 03:49:10 +00:00
Add flight checker to prevent abilities from affecting flying players
This commit is contained in:
1 parent
e722279009
commit
21b1571868
3 files changed
+24
-3
No files matched your search
@@ -9,8 +9,11 @@ import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.api.handler.IAbilityHandler;
|
||||
import noppes.npcs.util.NBTJsonUtil;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class AbilityController implements IAbilityHandler {
|
||||
@@ -26,6 +29,7 @@ public class AbilityController implements IAbilityHandler {
|
||||
private final Map<String, List<AbilityVariant>> externalVariants = new LinkedHashMap<>();
|
||||
private final List<IAbilityFieldProvider> fieldProviders = new ArrayList<>();
|
||||
private final List<IAbilityExtender> extenders = new ArrayList<>();
|
||||
private final List<Predicate<EntityPlayer>> flightCheckers = new ArrayList<>();
|
||||
|
||||
// ── Derived State ────────────────────────────────────────────────────────
|
||||
private final Set<String> builtInTypeIds = new HashSet<>();
|
||||
@@ -382,6 +386,18 @@ public class AbilityController implements IAbilityHandler {
|
||||
return extenders;
|
||||
}
|
||||
|
||||
public void registerFlightChecker(Predicate<EntityPlayer> checker) {
|
||||
flightCheckers.add(checker);
|
||||
}
|
||||
|
||||
public boolean isPlayerFlying(EntityPlayer player) {
|
||||
if (player.capabilities.isFlying) return true;
|
||||
for (Predicate<EntityPlayer> checker : flightCheckers) {
|
||||
if (checker.test(player)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire onAbilityStart on all extenders. Returns false if ANY extender cancels.
|
||||
*/
|
||||
|
||||
@@ -9,6 +9,7 @@ import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -106,7 +107,9 @@ public class ScriptPlayerEventHandler {
|
||||
Ability current = playerData.abilityData.getCurrentAbility();
|
||||
if (current == null || !current.hasAbilityMovement()) {
|
||||
player.motionX = 0;
|
||||
player.motionY = Math.min(player.motionY, 0); // Prevent jumping, allow gravity
|
||||
if (!AbilityController.Instance.isPlayerFlying(player)) {
|
||||
player.motionY = Math.min(player.motionY, 0);
|
||||
}
|
||||
player.motionZ = 0;
|
||||
player.velocityChanged = true;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import cpw.mods.fml.common.gameevent.InputEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import kamkeel.npcs.client.renderer.lightning.LightningBolt;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphManager;
|
||||
import kamkeel.npcs.network.PacketClient;
|
||||
import kamkeel.npcs.network.packets.player.CheckPlayerValue;
|
||||
@@ -133,9 +134,10 @@ public class ClientTickHandler {
|
||||
mc.thePlayer.motionZ = 0;
|
||||
}
|
||||
|
||||
// Prevent jumping: clamp upward motion when locked (allow gravity)
|
||||
// Prevent jumping when locked (allow gravity only if not flying)
|
||||
if ((ClientAbilityState.movementLocked || ClientAbilityState.positionLocked)
|
||||
&& !ClientAbilityState.hasAbilityMovement) {
|
||||
&& !ClientAbilityState.hasAbilityMovement
|
||||
&& !AbilityController.Instance.isPlayerFlying(mc.thePlayer)) {
|
||||
mc.thePlayer.motionY = Math.min(mc.thePlayer.motionY, 0);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user