mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 23:09:05 +00:00
Better Filename Handling for Abilities, Dash Directional Improvements, Fixed Duplicate Ability Name Handling
This commit is contained in:
1 parent
71dbf77def
commit
3de8cd49b6
23 files changed
+752
-178
No files matched your search
@@ -268,6 +268,15 @@ public abstract class AbstractDataAbilities {
|
||||
return currentAbility != null && currentAbility.isExecuting();
|
||||
}
|
||||
|
||||
/**
|
||||
* True when an executing ability grants invulnerability for its current phase.
|
||||
*/
|
||||
public boolean isCurrentAbilityInvulnerable() {
|
||||
return currentAbility != null
|
||||
&& currentAbility.isExecuting()
|
||||
&& currentAbility.isInvulnerableForCurrentPhase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently executing ability.
|
||||
*/
|
||||
|
||||
@@ -555,12 +555,15 @@ public class DataAbilities extends AbstractDataAbilities {
|
||||
* @return true if ability was interrupted
|
||||
*/
|
||||
public boolean onDamage(DamageSource source, float amount) {
|
||||
// Track hit for hit count condition
|
||||
recordHit();
|
||||
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
if (currentAbility.isInvulnerableForCurrentPhase()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Track hit for hit count condition
|
||||
recordHit();
|
||||
|
||||
net.minecraft.entity.Entity sourceEntity = source.getEntity();
|
||||
EntityLivingBase attacker = sourceEntity instanceof EntityLivingBase ? (EntityLivingBase) sourceEntity : null;
|
||||
|
||||
@@ -629,7 +629,12 @@ public class ScriptPlayerEventHandler {
|
||||
// Handle ability damage interactions (Guard counter, damage reduction)
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (pData != null && pData.abilityData != null && pData.abilityData.isExecutingAbility()) {
|
||||
event.ammount = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
if (pData.abilityData.isCurrentAbilityInvulnerable()) {
|
||||
event.ammount = 0;
|
||||
cancel = true;
|
||||
} else {
|
||||
event.ammount = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
}
|
||||
}
|
||||
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts((EntityPlayer) event.entityLiving);
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ClientAbilityState {
|
||||
public static boolean hasAbilityMovement = false;
|
||||
public static boolean positionLocked = false;
|
||||
public static boolean wasFlyingAtLock = false;
|
||||
public static boolean activePhase = false;
|
||||
public static float lockedYaw = 0;
|
||||
public static float lockedPitch = 0;
|
||||
|
||||
@@ -28,6 +29,7 @@ public class ClientAbilityState {
|
||||
hasAbilityMovement = (flags & PlayerAbilityStatePacket.FLAG_HAS_ABILITY_MOVEMENT) != 0;
|
||||
positionLocked = (flags & PlayerAbilityStatePacket.FLAG_POSITION_LOCKED) != 0;
|
||||
wasFlyingAtLock = (flags & PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK) != 0;
|
||||
activePhase = (flags & PlayerAbilityStatePacket.FLAG_ACTIVE_PHASE) != 0;
|
||||
lockedYaw = yaw;
|
||||
lockedPitch = pitch;
|
||||
}
|
||||
@@ -56,6 +58,7 @@ public class ClientAbilityState {
|
||||
hasAbilityMovement = false;
|
||||
positionLocked = false;
|
||||
wasFlyingAtLock = false;
|
||||
activePhase = false;
|
||||
lockedYaw = 0;
|
||||
lockedPitch = 0;
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ public class ClientTickHandler {
|
||||
private long buttonTime = 0L;
|
||||
private final int[] ignoreKeys = new int[]{157, 29, 54, 42, 184, 56, 220, 219};
|
||||
private boolean lastSpecialKeyDown = false;
|
||||
private boolean wasMovementSuppressed = false;
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
@@ -84,9 +85,15 @@ public class ClientTickHandler {
|
||||
lastSpecialKeyDown = specialKeyDown;
|
||||
}
|
||||
|
||||
boolean suppressMovement = mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput();
|
||||
if (!suppressMovement && wasMovementSuppressed) {
|
||||
syncMovementKeyStates(mc);
|
||||
}
|
||||
wasMovementSuppressed = suppressMovement;
|
||||
|
||||
// Suppress player input during ability-controlled phases.
|
||||
// Only suppress when no GUI screen is open (screens already capture input).
|
||||
if (mc.currentScreen == null && ClientAbilityState.shouldSuppressMovementInput()) {
|
||||
if (suppressMovement) {
|
||||
// Unpress movement keybinds at the source BEFORE updatePlayerMoveState() reads them.
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindForward.getKeyCode(), false);
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindBack.getKeyCode(), false);
|
||||
@@ -301,6 +308,27 @@ public class ClientTickHandler {
|
||||
|| keyCode == mc.gameSettings.keyBindSprint.getKeyCode();
|
||||
}
|
||||
|
||||
private void syncMovementKeyStates(Minecraft mc) {
|
||||
syncKeyBindingState(mc.gameSettings.keyBindForward);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindBack);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindLeft);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindRight);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindJump);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindSneak);
|
||||
syncKeyBindingState(mc.gameSettings.keyBindSprint);
|
||||
}
|
||||
|
||||
private void syncKeyBindingState(KeyBinding keyBinding) {
|
||||
int keyCode = keyBinding.getKeyCode();
|
||||
boolean pressed;
|
||||
if (keyCode < 0) {
|
||||
pressed = Mouse.isButtonDown(keyCode + 100);
|
||||
} else {
|
||||
pressed = Keyboard.isKeyDown(keyCode);
|
||||
}
|
||||
KeyBinding.setKeyBindState(keyCode, pressed);
|
||||
}
|
||||
|
||||
private boolean isIgnoredKey(int key) {
|
||||
int[] var2 = this.ignoreKeys;
|
||||
int var3 = var2.length;
|
||||
|
||||
@@ -84,8 +84,12 @@ public class SubGuiAbilitySaveConfirm extends SubGuiInterface implements ISubGui
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (subgui instanceof SubGuiDuplicateNameConfirm) {
|
||||
if (((SubGuiDuplicateNameConfirm) subgui).isConfirmed()) {
|
||||
SubGuiDuplicateNameConfirm confirm = (SubGuiDuplicateNameConfirm) subgui;
|
||||
if (confirm.isConfirmed()) {
|
||||
doSave();
|
||||
} else if (confirm.isBack()) {
|
||||
// Keep this save-confirm dialog open.
|
||||
return;
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,13 @@ import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
*/
|
||||
public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
|
||||
|
||||
private boolean confirmed = false;
|
||||
public enum Result {
|
||||
CONTINUE,
|
||||
BACK,
|
||||
CANCEL
|
||||
}
|
||||
|
||||
private Result result = Result.CANCEL;
|
||||
|
||||
public SubGuiDuplicateNameConfirm() {
|
||||
setBackground("menubg.png");
|
||||
@@ -26,22 +32,38 @@ public class SubGuiDuplicateNameConfirm extends SubGuiInterface {
|
||||
addLabel(new GuiNpcLabel(0, "ability.duplicate.name", guiLeft + 10, y));
|
||||
|
||||
y += 30;
|
||||
addButton(new GuiNpcButton(0, guiLeft + 20, y, 80, 20, "gui.continue"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 120, y, 80, 20, "gui.cancel"));
|
||||
addButton(new GuiNpcButton(0, guiLeft + 10, y, 65, 20, "gui.continue"));
|
||||
addButton(new GuiNpcButton(1, guiLeft + 78, y, 65, 20, "gui.back"));
|
||||
addButton(new GuiNpcButton(2, guiLeft + 146, y, 65, 20, "gui.cancel"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
if (guibutton.id == 0) {
|
||||
confirmed = true;
|
||||
result = Result.CONTINUE;
|
||||
close();
|
||||
} else if (guibutton.id == 1) {
|
||||
confirmed = false;
|
||||
result = Result.BACK;
|
||||
close();
|
||||
} else if (guibutton.id == 2) {
|
||||
result = Result.CANCEL;
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
public Result getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isConfirmed() {
|
||||
return confirmed;
|
||||
return result == Result.CONTINUE;
|
||||
}
|
||||
|
||||
public boolean isBack() {
|
||||
return result == Result.BACK;
|
||||
}
|
||||
|
||||
public boolean isCancelled() {
|
||||
return result == Result.CANCEL;
|
||||
}
|
||||
}
|
||||
@@ -245,6 +245,9 @@ public class GuiFieldBuilder {
|
||||
case STRING: {
|
||||
String sVal = def.getValue() != null ? def.getValue().toString() : "";
|
||||
GuiNpcTextField tf = new GuiNpcTextField(widgetId, parent, fontRenderer, fieldX, y, fieldW, 20, sVal);
|
||||
if ("gui.name".equals(def.getLabel())) {
|
||||
tf.setFileNameSafe();
|
||||
}
|
||||
if (!def.isEnabled()) tf.setEnabled(false);
|
||||
if (hover != null) tf.setHoverText(hover);
|
||||
sw.addTextField(tf);
|
||||
|
||||
@@ -104,7 +104,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
|
||||
// ==================== PENDING SAVE ====================
|
||||
private Ability pendingSaveAbility = null;
|
||||
private boolean pendingNewCreation = false;
|
||||
|
||||
// ==================== PENDING VARIANT ====================
|
||||
private String pendingTypeId = null;
|
||||
@@ -511,13 +510,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
Ability newAbility = AbilityController.Instance.create(pendingTypeId);
|
||||
if (newAbility != null) {
|
||||
gui.getVariants().get(idx).apply(newAbility);
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
pendingTypeId = null;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
pendingTypeId = null;
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
@@ -544,12 +536,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
if (variants.size() == 1) {
|
||||
variants.get(0).apply(newAbility);
|
||||
}
|
||||
if (hasDuplicateName(newAbility)) {
|
||||
pendingSaveAbility = newAbility;
|
||||
pendingNewCreation = true;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
openConfig(newAbility);
|
||||
return true;
|
||||
}
|
||||
@@ -561,27 +547,22 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
* @return true if a SubGui was opened (caller should return early, skipping initGui)
|
||||
*/
|
||||
private boolean handleDuplicateNameClosed(SubGuiDuplicateNameConfirm gui) {
|
||||
if (gui.isConfirmed() && pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
openConfig(pendingSaveAbility);
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
return true;
|
||||
} else {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
pendingSaveAbility = null;
|
||||
}
|
||||
} else if (pendingSaveAbility != null) {
|
||||
if (pendingNewCreation) {
|
||||
pendingSaveAbility = null;
|
||||
pendingNewCreation = false;
|
||||
} else {
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return true;
|
||||
}
|
||||
if (pendingSaveAbility == null) return false;
|
||||
|
||||
if (gui.isConfirmed()) {
|
||||
PacketClient.sendClient(new CustomAbilitySavePacket(pendingSaveAbility.writeNBT()));
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (gui.isBack()) {
|
||||
Ability ability = pendingSaveAbility;
|
||||
pendingSaveAbility = null;
|
||||
setSubGui(ability.createConfigGui(this));
|
||||
return true;
|
||||
}
|
||||
|
||||
pendingSaveAbility = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -590,7 +571,6 @@ public class GuiNpcManageAbilities extends GuiAbilityInterface
|
||||
*/
|
||||
private boolean handlePendingSave() {
|
||||
if (hasDuplicateName(pendingSaveAbility)) {
|
||||
pendingNewCreation = false;
|
||||
setSubGui(new SubGuiDuplicateNameConfirm());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.packets.player.ability.AbilityHotbarSelectPacket;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import noppes.npcs.client.ClientProxy;
|
||||
import noppes.npcs.client.ClientAbilityState;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
@@ -189,6 +190,7 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
|
||||
int centerX = overlayWidth / 2;
|
||||
int centerY = overlayHeight / 2;
|
||||
boolean activePhase = ClientAbilityState.activePhase;
|
||||
|
||||
// Compute text visibility: 0=Shown, 1=Hidden, 2=Held
|
||||
boolean showText;
|
||||
@@ -246,16 +248,16 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
|
||||
if (rawSlotIndex == -1) {
|
||||
// Deselect slot — draw empty marker
|
||||
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha);
|
||||
drawDeselectSlot(cx, cy, scaledSize, isCenter, slotAlpha, activePhase);
|
||||
} else {
|
||||
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText);
|
||||
slots[rawSlotIndex].drawCarousel(mc, sr, slotCooldown, cx, cy, scaledSize, isCenter, slotAlpha, showText, activePhase);
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha) {
|
||||
private void drawDeselectSlot(int cx, int cy, int size, boolean isCenter, float alpha, boolean activePhase) {
|
||||
float radius = size / 2f;
|
||||
float baseAlpha = isCenter ? 0.9f : 0.6f;
|
||||
float a = baseAlpha * alpha;
|
||||
@@ -268,7 +270,13 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
if (isCenter) {
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
GL11.glColor4f(0.65f, 0.14f, 0.14f, a);
|
||||
} else {
|
||||
GL11.glColor4f(0.38f, 0.10f, 0.10f, a);
|
||||
}
|
||||
} else if (isCenter) {
|
||||
GL11.glColor4f(0.5f, 0.2f, 0.2f, a);
|
||||
} else {
|
||||
GL11.glColor4f(0.3f, 0.3f, 0.3f, a);
|
||||
@@ -292,7 +300,13 @@ public class AbilityHotbarComponent extends HudComponent {
|
||||
}
|
||||
|
||||
// Draw X mark
|
||||
if (isCenter) {
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
GL11.glColor4f(1.0f, 0.45f, 0.35f, alpha);
|
||||
} else {
|
||||
GL11.glColor4f(0.75f, 0.30f, 0.30f, alpha * 0.8f);
|
||||
}
|
||||
} else if (isCenter) {
|
||||
GL11.glColor4f(0.8f, 0.4f, 0.4f, alpha);
|
||||
} else {
|
||||
GL11.glColor4f(0.5f, 0.5f, 0.5f, alpha * 0.8f);
|
||||
|
||||
@@ -48,7 +48,7 @@ public class AbilityHotbarSlotRenderer extends Gui {
|
||||
|
||||
public void drawCarousel(Minecraft mc, ScaledResolution sr, float cooldownProgress,
|
||||
int cx, int cy, int size, boolean isCenter, float slotAlpha,
|
||||
boolean showText) {
|
||||
boolean showText, boolean activePhase) {
|
||||
float nameAlpha = this.nameAlpha;
|
||||
boolean isHorizontal = ConfigClient.AbilityHotbarHorizontal;
|
||||
if (size <= 0 || slotAlpha <= 0) return;
|
||||
@@ -61,21 +61,54 @@ public class AbilityHotbarSlotRenderer extends Gui {
|
||||
|
||||
boolean altTexture = ConfigClient.AbilityHotbarAltTexture;
|
||||
|
||||
if (altTexture) {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.6f, 0.6f, 0.6f, 0.75f * alpha, false);
|
||||
float fillR;
|
||||
float fillG;
|
||||
float fillB;
|
||||
float outlineR;
|
||||
float outlineG;
|
||||
float outlineB;
|
||||
|
||||
if (activePhase) {
|
||||
if (isCenter) {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.8f, 0.8f, 0.2f, alpha, true);
|
||||
fillR = 0.95f;
|
||||
fillG = 0.26f;
|
||||
fillB = 0.22f;
|
||||
outlineR = 1.0f;
|
||||
outlineG = 0.52f;
|
||||
outlineB = 0.28f;
|
||||
} else {
|
||||
drawRoundedRect(-radius, -radius, radius, radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
|
||||
fillR = 0.36f;
|
||||
fillG = 0.14f;
|
||||
fillB = 0.14f;
|
||||
outlineR = 0.65f;
|
||||
outlineG = 0.22f;
|
||||
outlineB = 0.20f;
|
||||
}
|
||||
} else if (isCenter) {
|
||||
fillR = 0.8f;
|
||||
fillG = 0.8f;
|
||||
fillB = 0.2f;
|
||||
outlineR = 0.8f;
|
||||
outlineG = 0.8f;
|
||||
outlineB = 0.2f;
|
||||
} else {
|
||||
if (isCenter) {
|
||||
drawCircle(radius, 0.8f, 0.8f, 0.2f, 0.66f * alpha, false);
|
||||
drawCircle(radius, 0.8f, 0.8f, 0.2f, alpha, true);
|
||||
} else {
|
||||
drawCircle(radius, 1f, 1f, 1f, 0.66f * alpha, false);
|
||||
drawCircle(radius, 0.4f, 0.4f, 0.4f, alpha * 0.8f, true);
|
||||
}
|
||||
fillR = 0.4f;
|
||||
fillG = 0.4f;
|
||||
fillB = 0.4f;
|
||||
outlineR = 1f;
|
||||
outlineG = 1f;
|
||||
outlineB = 1f;
|
||||
}
|
||||
|
||||
if (altTexture) {
|
||||
float baseR = activePhase ? 0.30f : 0.6f;
|
||||
float baseG = activePhase ? 0.12f : 0.6f;
|
||||
float baseB = activePhase ? 0.12f : 0.6f;
|
||||
drawRoundedRect(-radius, -radius, radius, radius, baseR, baseG, baseB, 0.75f * alpha, false);
|
||||
drawRoundedRect(-radius, -radius, radius, radius, fillR, fillG, fillB, alpha * 0.8f, true);
|
||||
} else {
|
||||
drawCircle(radius, outlineR, outlineG, outlineB, 0.66f * alpha, false);
|
||||
drawCircle(radius, fillR, fillG, fillB, alpha * 0.8f, true);
|
||||
}
|
||||
|
||||
// Ability icon
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import kamkeel.npcs.util.FileNameHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -26,6 +27,7 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
public float minFloat = 0, maxFloat = Float.MAX_VALUE, defFloat = 0;
|
||||
protected static GuiNpcTextField activeTextfield = null;
|
||||
public boolean canEdit = true;
|
||||
private boolean fileNameSafe = false;
|
||||
public String hoverableText = "";
|
||||
private boolean wasHovered = false;
|
||||
private int hoverCount = 0;
|
||||
@@ -71,6 +73,11 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
public boolean textboxKeyTyped(char c, int i) {
|
||||
if (!canEdit || !isFocused())
|
||||
return false;
|
||||
|
||||
if (fileNameSafe && !GuiScreen.isCtrlKeyDown() && !isFileNameCharAllowed(c, i)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Allow Ctrl shortcuts (select all, copy, paste, cut) to bypass char filter
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
// For Ctrl+V (paste) on numeric fields, filter clipboard to valid chars
|
||||
@@ -87,7 +94,17 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.textboxKeyTyped(c, i);
|
||||
if (i == 47 && fileNameSafe) {
|
||||
String clipboard = GuiScreen.getClipboardString();
|
||||
if (clipboard != null) {
|
||||
String filtered = filterFileNameClipboard(clipboard);
|
||||
if (!filtered.isEmpty())
|
||||
writeText(filtered);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
boolean handled = super.textboxKeyTyped(c, i);
|
||||
return handled;
|
||||
}
|
||||
if (!charAllowed(c, i))
|
||||
return false;
|
||||
@@ -179,6 +196,9 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
else if (getFloat() > maxFloat)
|
||||
setText(maxFloat + "");
|
||||
}
|
||||
if (fileNameSafe) {
|
||||
normalizeFileNameText();
|
||||
}
|
||||
setCursorPositionZero();
|
||||
if (listener != null)
|
||||
listener.unFocused(this);
|
||||
@@ -238,6 +258,51 @@ public class GuiNpcTextField extends GuiTextField {
|
||||
return this;
|
||||
}
|
||||
|
||||
public GuiNpcTextField setFileNameSafe() {
|
||||
fileNameSafe = true;
|
||||
normalizeFileNameText();
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isSpecialNavigationKey(int keyCode) {
|
||||
for (int allowed : allowedSpecialChars) {
|
||||
if (allowed == keyCode) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isFileNameCharAllowed(char c, int keyCode) {
|
||||
if (isSpecialNavigationKey(keyCode) || c < 32) {
|
||||
return true;
|
||||
}
|
||||
return Character.isLetterOrDigit(c) || c == '_' || c == '-' || c == ' ';
|
||||
}
|
||||
|
||||
private String filterFileNameClipboard(String clipboard) {
|
||||
StringBuilder filtered = new StringBuilder(clipboard.length());
|
||||
for (int idx = 0; idx < clipboard.length(); idx++) {
|
||||
char c = clipboard.charAt(idx);
|
||||
if (Character.isLetterOrDigit(c) || c == '_' || c == '-') {
|
||||
filtered.append(c);
|
||||
} else if (Character.isWhitespace(c)) {
|
||||
filtered.append(' ');
|
||||
}
|
||||
}
|
||||
return filtered.toString();
|
||||
}
|
||||
|
||||
private void normalizeFileNameText() {
|
||||
String current = getText();
|
||||
String sanitized = FileNameHelper.sanitizeTextInput(current);
|
||||
if (sanitized.equals(current)) return;
|
||||
|
||||
int cursor = getCursorPosition();
|
||||
setText(sanitized);
|
||||
setCursorPosition(Math.min(cursor, sanitized.length()));
|
||||
}
|
||||
|
||||
public void setHoverText(String text) {
|
||||
this.hoverableText = StatCollector.translateToLocal(text);
|
||||
}
|
||||
|
||||
@@ -806,6 +806,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return amount;
|
||||
}
|
||||
if (currentAbility.isInvulnerableForCurrentPhase()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
net.minecraft.entity.Entity sourceEntity = source.getEntity();
|
||||
EntityLivingBase attacker = sourceEntity instanceof EntityLivingBase ? (EntityLivingBase) sourceEntity : null;
|
||||
@@ -937,6 +940,9 @@ public class PlayerAbilityData extends AbstractDataAbilities implements IPlayerA
|
||||
if (wasFlyingAtLock) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_WAS_FLYING_AT_LOCK;
|
||||
}
|
||||
if (currentAbility.getPhase() == AbilityPhase.ACTIVE) {
|
||||
flags |= PlayerAbilityStatePacket.FLAG_ACTIVE_PHASE;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
|
||||
@@ -659,6 +659,9 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
if (damagesource.damageType != null && damagesource.damageType.equals("outOfWorld") && isKilled()) {
|
||||
reset();
|
||||
}
|
||||
if (this.abilities != null && this.abilities.isCurrentAbilityInvulnerable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check for custom weapon attack speed - bypass immunity if enough time has passed
|
||||
Entity sourceEntity = damagesource.getEntity();
|
||||
|
||||
Reference in new issue
Block a user