mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-24 11:44:25 +00:00
Merge remote-tracking branch 'origin/dev' into syntax-highlighter-unified
# Conflicts: # src/api # src/main/java/kamkeel/npcs/util/BukkitUtil.java # src/main/java/kamkeel/npcs/util/VaultUtil.java # src/main/java/noppes/npcs/CustomNpcsPermissions.java
This commit is contained in:
commit
ba7e4cc3b2
50 files changed
+2663
-766
No files matched your search
@@ -7,7 +7,6 @@ import kamkeel.npcs.util.BukkitUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
//import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
@@ -67,8 +66,8 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission GLOBAL_NATURALSPAWN = new Permission("customnpcs.global.naturalspawn");
|
||||
public static final Permission GLOBAL_TAG = new Permission("customnpcs.global.tag");
|
||||
public static final Permission GLOBAL_ANIMATION = new Permission("customnpcs.global.animation");
|
||||
public static final Permission GLOBAL_ABILITY = new Permission("customnpcs.global.ability");
|
||||
public static final Permission GLOBAL_MAGIC = new Permission("customnpcs.global.magic");
|
||||
public static final Permission GLOBAL_ABILITY = new Permission("customnpcs.global.ability");
|
||||
public static final Permission GLOBAL_EFFECT = new Permission("customnpcs.global.effect");
|
||||
|
||||
public static final Permission SPAWNER_MOB = new Permission("customnpcs.spawner.mob");
|
||||
@@ -112,11 +111,8 @@ public class CustomNpcsPermissions {
|
||||
public static final Permission PROFILE_REGION_BYPASS = new Permission("customnpcs.profile.region-bypass");
|
||||
public static final Permission PROFILE_MAX = new Permission("customnpcs.profile.max.*");
|
||||
|
||||
// Auction
|
||||
public static final Permission AUCTION_TRADES_MAX = new Permission("customnpcs.auction.trades.*");
|
||||
|
||||
public static CustomNpcsPermissions Instance;
|
||||
private static boolean isEnabled;
|
||||
private Method hasPermission;
|
||||
|
||||
public CustomNpcsPermissions() {
|
||||
Instance = this;
|
||||
@@ -132,16 +128,16 @@ public class CustomNpcsPermissions {
|
||||
}
|
||||
|
||||
try {
|
||||
Class.forName("org.bukkit.entity.Player").getMethod("hasPermission", String.class);
|
||||
isEnabled = true;
|
||||
|
||||
hasPermission = BukkitUtil.getPlayerClass().getMethod("hasPermission", String.class);
|
||||
LogManager.getLogger(CustomNpcs.class).info("Bukkit permissions enabled");
|
||||
LogManager.getLogger(CustomNpcs.class).info("Permissions available:");
|
||||
Collections.sort(Permission.permissions, String.CASE_INSENSITIVE_ORDER);
|
||||
for (String p : Permission.permissions) {
|
||||
LogManager.getLogger(CustomNpcs.class).info(p);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -175,13 +171,17 @@ public class CustomNpcsPermissions {
|
||||
}
|
||||
|
||||
private boolean bukkitPermission(String username, String permission) {
|
||||
if (!BukkitUtil.isEnabled() || !isEnabled) return false;
|
||||
if (hasPermission == null) return false;
|
||||
|
||||
try {
|
||||
Object player = BukkitUtil.getPlayer(username);
|
||||
if (player == null) return false;
|
||||
return false;//((Player) player).hasPermission(permission);
|
||||
} catch (Exception e) {
|
||||
return (Boolean) hasPermission.invoke(player, permission);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
@@ -206,6 +206,6 @@ public class CustomNpcsPermissions {
|
||||
}
|
||||
|
||||
public static boolean enabled() {
|
||||
return BukkitUtil.isEnabled() && isEnabled;
|
||||
return BukkitUtil.isEnabled();
|
||||
}
|
||||
}
|
||||
@@ -429,6 +429,14 @@ public class DataAbilities {
|
||||
playAbilityAnimation((Animation) AnimationController.Instance.get(animation));
|
||||
}
|
||||
|
||||
public void playAbilityAnimation(String animation) {
|
||||
if (animation.isEmpty()) return;
|
||||
if (AnimationController.Instance == null) return;
|
||||
if (AnimationController.Instance.get(animation, true) == null) return;
|
||||
|
||||
playAbilityAnimation((Animation) AnimationController.Instance.get(animation, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop any currently playing ability animation.
|
||||
*/
|
||||
@@ -501,18 +509,12 @@ public class DataAbilities {
|
||||
// Track hit for hit count condition
|
||||
recordHit();
|
||||
|
||||
// Check if currently executing a Guard ability and notify it of damage taken
|
||||
if (currentAbility instanceof AbilityGuard) {
|
||||
AbilityGuard guard = (AbilityGuard) currentAbility;
|
||||
if (guard.isGuarding() && source.getEntity() instanceof EntityLivingBase) {
|
||||
guard.onDamageTaken(npc, (EntityLivingBase) source.getEntity(), source, amount);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentAbility == null || !currentAbility.isExecuting()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
currentAbility.onDamageTaken(npc, (EntityLivingBase) source.getEntity(), source, amount);
|
||||
|
||||
if (currentAbility.canInterrupt(source)) {
|
||||
interruptCurrentAbility(source, amount);
|
||||
return true;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package noppes.npcs.ai;
|
||||
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -80,13 +81,14 @@ public class CombatHandler {
|
||||
}
|
||||
|
||||
// Handle guard counter before interruption
|
||||
if (npc.abilities.getCurrentAbility() instanceof kamkeel.npcs.controllers.data.ability.type.AbilityGuard) {
|
||||
kamkeel.npcs.controllers.data.ability.type.AbilityGuard guard =
|
||||
(kamkeel.npcs.controllers.data.ability.type.AbilityGuard) npc.abilities.getCurrentAbility();
|
||||
if (guard.isGuarding() && e instanceof EntityLivingBase) {
|
||||
guard.onDamageTaken(npc, (EntityLivingBase) e, source, damageAmount);
|
||||
}
|
||||
}
|
||||
|
||||
// if (npc.abilities.getCurrentAbility() instanceof AbilityGuard) {
|
||||
// AbilityGuard guard =
|
||||
// (AbilityGuard) npc.abilities.getCurrentAbility();
|
||||
// if (guard.isGuarding() && e instanceof EntityLivingBase) {
|
||||
// guard.onDamageTaken(npc, (EntityLivingBase) e, source, damageAmount);
|
||||
// }
|
||||
// }
|
||||
|
||||
// Check for ability interruption
|
||||
npc.abilities.onDamage(source, damageAmount);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package noppes.npcs.client.gui.advanced;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityEffect;
|
||||
import kamkeel.npcs.controllers.data.ability.Condition;
|
||||
import kamkeel.npcs.controllers.data.ability.gui.AbilityFieldBuilder;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.client.gui.builder.FieldType;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.StatCollector;
|
||||
@@ -55,7 +53,6 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
private int editingConditionIndex = -1;
|
||||
|
||||
private AbilityFieldBuilder builder;
|
||||
private FieldDef activeSubGuiField = null;
|
||||
|
||||
// Scroll position preservation per tab
|
||||
private float[] tabScrollY;
|
||||
@@ -65,7 +62,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
this.callback = callback;
|
||||
this.conditions = new ArrayList<>(ability.getConditions());
|
||||
|
||||
this.fieldDefs = ability.getAllFieldDefinitions();
|
||||
this.fieldDefs = ability.getAllDefinitions();
|
||||
discoverCustomTabs();
|
||||
|
||||
setBackground("menubg.png", 217);
|
||||
@@ -263,7 +260,6 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void buttonEvent(GuiButton guibutton) {
|
||||
int id = guibutton.id;
|
||||
|
||||
@@ -281,6 +277,20 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
if (id == -1000) { close(); return; }
|
||||
|
||||
// Condition buttons (50-80)
|
||||
if (handleConditionButton(id)) return;
|
||||
|
||||
// Declarative field handling (effects list, booleans, enums, sub-guis, clear buttons)
|
||||
if (builder.handleButtonEvent(id, guibutton)) {
|
||||
// SUB_GUI fields are opened directly by the builder via setSubGuiWithResult().
|
||||
// Only rebuild if no sub-gui was opened (e.g. boolean toggle, enum change).
|
||||
if (!hasSubGui()) {
|
||||
initGui();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean handleConditionButton(int id) {
|
||||
if (id >= 50 && id < 80) {
|
||||
int condIndex = (id - 50) / 10;
|
||||
int action = (id - 50) % 10;
|
||||
@@ -295,109 +305,16 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
if (id == 80) {
|
||||
if (conditions.size() < 3) {
|
||||
editingConditionIndex = conditions.size();
|
||||
setSubGui(new SubGuiConditionEdit(null));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear buttons (effects delete or SUB_GUI clear)
|
||||
if (id >= CLEAR_ID_START) {
|
||||
// Check effects list delete first
|
||||
int[] meta = builder.getEffectWidgetMeta().get(id);
|
||||
if (meta != null && meta[1] == 3) {
|
||||
FieldDef def = builder.getClearFieldMap().get(id);
|
||||
if (def != null && def.getType() == FieldType.EFFECTS_LIST) {
|
||||
handleEffectButton(def, meta, guibutton);
|
||||
return;
|
||||
}
|
||||
}
|
||||
// SUB_GUI clear
|
||||
FieldDef def = builder.getClearFieldMap().get(id);
|
||||
if (def != null && def.hasClearAction()) {
|
||||
def.getClearAction().run();
|
||||
initGui();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Declarative field buttons
|
||||
if (id >= DECLARATIVE_ID_START) {
|
||||
FieldDef def = builder.getButtonFieldMap().get(id);
|
||||
if (def == null) return;
|
||||
|
||||
// Effects list buttons (type, amp, add)
|
||||
int[] meta = builder.getEffectWidgetMeta().get(id);
|
||||
if (meta != null && def.getType() == FieldType.EFFECTS_LIST) {
|
||||
handleEffectButton(def, meta, guibutton);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (def.getType()) {
|
||||
case BOOLEAN:
|
||||
def.setValue(((GuiNpcButton) guibutton).getValue() == 1);
|
||||
initGui();
|
||||
break;
|
||||
case ENUM: {
|
||||
int idx = ((GuiNpcButton) guibutton).getValue();
|
||||
Class<? extends Enum<?>> ec = def.getEnumClass();
|
||||
if (ec != null) {
|
||||
Enum<?>[] constants = ec.getEnumConstants();
|
||||
if (idx >= 0 && idx < constants.length) def.setValue(constants[idx]);
|
||||
}
|
||||
initGui();
|
||||
break;
|
||||
}
|
||||
case STRING_ENUM: {
|
||||
int idx = ((GuiNpcButton) guibutton).getValue();
|
||||
String[] values = def.getStringEnumValues();
|
||||
if (values != null && idx >= 0 && idx < values.length) def.setStringEnumValue(values[idx]);
|
||||
initGui();
|
||||
break;
|
||||
}
|
||||
case SUB_GUI:
|
||||
activeSubGuiField = def;
|
||||
if (def.getSubGuiFactory() != null) setSubGui(def.getSubGuiFactory().get());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void handleEffectButton(FieldDef def, int[] meta, GuiButton btn) {
|
||||
List<AbilityEffect> effects = (List<AbilityEffect>) def.getValue();
|
||||
if (effects == null) return;
|
||||
int effectIdx = meta[0];
|
||||
int action = meta[1];
|
||||
|
||||
switch (action) {
|
||||
case 0: // Type changed
|
||||
if (effectIdx < effects.size()) {
|
||||
effects.get(effectIdx).setType(AbilityEffect.EffectType.fromOrdinal(((GuiNpcButton) btn).getValue()));
|
||||
}
|
||||
break;
|
||||
case 2: // Amp changed
|
||||
if (effectIdx < effects.size()) {
|
||||
effects.get(effectIdx).setAmplifier(((GuiNpcButton) btn).getValue());
|
||||
}
|
||||
break;
|
||||
case 3: // Delete
|
||||
if (effectIdx < effects.size()) {
|
||||
effects.remove(effectIdx);
|
||||
initGui();
|
||||
}
|
||||
break;
|
||||
case 4: // Add
|
||||
if (effects.size() < 5) {
|
||||
effects.add(new AbilityEffect(AbilityEffect.EffectType.SLOWNESS, 60, 0));
|
||||
initGui();
|
||||
}
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -405,38 +322,9 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void unFocused(GuiNpcTextField textField) {
|
||||
int id = textField.id;
|
||||
if (id < DECLARATIVE_ID_START) return;
|
||||
|
||||
// Check effects list duration fields
|
||||
int[] meta = builder.getEffectWidgetMeta().get(id);
|
||||
if (meta != null && meta[1] == 1) {
|
||||
FieldDef def = builder.getTextFieldMap().get(id);
|
||||
if (def != null && def.getType() == FieldType.EFFECTS_LIST) {
|
||||
List<AbilityEffect> effects = (List<AbilityEffect>) def.getValue();
|
||||
if (effects != null && meta[0] < effects.size()) {
|
||||
effects.get(meta[0]).setDurationTicks(textField.getInteger());
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
FieldDef def = builder.getTextFieldMap().get(id);
|
||||
if (def == null) return;
|
||||
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
try { def.setValue(Float.parseFloat(textField.getText())); } catch (NumberFormatException ignored) {}
|
||||
break;
|
||||
case INT:
|
||||
try { def.setValue(Integer.parseInt(textField.getText())); } catch (NumberFormatException ignored) {}
|
||||
break;
|
||||
case STRING:
|
||||
def.setValue(textField.getText());
|
||||
break;
|
||||
}
|
||||
if (textField.id < DECLARATIVE_ID_START) return;
|
||||
builder.handleTextFieldEvent(textField.id, textField);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════
|
||||
@@ -445,12 +333,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
|
||||
@Override
|
||||
public void subGuiClosed(SubGuiInterface subgui) {
|
||||
if (activeSubGuiField != null) {
|
||||
FieldDef def = activeSubGuiField;
|
||||
activeSubGuiField = null;
|
||||
if (def.getSubGuiResultHandler() != null) {
|
||||
def.getSubGuiResultHandler().accept(subgui);
|
||||
}
|
||||
if (builder.handleSubGuiClosed(subgui)) {
|
||||
initGui();
|
||||
return;
|
||||
}
|
||||
@@ -493,7 +376,7 @@ public class SubGuiAbilityConfig extends SubGuiInterface implements ITextfieldLi
|
||||
ability.readNBT(nbt);
|
||||
|
||||
this.conditions = new ArrayList<>(ability.getConditions());
|
||||
this.fieldDefs = ability.getAllFieldDefinitions();
|
||||
this.fieldDefs = ability.getAllDefinitions();
|
||||
discoverCustomTabs();
|
||||
initGui();
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
package noppes.npcs.client.gui.builder;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public enum ColumnHint {
|
||||
FULL,
|
||||
LEFT,
|
||||
RIGHT
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import noppes.npcs.client.gui.select.GuiAnimationSelection;
|
||||
import noppes.npcs.client.gui.select.GuiSoundSelection;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
@@ -24,12 +25,10 @@ public class FieldDef {
|
||||
private final String label;
|
||||
private final FieldType type;
|
||||
private String tab = null;
|
||||
private ColumnHint column = ColumnHint.FULL;
|
||||
private Supplier<Object> getter;
|
||||
private Consumer<Object> setter;
|
||||
private BooleanSupplier visibleWhen = () -> true;
|
||||
private BooleanSupplier enabledWhen = () -> true;
|
||||
private String tooltip = null;
|
||||
private String hoverText = null;
|
||||
|
||||
// Numeric range
|
||||
@@ -51,6 +50,10 @@ public class FieldDef {
|
||||
private Supplier<Integer> buttonTextColorSupplier;
|
||||
private Runnable clearAction;
|
||||
|
||||
// Row pairing (ROW type only)
|
||||
private FieldDef leftChild;
|
||||
private FieldDef rightChild;
|
||||
|
||||
private FieldDef(String label, FieldType type) {
|
||||
this.label = label;
|
||||
this.type = type;
|
||||
@@ -134,6 +137,17 @@ public class FieldDef {
|
||||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a two-column row pairing two fields side by side.
|
||||
* If one child is hidden (via visibleWhen), the other renders full-width.
|
||||
*/
|
||||
public static FieldDef row(FieldDef left, FieldDef right) {
|
||||
FieldDef def = new FieldDef("", FieldType.ROW);
|
||||
def.leftChild = left;
|
||||
def.rightChild = right;
|
||||
return def;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// CONVENIENCE FACTORIES (SUB_GUI wrappers)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
@@ -206,8 +220,13 @@ public class FieldDef {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldDef column(ColumnHint column) {
|
||||
this.column = column;
|
||||
public FieldDef min(float min) {
|
||||
this.min = min;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldDef max(float max) {
|
||||
this.max = max;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -221,11 +240,6 @@ public class FieldDef {
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldDef tooltip(String tooltip) {
|
||||
this.tooltip = tooltip;
|
||||
return this;
|
||||
}
|
||||
|
||||
public FieldDef hover(String hoverText) {
|
||||
this.hoverText = hoverText;
|
||||
return this;
|
||||
@@ -253,10 +267,8 @@ public class FieldDef {
|
||||
public String getLabel() { return label; }
|
||||
public FieldType getType() { return type; }
|
||||
public String getTab() { return tab; }
|
||||
public ColumnHint getColumn() { return column; }
|
||||
public boolean isVisible() { return visibleWhen.getAsBoolean(); }
|
||||
public boolean isEnabled() { return enabledWhen.getAsBoolean(); }
|
||||
public String getTooltip() { return tooltip; }
|
||||
public String getHoverText() { return hoverText; }
|
||||
public float getMin() { return min; }
|
||||
public float getMax() { return max; }
|
||||
@@ -293,4 +305,77 @@ public class FieldDef {
|
||||
return buttonTextColorSupplier != null ? buttonTextColorSupplier.get() : null;
|
||||
}
|
||||
|
||||
public FieldDef getLeftChild() { return leftChild; }
|
||||
public FieldDef getRightChild() { return rightChild; }
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// LIST MANIPULATION (for mod injection)
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Insert a field before the first field matching the target label.
|
||||
* Searches top-level labels and ROW children.
|
||||
*
|
||||
* @param fields The field list to modify
|
||||
* @param targetLabel The label of the field to insert before
|
||||
* @param newField The field to insert
|
||||
* @return true if the target was found and the field was inserted
|
||||
*/
|
||||
public static boolean insertBefore(java.util.List<FieldDef> fields, String targetLabel, FieldDef newField) {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
if (matchesLabel(fields.get(i), targetLabel)) {
|
||||
fields.add(i, newField);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a field after the first field matching the target label.
|
||||
* Searches top-level labels and ROW children.
|
||||
*
|
||||
* @param fields The field list to modify
|
||||
* @param targetLabel The label of the field to insert after
|
||||
* @param newField The field to insert
|
||||
* @return true if the target was found and the field was inserted
|
||||
*/
|
||||
public static boolean insertAfter(List<FieldDef> fields, String targetLabel, FieldDef newField) {
|
||||
for (int i = 0; i < fields.size(); i++) {
|
||||
if (matchesLabel(fields.get(i), targetLabel)) {
|
||||
fields.add(i + 1, newField);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the visibility condition of a field.
|
||||
* Searches top-level labels and ROW children.
|
||||
*
|
||||
* @param fields The field list to modify
|
||||
* @param targetLabel The label of the field to modify
|
||||
* @param condition The condition to replace
|
||||
* @return true if the target was found and the condition was modified
|
||||
*/
|
||||
public static boolean modifyVisibility(List<FieldDef> fields, String targetLabel, BooleanSupplier condition) {
|
||||
for (FieldDef field : fields) {
|
||||
if (matchesLabel(field, targetLabel)) {
|
||||
field.visibleWhen(condition);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean matchesLabel(FieldDef def, String targetLabel) {
|
||||
if (targetLabel.equals(def.label)) return true;
|
||||
if (def.type == FieldType.ROW) {
|
||||
if (def.leftChild != null && targetLabel.equals(def.leftChild.label)) return true;
|
||||
if (def.rightChild != null && targetLabel.equals(def.rightChild.label)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,5 +14,6 @@ public enum FieldType {
|
||||
STRING,
|
||||
SECTION_HEADER,
|
||||
LABEL,
|
||||
EFFECTS_LIST
|
||||
EFFECTS_LIST,
|
||||
ROW
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package noppes.npcs.client.gui.builder;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
||||
import noppes.npcs.client.gui.util.GuiNpcButton;
|
||||
@@ -10,6 +11,7 @@ import noppes.npcs.client.gui.util.GuiNpcButtonYesNo;
|
||||
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
||||
import noppes.npcs.client.gui.util.GuiNpcTextField;
|
||||
import noppes.npcs.client.gui.util.GuiScrollWindow;
|
||||
import noppes.npcs.client.gui.util.SubGuiInterface;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -19,8 +21,8 @@ import java.util.Map;
|
||||
* General-purpose builder that converts a list of {@link FieldDef} into positioned
|
||||
* GUI widgets inside a {@link GuiScrollWindow}.
|
||||
* <p>
|
||||
* Supports 1-column and 2-column layouts. Subclasses can override {@link #buildField}
|
||||
* to handle custom field types.
|
||||
* Uses {@link FieldDef#row(FieldDef, FieldDef)} for two-column layouts.
|
||||
* Subclasses can override {@link #buildField} to handle custom field types.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class GuiFieldBuilder {
|
||||
@@ -36,9 +38,6 @@ public class GuiFieldBuilder {
|
||||
protected int rowHeight = 24;
|
||||
protected int labelPadding = 8;
|
||||
|
||||
// Column mode
|
||||
protected int columnCount = 2;
|
||||
|
||||
// Dependencies
|
||||
protected final GuiNPCInterface parent;
|
||||
protected GuiScrollWindow sw;
|
||||
@@ -71,7 +70,6 @@ public class GuiFieldBuilder {
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public GuiFieldBuilder scrollWindowId(int id) { this.scrollWindowId = id; return this; }
|
||||
public GuiFieldBuilder columns(int count) { this.columnCount = Math.max(1, Math.min(2, count)); return this; }
|
||||
public GuiFieldBuilder contentRight(int v) { this.contentRight = v; return this; }
|
||||
public GuiFieldBuilder startIds(int widget, int clear, int label) {
|
||||
this.widgetId = widget; this.clearId = clear; this.labelId = label; return this;
|
||||
@@ -125,38 +123,37 @@ public class GuiFieldBuilder {
|
||||
// Section header
|
||||
if (def.getType() == FieldType.SECTION_HEADER) {
|
||||
y += 3;
|
||||
String sectionText = StatCollector.translateToLocal(def.getLabel());
|
||||
if (def.getTooltip() != null && !def.getTooltip().isEmpty()) {
|
||||
sectionText += " (" + StatCollector.translateToLocal(def.getTooltip()) + ")";
|
||||
GuiNpcLabel sectionLabel = new GuiNpcLabel(labelId++, def.getLabel(), colLLabel, y + 2, 0xFFFF55);
|
||||
if (def.getHoverText() != null && !def.getHoverText().isEmpty()) {
|
||||
sectionLabel.setHoverText(def.getHoverText());
|
||||
}
|
||||
sw.addLabel(new GuiNpcLabel(labelId++, sectionText, colLLabel, y + 2, 0xFFFF55));
|
||||
sw.addLabel(sectionLabel);
|
||||
y += 15;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Two-column pair: LEFT followed by RIGHT (only in 2-column mode)
|
||||
if (columnCount == 2
|
||||
&& def.getColumn() == ColumnHint.LEFT
|
||||
&& i + 1 < fields.size()
|
||||
&& fields.get(i + 1).getColumn() == ColumnHint.RIGHT
|
||||
&& fields.get(i + 1).getType() != FieldType.SECTION_HEADER) {
|
||||
renderFieldAt(def, colLLabel, colLField, colLWidth, y);
|
||||
// ROW: explicit two-column pair
|
||||
if (def.getType() == FieldType.ROW) {
|
||||
FieldDef left = def.getLeftChild();
|
||||
FieldDef right = def.getRightChild();
|
||||
boolean leftVis = left != null && left.isVisible();
|
||||
boolean rightVis = right != null && right.isVisible();
|
||||
|
||||
i++;
|
||||
FieldDef rightDef = fields.get(i);
|
||||
renderFieldAt(rightDef, colRLabel, colRField, colRWidth, y);
|
||||
|
||||
y += rowHeight;
|
||||
} else {
|
||||
// Full-width: compute fieldX from label pixel width
|
||||
int fieldW = getFullFieldWidth(def);
|
||||
String translated = StatCollector.translateToLocal(def.getLabel());
|
||||
int labelW = fontRenderer.getStringWidth(translated);
|
||||
int fieldX = colLLabel + labelW + labelPadding;
|
||||
|
||||
renderFieldAt(def, colLLabel, fieldX, fieldW, y);
|
||||
y += rowHeight;
|
||||
if (leftVis && rightVis) {
|
||||
renderFieldAt(left, colLLabel, colLField, colLWidth, y);
|
||||
renderFieldAt(right, colRLabel, colRField, colRWidth, y);
|
||||
} else if (leftVis) {
|
||||
renderFullWidth(left, y);
|
||||
} else if (rightVis) {
|
||||
renderFullWidth(right, y);
|
||||
}
|
||||
if (leftVis || rightVis) y += rowHeight;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Full-width field
|
||||
renderFullWidth(def, y);
|
||||
y += rowHeight;
|
||||
}
|
||||
|
||||
lastBuildY = y;
|
||||
@@ -182,9 +179,12 @@ public class GuiFieldBuilder {
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
protected void renderFieldAt(FieldDef def, int labelX, int fieldX, int fieldW, int y) {
|
||||
sw.addLabel(new GuiNpcLabel(labelId++, def.getLabel(), labelX, y + 5, 0xFFFFFF));
|
||||
|
||||
String hover = def.getHoverText() != null ? def.getHoverText() : def.getTooltip();
|
||||
GuiNpcLabel fieldLabel = new GuiNpcLabel(labelId++, def.getLabel(), labelX, y + 5, 0xFFFFFF);
|
||||
String hover = def.getHoverText();
|
||||
if (hover != null && !hover.isEmpty()) {
|
||||
fieldLabel.setHoverText(hover);
|
||||
}
|
||||
sw.addLabel(fieldLabel);
|
||||
|
||||
switch (def.getType()) {
|
||||
case FLOAT: {
|
||||
@@ -307,6 +307,14 @@ public class GuiFieldBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFullWidth(FieldDef def, int y) {
|
||||
int fieldW = getFullFieldWidth(def);
|
||||
String translated = StatCollector.translateToLocal(def.getLabel());
|
||||
int labelW = fontRenderer.getStringWidth(translated);
|
||||
int fieldX = colLLabel + labelW + labelPadding;
|
||||
renderFieldAt(def, colLLabel, fieldX, fieldW, y);
|
||||
}
|
||||
|
||||
protected int getFullFieldWidth(FieldDef def) {
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
@@ -321,6 +329,101 @@ public class GuiFieldBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// EVENT HANDLING
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Handles button events for declarative fields.
|
||||
* Call from parent GUI's buttonEvent(). Returns true if the event was handled.
|
||||
* <p>
|
||||
* For SUB_GUI fields, the sub-gui is opened directly via {@code parent.setSubGuiWithResult()},
|
||||
* so the result handler survives initGui() rebuilds. After this returns true, check
|
||||
* {@code parent.hasSubGui()} to determine if initGui() should be called.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public boolean handleButtonEvent(int buttonId, GuiButton button) {
|
||||
// Check clear buttons first
|
||||
if (clearFieldMap.containsKey(buttonId)) {
|
||||
FieldDef def = clearFieldMap.get(buttonId);
|
||||
if (def != null && def.hasClearAction()) {
|
||||
def.getClearAction().run();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check field buttons
|
||||
FieldDef def = buttonFieldMap.get(buttonId);
|
||||
if (def == null) return false;
|
||||
|
||||
switch (def.getType()) {
|
||||
case BOOLEAN:
|
||||
def.setValue(((GuiNpcButton) button).getValue() == 1);
|
||||
return true;
|
||||
case ENUM: {
|
||||
int idx = ((GuiNpcButton) button).getValue();
|
||||
Class<? extends Enum<?>> ec = def.getEnumClass();
|
||||
if (ec != null) {
|
||||
Enum<?>[] constants = ec.getEnumConstants();
|
||||
if (idx >= 0 && idx < constants.length) def.setValue(constants[idx]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case STRING_ENUM: {
|
||||
int idx = ((GuiNpcButton) button).getValue();
|
||||
String[] values = def.getStringEnumValues();
|
||||
if (values != null && idx >= 0 && idx < values.length) def.setStringEnumValue(values[idx]);
|
||||
return true;
|
||||
}
|
||||
case SUB_GUI:
|
||||
if (def.getSubGuiFactory() != null) {
|
||||
parent.setSubGuiWithResult(def.getSubGuiFactory().get(), sub -> {
|
||||
if (def.getSubGuiResultHandler() != null) {
|
||||
def.getSubGuiResultHandler().accept(sub);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles text field unfocus events for declarative fields.
|
||||
* Call from parent GUI's unFocused(). Returns true if the event was handled.
|
||||
*/
|
||||
public boolean handleTextFieldEvent(int textFieldId, GuiNpcTextField field) {
|
||||
FieldDef def = textFieldMap.get(textFieldId);
|
||||
if (def == null) return false;
|
||||
|
||||
switch (def.getType()) {
|
||||
case FLOAT:
|
||||
try { def.setValue(Float.parseFloat(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
case INT:
|
||||
try { def.setValue(Integer.parseInt(field.getText())); } catch (NumberFormatException ignored) {}
|
||||
return true;
|
||||
case STRING:
|
||||
def.setValue(field.getText());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sub-gui close events. Call from parent GUI's subGuiClosed().
|
||||
* <p>
|
||||
* Note: SUB_GUI fields opened via handleButtonEvent use
|
||||
* {@code parent.setSubGuiWithResult()}, so their results are handled
|
||||
* automatically by {@code GuiNPCInterface.closeSubGui()}. This method
|
||||
* only handles sub-guis opened through other means.
|
||||
*/
|
||||
public boolean handleSubGuiClosed(SubGuiInterface subgui) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// GETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public abstract class GuiNPCInterface extends GuiScreen {
|
||||
@@ -52,6 +53,7 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
public Supplier<Boolean> closeOnEscSupplier = null;
|
||||
public int guiLeft, guiTop, xSize, ySize;
|
||||
private SubGuiInterface subgui;
|
||||
private Consumer<SubGuiInterface> pendingSubGuiResult;
|
||||
public int mouseX, mouseY, mouseScroll;
|
||||
public float bgScale = 1;
|
||||
public float bgScaleX = 1;
|
||||
@@ -518,7 +520,21 @@ public abstract class GuiNPCInterface extends GuiScreen {
|
||||
initGui();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a sub-gui with a result handler that will be called when the sub-gui closes.
|
||||
* The handler survives initGui() rebuilds since it lives on the parent, not the builder.
|
||||
*/
|
||||
public void setSubGuiWithResult(SubGuiInterface gui, Consumer<SubGuiInterface> resultHandler) {
|
||||
this.pendingSubGuiResult = resultHandler;
|
||||
setSubGui(gui);
|
||||
}
|
||||
|
||||
public void closeSubGui(SubGuiInterface gui) {
|
||||
if (pendingSubGuiResult != null) {
|
||||
Consumer<SubGuiInterface> handler = pendingSubGuiResult;
|
||||
pendingSubGuiResult = null;
|
||||
handler.accept(gui);
|
||||
}
|
||||
subgui = null;
|
||||
initGui();
|
||||
}
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
package noppes.npcs.client.gui.util;
|
||||
|
||||
import kamkeel.npcs.util.TextSplitter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import noppes.npcs.client.CustomNpcResourceListener;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public class GuiNpcLabel {
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiNpcLabel extends Gui {
|
||||
public String label;
|
||||
public int x, y, color;
|
||||
public boolean enabled = true;
|
||||
public int id;
|
||||
public boolean drawShadow = false;
|
||||
|
||||
// Hover text support
|
||||
public String hoverableText = "";
|
||||
private boolean wasHovered = false;
|
||||
private int hoverCount = 0;
|
||||
|
||||
public GuiNpcLabel(int id, Object label, int x, int y, int color) {
|
||||
this.id = id;
|
||||
this.label = StatCollector.translateToLocal(label.toString());
|
||||
@@ -25,6 +39,10 @@ public class GuiNpcLabel {
|
||||
this(id, label, x, y, CustomNpcResourceListener.DefaultTextColor);
|
||||
}
|
||||
|
||||
public void setHoverText(String text) {
|
||||
this.hoverableText = text;
|
||||
}
|
||||
|
||||
public void drawLabel(GuiScreen gui, FontRenderer fontRenderer) {
|
||||
if (enabled)
|
||||
fontRenderer.drawString(label, x, y, color, drawShadow);
|
||||
@@ -34,4 +52,119 @@ public class GuiNpcLabel {
|
||||
int size = Minecraft.getMinecraft().fontRenderer.getStringWidth(label);
|
||||
x += (width - size) / 2;
|
||||
}
|
||||
|
||||
public boolean isMouseOver(int mouseX, int mouseY, FontRenderer fr) {
|
||||
int width = fr.getStringWidth(label);
|
||||
return mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws hover tooltip if the mouse is over this label.
|
||||
* @param localMouseX Mouse X in scroll-local coordinates (for hit testing)
|
||||
* @param localMouseY Mouse Y in scroll-local coordinates (for hit testing)
|
||||
* @param screenMouseX Mouse X in screen coordinates (for tooltip positioning)
|
||||
* @param screenMouseY Mouse Y in screen coordinates (for tooltip positioning)
|
||||
* @param hasSubGui Whether a sub-gui is open
|
||||
* @param fr FontRenderer for measuring label width
|
||||
*/
|
||||
public void drawHover(int localMouseX, int localMouseY, int screenMouseX, int screenMouseY, boolean hasSubGui, FontRenderer fr) {
|
||||
if (hasSubGui || hoverableText.isEmpty()) return;
|
||||
|
||||
boolean hovered = isMouseOver(localMouseX, localMouseY, fr);
|
||||
if (!hovered) {
|
||||
wasHovered = false;
|
||||
hoverCount = 0;
|
||||
return;
|
||||
}
|
||||
if (!wasHovered) {
|
||||
wasHovered = true;
|
||||
hoverCount = 0;
|
||||
}
|
||||
if (hoverCount < 65) hoverCount++;
|
||||
|
||||
if (hoverCount > 60) {
|
||||
GL11.glPushMatrix();
|
||||
Minecraft mc = Minecraft.getMinecraft();
|
||||
String displayString = StatCollector.translateToLocal(hoverableText);
|
||||
GL11.glColor4f(1, 1, 1, 1);
|
||||
List<String> lines = TextSplitter.splitText(displayString, 30);
|
||||
drawHoveringText(lines, screenMouseX, screenMouseY, mc);
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected void drawHoveringText(List textLines, int x, int y, Minecraft mc) {
|
||||
if (mc.fontRenderer == null || textLines.isEmpty())
|
||||
return;
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
int maxWidth = 0;
|
||||
Iterator iterator = textLines.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String s = (String) iterator.next();
|
||||
int lineWidth = mc.fontRenderer.getStringWidth(s);
|
||||
if (lineWidth > maxWidth) {
|
||||
maxWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
int j2 = x + 12;
|
||||
int k2 = y - 12;
|
||||
int maxHeight = 8;
|
||||
|
||||
if (textLines.size() > 1) {
|
||||
maxHeight += 2 + (textLines.size() - 1) * 10;
|
||||
}
|
||||
|
||||
ScaledResolution scaledRes = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
int screenWidth = scaledRes.getScaledWidth();
|
||||
int screenHeight = scaledRes.getScaledHeight();
|
||||
|
||||
if (j2 + maxWidth + 6 > screenWidth) {
|
||||
j2 = x - maxWidth - 16;
|
||||
}
|
||||
if (j2 < 4) {
|
||||
j2 = 4;
|
||||
}
|
||||
if (k2 + maxHeight + 6 > screenHeight) {
|
||||
k2 = screenHeight - maxHeight - 6;
|
||||
}
|
||||
if (k2 < 4) {
|
||||
k2 = 4;
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
int j1 = -267386864;
|
||||
this.drawGradientRect(j2 - 3, k2 - 4, j2 + maxWidth + 3, k2 - 3, j1, j1);
|
||||
this.drawGradientRect(j2 - 3, k2 + maxHeight + 3, j2 + maxWidth + 3, k2 + maxHeight + 4, j1, j1);
|
||||
this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 + maxHeight + 3, j1, j1);
|
||||
this.drawGradientRect(j2 - 4, k2 - 3, j2 - 3, k2 + maxHeight + 3, j1, j1);
|
||||
this.drawGradientRect(j2 + maxWidth + 3, k2 - 3, j2 + maxWidth + 4, k2 + maxHeight + 3, j1, j1);
|
||||
int k1 = 1347420415;
|
||||
int l1 = (k1 & 16711422) >> 1 | k1 & -16777216;
|
||||
this.drawGradientRect(j2 - 3, k2 - 3 + 1, j2 - 3 + 1, k2 + maxHeight + 3 - 1, k1, l1);
|
||||
this.drawGradientRect(j2 + maxWidth + 2, k2 - 3 + 1, j2 + maxWidth + 3, k2 + maxHeight + 3 - 1, k1, l1);
|
||||
this.drawGradientRect(j2 - 3, k2 - 3, j2 + maxWidth + 3, k2 - 3 + 1, k1, k1);
|
||||
this.drawGradientRect(j2 - 3, k2 + maxHeight + 2, j2 + maxWidth + 3, k2 + maxHeight + 3, l1, l1);
|
||||
|
||||
for (int i2 = 0; i2 < textLines.size(); ++i2) {
|
||||
String s1 = (String) textLines.get(i2);
|
||||
mc.fontRenderer.drawStringWithShadow(s1, j2, k2, -1);
|
||||
if (i2 == 0) {
|
||||
k2 += 2;
|
||||
}
|
||||
k2 += 10;
|
||||
}
|
||||
|
||||
this.zLevel = 0.0F;
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_DEPTH_TEST);
|
||||
RenderHelper.enableStandardItemLighting();
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
}
|
||||
}
|
||||
@@ -300,6 +300,14 @@ public class GuiScrollWindow extends GuiScreen implements ITextfieldListener, IC
|
||||
button.drawHover(mouseX, mouseY, subGui);
|
||||
}
|
||||
}
|
||||
// Label hover: convert screen mouse to scroll-local coords for hit testing
|
||||
int localMouseX = mouseX - xPos;
|
||||
int localMouseY = (int) (mouseY - yPos + scrollY);
|
||||
for (GuiNpcLabel label : labels.values()) {
|
||||
if (!label.hoverableText.isEmpty()) {
|
||||
label.drawHover(localMouseX, localMouseY, mouseX, mouseY, subGui, fontRendererObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void elementClicked() {
|
||||
|
||||
@@ -453,13 +453,29 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
// ANIMATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
private void playAbilityAnimation(Animation animation) {
|
||||
public void playAbilityAnimation(Animation animation) {
|
||||
if (animation == null || AnimationController.Instance == null) return;
|
||||
playerData.animationData.setEnabled(true);
|
||||
playerData.animationData.setAnimation(animation);
|
||||
playerData.animationData.updateClient();
|
||||
}
|
||||
|
||||
public void playAbilityAnimation(int animation) {
|
||||
if (animation < 0) return;
|
||||
if (AnimationController.Instance == null) return;
|
||||
if (AnimationController.Instance.get(animation) == null) return;
|
||||
|
||||
playAbilityAnimation((Animation) AnimationController.Instance.get(animation));
|
||||
}
|
||||
|
||||
public void playAbilityAnimation(String animation) {
|
||||
if (animation.isEmpty()) return;
|
||||
if (AnimationController.Instance == null) return;
|
||||
if (AnimationController.Instance.get(animation, true) == null) return;
|
||||
|
||||
playAbilityAnimation((Animation) AnimationController.Instance.get(animation, true));
|
||||
}
|
||||
|
||||
private void stopAbilityAnimation() {
|
||||
playerData.animationData.setAnimation(null);
|
||||
playerData.animationData.updateClient();
|
||||
|
||||
@@ -16,6 +16,7 @@ public class ItemElementalStaff extends ItemStaff {
|
||||
public ItemElementalStaff(int par1, EnumNpcToolMaterial material) {
|
||||
super(par1, material);
|
||||
setHasSubtypes(true);
|
||||
this.color = OrbColor.GENERIC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
package noppes.npcs.items;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.data.*;
|
||||
import kamkeel.npcs.entity.EntityAbilityOrb;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.passive.EntitySheep;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.EnumAction;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -20,13 +24,18 @@ import noppes.npcs.entity.EntityProjectile;
|
||||
import noppes.npcs.util.IProjectileCallback;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
|
||||
private EnumNpcToolMaterial material;
|
||||
|
||||
protected OrbColor color;
|
||||
|
||||
public ItemStaff(int par1, EnumNpcToolMaterial material) {
|
||||
super(par1);
|
||||
this.material = material;
|
||||
this.color = OrbColor.get(material.ordinal());;
|
||||
setCreativeTab(CustomItems.tabWeapon);
|
||||
}
|
||||
|
||||
@@ -36,70 +45,92 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World worldObj, EntityPlayer player, int par4) {
|
||||
if (worldObj.isRemote) {
|
||||
public void onPlayerStoppedUsing(ItemStack stack, World world, EntityPlayer player, int par4) {
|
||||
|
||||
if (world.isRemote)
|
||||
return;
|
||||
}
|
||||
|
||||
if (stack.stackTagCompound == null)
|
||||
return;
|
||||
Entity entity = ((WorldServer) player.worldObj).getEntityByID(stack.stackTagCompound.getInteger("MagicProjectile"));
|
||||
if (entity == null || !(entity instanceof EntityProjectile))
|
||||
|
||||
Entity entity = ((WorldServer) world)
|
||||
.getEntityByID(stack.stackTagCompound.getInteger("MagicProjectile"));
|
||||
|
||||
if (!(entity instanceof EntityAbilityOrb))
|
||||
return;
|
||||
EntityProjectile item = (EntityProjectile) entity;
|
||||
item.callback = this;
|
||||
item.callbackItem = stack;
|
||||
item.explosive = true;
|
||||
item.explosiveDamage = false;
|
||||
item.explosiveRadius = 1;
|
||||
item.prevRotationYaw = item.rotationYaw = player.rotationYaw;
|
||||
item.prevRotationPitch = item.rotationPitch = player.rotationPitch;
|
||||
item.shoot(2);
|
||||
|
||||
player.worldObj.playSoundAtEntity(player, "customnpcs:magic.shot", 1.0F, 1);
|
||||
EntityAbilityOrb orb = (EntityAbilityOrb) entity;
|
||||
|
||||
orb.startMoving(null);
|
||||
|
||||
world.playSoundAtEntity(
|
||||
player,
|
||||
"customnpcs:magic.shot",
|
||||
1.0F,
|
||||
1.0F
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUsingTick(ItemStack stack, EntityPlayer player, int count) {
|
||||
int tick = getMaxItemUseDuration(stack) - count;
|
||||
|
||||
if (player.worldObj.isRemote) {
|
||||
spawnParticle(stack, player);
|
||||
return;
|
||||
}
|
||||
|
||||
int chargeTime = 20 + material.getHarvestLevel() * 8;
|
||||
|
||||
if (tick == chargeTime) {
|
||||
|
||||
if (!player.capabilities.isCreativeMode && !hasInfinite(stack)) {
|
||||
if (!hasItem(player, CustomItems.mana))
|
||||
return;
|
||||
consumeItem(player, CustomItems.mana);
|
||||
}
|
||||
player.worldObj.playSoundAtEntity(player, "customnpcs:magic.charge", 1.0F, 1);
|
||||
|
||||
player.worldObj.playSoundAtEntity(
|
||||
player,
|
||||
"customnpcs:magic.charge",
|
||||
1.0F,
|
||||
1.0F
|
||||
);
|
||||
|
||||
if (stack.stackTagCompound == null) {
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
int damage = 6 + material.getDamageVsEntity() + player.worldObj.rand.nextInt(4);
|
||||
damage += damage * EnchantInterface.getLevel(EnchantInterface.Damage, stack) * 0.5f;
|
||||
EntityProjectile projectile = new EntityMagicProjectile(player.worldObj, player, getProjectile(stack), false);
|
||||
projectile.damage = damage;
|
||||
projectile.setSpeed(25);
|
||||
double dx = -MathHelper.sin((float) ((player.rotationYaw / 180F) * Math.PI)) * MathHelper.cos((float) ((player.rotationPitch / 180F) * Math.PI));
|
||||
double dz = MathHelper.cos((float) ((player.rotationYaw / 180F) * Math.PI)) * MathHelper.cos((float) ((player.rotationPitch / 180F) * Math.PI));
|
||||
projectile.setPosition(player.posX + dx * 0.8, player.posY + 1.5 - player.rotationPitch / 80, player.posZ + dz * 0.8);
|
||||
player.worldObj.spawnEntityInWorld(projectile);
|
||||
stack.stackTagCompound.setInteger("MagicProjectile", projectile.getEntityId());//entityid
|
||||
}
|
||||
if (tick > chargeTime && stack.stackTagCompound != null) {
|
||||
Entity entity = ((WorldServer) player.worldObj).getEntityByID(stack.stackTagCompound.getInteger("MagicProjectile"));
|
||||
if (entity == null || !(entity instanceof EntityProjectile))
|
||||
return;
|
||||
EntityProjectile item = (EntityProjectile) entity;
|
||||
item.ticksInAir = 0;
|
||||
|
||||
double dx = -MathHelper.sin((float) ((player.rotationYaw / 180F) * Math.PI)) * MathHelper.cos((float) ((player.rotationPitch / 180F) * Math.PI));
|
||||
double dz = MathHelper.cos((float) ((player.rotationYaw / 180F) * Math.PI)) * MathHelper.cos((float) ((player.rotationPitch / 180F) * Math.PI));
|
||||
item.setPosition(player.posX + dx * 0.8, player.posY + 1.5 - player.rotationPitch / 80, player.posZ + dz * 0.8);
|
||||
}
|
||||
EnergyCombatData combat = new EnergyCombatData();
|
||||
combat.damage = damage;
|
||||
combat.explosive = true;
|
||||
|
||||
EnergyColorData colorData = new EnergyColorData(getOrbColor(stack, false), getOrbColor(stack, true));
|
||||
EnergyLightningData lightning = new EnergyLightningData();
|
||||
EnergyLifespanData lifespan = new EnergyLifespanData(100, 72000);
|
||||
EnergyHomingData homing = new EnergyHomingData();
|
||||
|
||||
homing.speed = 0.5f;
|
||||
homing.homingStrength = 0.35f;
|
||||
homing.homingRange = 20f;
|
||||
|
||||
EntityAbilityOrb orb = new EntityAbilityOrb(
|
||||
player.worldObj, player, null,
|
||||
player.posX, player.posY + player.getEyeHeight(), player.posZ,
|
||||
1.0f, colorData, combat, homing, lightning, lifespan
|
||||
);
|
||||
|
||||
orb.setupCharging(
|
||||
new EnergyAnchorData(AnchorPoint.FRONT, 0, -1, 0),
|
||||
chargeTime
|
||||
);
|
||||
|
||||
player.worldObj.spawnEntityInWorld(orb);
|
||||
stack.stackTagCompound.setInteger("MagicProjectile", orb.getEntityId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,6 +149,15 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
return EnumAction.bow;
|
||||
}
|
||||
|
||||
public int getOrbColor(ItemStack stack, boolean outer) {
|
||||
if (color == OrbColor.GENERIC) {
|
||||
float[] color = EntitySheep.fleeceColorTable[stack.getItemDamage()];
|
||||
return new Color(color[0], color[1], color[2]).getRGB();
|
||||
}
|
||||
|
||||
return outer ? color.outer : color.inner;
|
||||
}
|
||||
|
||||
public ItemStack getProjectile(ItemStack stack) {
|
||||
if (stack.getItem() == CustomItems.staffWood) {
|
||||
return new ItemStack(CustomItems.spellNature);
|
||||
@@ -196,4 +236,32 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
|
||||
public boolean hasInfinite(ItemStack stack) {
|
||||
return EnchantInterface.getLevel(EnchantInterface.Infinite, stack) > 0;
|
||||
}
|
||||
|
||||
public enum OrbColor {
|
||||
WOOD(0x7cc818, 0x644a32),
|
||||
STONE(0x532d5b, 0x515151),
|
||||
BRONZE(0x83F7F6, 0x5CF0FF),
|
||||
IRON(0xf7fac5, 0xeafa94),
|
||||
DIA(0x44B6FF, 0x94DFED),
|
||||
GOLD(0xb3011e, 0xd47c32),
|
||||
EMERALD(0xdd6df7, 0xcf1dfa),
|
||||
DEMONIC(0xb8144a, 0x422643),
|
||||
FROST(0xffffff, 0xaccbfe),
|
||||
MITHRIL(0xf7fac5, 0xffffff),
|
||||
GENERIC(0xFFFFFF, 0x88FFFF);
|
||||
|
||||
public final int inner;
|
||||
public final int outer;
|
||||
|
||||
OrbColor(int inner, int outer) {
|
||||
this.inner = inner;
|
||||
this.outer = outer;
|
||||
}
|
||||
|
||||
public static OrbColor get(int id) {
|
||||
if (id >= OrbColor.values().length || id < 0) return GENERIC;
|
||||
|
||||
return OrbColor.values()[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user