mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-18 03:25:02 +00:00
Another MEGA COMMIT to Core Structure
This commit is contained in:
1 parent
cb6e1ca386
commit
3a8b75f152
79 files changed
+4557
-96
No files matched your search
+37
@@ -0,0 +1,37 @@
|
||||
package kamkeel.npcs.controllers.data.ability.conditions;
|
||||
|
||||
public enum ConditionFilter {
|
||||
CASTER,
|
||||
TARGET,
|
||||
BOTH;
|
||||
|
||||
public boolean checksCaster() {
|
||||
return this == CASTER || this == BOTH;
|
||||
}
|
||||
|
||||
public boolean checksTarget() {
|
||||
return this == TARGET || this == BOTH;
|
||||
}
|
||||
|
||||
public static ConditionFilter fromOrdinal(int ordinal) {
|
||||
ConditionFilter[] values = values();
|
||||
if (ordinal >= 0 && ordinal < values.length) {
|
||||
return values[ordinal];
|
||||
}
|
||||
return BOTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
switch (this) {
|
||||
case BOTH:
|
||||
return "condition.filter.both";
|
||||
case CASTER:
|
||||
return "condition.filter.caster";
|
||||
case TARGET:
|
||||
return "condition.filter.target";
|
||||
default:
|
||||
return name();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AnchorPoint;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyAnchorData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.energy.EnergyDisplayData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Per-projectile data: anchor point + optional color override.
|
||||
* All projectiles share the primary EnergyDisplayData; this class
|
||||
* allows individual projectiles to override just the inner/outer colors.
|
||||
*/
|
||||
public class ProjectileData {
|
||||
public EnergyAnchorData anchor;
|
||||
public boolean colorOverride = false;
|
||||
public int innerColor = 0xFFFFFF;
|
||||
public int outerColor = 0x8888FF;
|
||||
|
||||
public ProjectileData(AnchorPoint defaultAnchor) {
|
||||
this.anchor = new EnergyAnchorData(defaultAnchor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the display data to use for this projectile.
|
||||
* If colorOverride is false, returns the primary display data directly.
|
||||
* If colorOverride is true, returns a copy with overridden inner/outer colors.
|
||||
*/
|
||||
public EnergyDisplayData resolveDisplay(EnergyDisplayData primary) {
|
||||
// Always return a copy so entity mutations never bleed back into the ability template.
|
||||
EnergyDisplayData resolved = primary.copy();
|
||||
if (colorOverride) {
|
||||
resolved.innerColor = this.innerColor;
|
||||
resolved.outerColor = this.outerColor;
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
// OLD: anchor.writeNBT(new MC1710NBTCompound(nbt));
|
||||
anchor.writeNBT(nbt);
|
||||
nbt.setBoolean("colorOverride", colorOverride);
|
||||
if (colorOverride) {
|
||||
nbt.setInteger("overrideInnerColor", innerColor);
|
||||
nbt.setInteger("overrideOuterColor", outerColor);
|
||||
}
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
// OLD: anchor.readNBT(new MC1710NBTCompound(nbt));
|
||||
anchor.readNBT(nbt);
|
||||
colorOverride = nbt.getBoolean("colorOverride");
|
||||
if (colorOverride) {
|
||||
innerColor = nbt.getInteger("overrideInnerColor");
|
||||
outerColor = nbt.getInteger("overrideOuterColor");
|
||||
}
|
||||
}
|
||||
|
||||
public ProjectileData copy() {
|
||||
ProjectileData copy = new ProjectileData(anchor.anchorPoint);
|
||||
copy.anchor = anchor.copy();
|
||||
copy.colorOverride = colorOverride;
|
||||
copy.innerColor = innerColor;
|
||||
copy.outerColor = outerColor;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AnchorPoint;
|
||||
import noppes.npcs.api.ability.data.IEnergyAnchorData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
public class EnergyAnchorData implements IEnergyAnchorData {
|
||||
public AnchorPoint anchorPoint = AnchorPoint.FRONT;
|
||||
public float anchorOffsetX = 0;
|
||||
public float anchorOffsetY = 0;
|
||||
public float anchorOffsetZ = 0;
|
||||
public boolean launchFromAnchor = false;
|
||||
|
||||
public EnergyAnchorData() {
|
||||
}
|
||||
|
||||
public EnergyAnchorData(AnchorPoint anchorPoint) {
|
||||
this.anchorPoint = anchorPoint;
|
||||
}
|
||||
|
||||
public EnergyAnchorData(AnchorPoint anchorPoint, float anchorOffsetX, float anchorOffsetY, float anchorOffsetZ) {
|
||||
this.anchorPoint = anchorPoint;
|
||||
this.anchorOffsetX = anchorOffsetX;
|
||||
this.anchorOffsetY = anchorOffsetY;
|
||||
this.anchorOffsetZ = anchorOffsetZ;
|
||||
}
|
||||
|
||||
public EnergyAnchorData(int anchorPoint) {
|
||||
this.anchorPoint = AnchorPoint.fromOrdinal(anchorPoint);
|
||||
}
|
||||
|
||||
public EnergyAnchorData(int anchorPoint, float anchorOffsetX, float anchorOffsetY, float anchorOffsetZ) {
|
||||
this.anchorPoint = AnchorPoint.fromOrdinal(anchorPoint);
|
||||
this.anchorOffsetX = anchorOffsetX;
|
||||
this.anchorOffsetY = anchorOffsetY;
|
||||
this.anchorOffsetZ = anchorOffsetZ;
|
||||
}
|
||||
|
||||
public AnchorPoint getAnchorPoint() {
|
||||
return anchorPoint;
|
||||
}
|
||||
|
||||
public void setAnchorPoint(AnchorPoint anchorPoint) {
|
||||
this.anchorPoint = anchorPoint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnchor() {
|
||||
return anchorPoint.ordinal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchor(int anchor) {
|
||||
this.anchorPoint = AnchorPoint.fromOrdinal(anchor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnchorOffsetX() {
|
||||
return anchorOffsetX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchorOffsetX(float anchorOffsetX) {
|
||||
this.anchorOffsetX = anchorOffsetX;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnchorOffsetY() {
|
||||
return anchorOffsetY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchorOffsetY(float anchorOffsetY) {
|
||||
this.anchorOffsetY = anchorOffsetY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnchorOffsetZ() {
|
||||
return anchorOffsetZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAnchorOffsetZ(float anchorOffsetZ) {
|
||||
this.anchorOffsetZ = anchorOffsetZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getLaunchFromAnchor() {
|
||||
return launchFromAnchor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLaunchFromAnchor(boolean launchFromAnchor) {
|
||||
this.launchFromAnchor = launchFromAnchor;
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setInteger("anchorPoint", anchorPoint.ordinal());
|
||||
nbt.setFloat("anchorOffsetX", anchorOffsetX);
|
||||
nbt.setFloat("anchorOffsetY", anchorOffsetY);
|
||||
nbt.setFloat("anchorOffsetZ", anchorOffsetZ);
|
||||
nbt.setBoolean("launchFromAnchor", launchFromAnchor);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
this.anchorPoint = AnchorPoint.fromOrdinal(nbt.getInteger("anchorPoint"));
|
||||
this.anchorOffsetX = nbt.getFloat("anchorOffsetX");
|
||||
this.anchorOffsetY = nbt.getFloat("anchorOffsetY");
|
||||
this.anchorOffsetZ = nbt.getFloat("anchorOffsetZ");
|
||||
this.launchFromAnchor = nbt.getBoolean("launchFromAnchor");
|
||||
}
|
||||
|
||||
public EnergyAnchorData copy() {
|
||||
EnergyAnchorData copy = new EnergyAnchorData(anchorPoint, anchorOffsetX, anchorOffsetY, anchorOffsetZ);
|
||||
copy.launchFromAnchor = this.launchFromAnchor;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+235
@@ -0,0 +1,235 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Groups barrier properties shared by energy barrier abilities (Dome, Wall, Shield).
|
||||
* Handles health/durability, duration, and per-projectile-type damage multipliers.
|
||||
*
|
||||
* Properties:
|
||||
* - Solid: Hard wall - entities cannot pass through the barrier boundary (either direction)
|
||||
* - Knockback: Repulsion field - entities near the surface get pushed away
|
||||
* - Absorbing: Caster's incoming damage is redirected to the barrier
|
||||
* - Allows Melee: Barrier can be hit by melee attacks (punching)
|
||||
*/
|
||||
public class EnergyBarrierData {
|
||||
|
||||
public float maxHealth = 100.0f;
|
||||
public boolean useHealth = true;
|
||||
public int durationTicks = 200;
|
||||
public boolean useDuration = true;
|
||||
public float defaultMultiplier = 1.0f;
|
||||
|
||||
// Solid: entities cannot pass through the barrier boundary
|
||||
public boolean solid = false;
|
||||
|
||||
// Knockback: repulsion field pushing entities away from surface
|
||||
public boolean knockbackEnabled = false;
|
||||
public float knockbackStrength = 1.0f;
|
||||
|
||||
// Absorbing: caster's damage is redirected to the barrier
|
||||
public boolean absorbing = false;
|
||||
// Absorb radius: max distance from barrier's current position for absorption to work
|
||||
// -1 = no radius limit (absorb regardless of distance)
|
||||
// 0 = use barrier's own extent as the radius (dome radius, panel half-size, etc.)
|
||||
// positive = owner must be within this many blocks of the barrier entity
|
||||
public float absorbRadius = 0.0f;
|
||||
|
||||
// Melee: barrier can be hit by melee attacks
|
||||
public boolean meleeEnabled = false;
|
||||
public float meleeDamageMultiplier = 1.0f;
|
||||
|
||||
// Reflection: rebound projectiles that fail to break the barrier
|
||||
public boolean reflect = false;
|
||||
public float reflectStrengthPct = 25.0f;
|
||||
public boolean targetOwner = false;
|
||||
|
||||
/**
|
||||
* Per-projectile-type damage multipliers.
|
||||
* Key is the ability typeId (e.g., "ability.cnpc.orb", "ability.cnpc.beam").
|
||||
* Value is the multiplier applied to damage dealt to this barrier.
|
||||
*/
|
||||
private Map<String, Float> damageMultipliers = new HashMap<>();
|
||||
|
||||
public EnergyBarrierData() {
|
||||
}
|
||||
|
||||
public EnergyBarrierData(float maxHealth, boolean useHealth, int durationTicks, boolean useDuration) {
|
||||
this.maxHealth = maxHealth;
|
||||
this.useHealth = useHealth;
|
||||
this.durationTicks = durationTicks;
|
||||
this.useDuration = useDuration;
|
||||
}
|
||||
|
||||
// ==================== MULTIPLIER METHODS ====================
|
||||
|
||||
public float getMultiplier(String abilityTypeId) {
|
||||
Float mult = damageMultipliers.get(abilityTypeId);
|
||||
return mult != null ? mult : defaultMultiplier;
|
||||
}
|
||||
|
||||
public void setMultiplier(String abilityTypeId, float multiplier) {
|
||||
damageMultipliers.put(abilityTypeId, multiplier);
|
||||
}
|
||||
|
||||
public void removeMultiplier(String abilityTypeId) {
|
||||
damageMultipliers.remove(abilityTypeId);
|
||||
}
|
||||
|
||||
public Map<String, Float> getDamageMultipliers() {
|
||||
return damageMultipliers;
|
||||
}
|
||||
|
||||
public void setDamageMultipliers(Map<String, Float> multipliers) {
|
||||
this.damageMultipliers = multipliers != null ? multipliers : new HashMap<>();
|
||||
}
|
||||
|
||||
// ==================== GETTERS & SETTERS ====================
|
||||
|
||||
public float getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public void setMaxHealth(float maxHealth) {
|
||||
this.maxHealth = Math.max(1.0f, maxHealth);
|
||||
}
|
||||
|
||||
public boolean isUseHealth() {
|
||||
return useHealth;
|
||||
}
|
||||
|
||||
public void setUseHealth(boolean useHealth) {
|
||||
this.useHealth = useHealth;
|
||||
}
|
||||
|
||||
public int getDurationTicks() {
|
||||
return durationTicks;
|
||||
}
|
||||
|
||||
public void setDurationTicks(int durationTicks) {
|
||||
this.durationTicks = Math.max(1, durationTicks);
|
||||
}
|
||||
|
||||
public boolean isUseDuration() {
|
||||
return useDuration;
|
||||
}
|
||||
|
||||
public void setUseDuration(boolean useDuration) {
|
||||
this.useDuration = useDuration;
|
||||
}
|
||||
|
||||
public float getDefaultMultiplier() {
|
||||
return defaultMultiplier;
|
||||
}
|
||||
|
||||
public void setDefaultMultiplier(float defaultMultiplier) {
|
||||
this.defaultMultiplier = defaultMultiplier;
|
||||
}
|
||||
|
||||
public boolean isReflect() {
|
||||
return reflect;
|
||||
}
|
||||
|
||||
public void setReflect(boolean reflect) {
|
||||
this.reflect = reflect;
|
||||
}
|
||||
|
||||
public float getReflectStrengthPct() {
|
||||
return reflectStrengthPct;
|
||||
}
|
||||
|
||||
public void setReflectStrengthPct(float reflectStrengthPct) {
|
||||
this.reflectStrengthPct = Math.max(0.0f, Math.min(100.0f, reflectStrengthPct));
|
||||
}
|
||||
|
||||
public boolean isTargetOwner() {
|
||||
return targetOwner;
|
||||
}
|
||||
|
||||
public void setTargetOwner(boolean targetOwner) {
|
||||
this.targetOwner = targetOwner;
|
||||
}
|
||||
|
||||
public float getAbsorbRadius() {
|
||||
return absorbRadius;
|
||||
}
|
||||
|
||||
public void setAbsorbRadius(float absorbRadius) {
|
||||
this.absorbRadius = absorbRadius;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setFloat("barrierMaxHealth", maxHealth);
|
||||
nbt.setBoolean("barrierUseHealth", useHealth);
|
||||
nbt.setInteger("barrierDuration", durationTicks);
|
||||
nbt.setBoolean("barrierUseDuration", useDuration);
|
||||
nbt.setFloat("barrierDefaultMult", defaultMultiplier);
|
||||
nbt.setBoolean("barrierSolid", solid);
|
||||
nbt.setBoolean("barrierKnockback", knockbackEnabled);
|
||||
nbt.setFloat("barrierKnockbackStr", knockbackStrength);
|
||||
nbt.setBoolean("barrierAbsorbing", absorbing);
|
||||
nbt.setFloat("barrierAbsorbRadius", absorbRadius);
|
||||
nbt.setBoolean("barrierMelee", meleeEnabled);
|
||||
nbt.setFloat("barrierMeleeMult", meleeDamageMultiplier);
|
||||
nbt.setBoolean("barrierReflect", reflect);
|
||||
nbt.setFloat("barrierReflectStrPct", reflectStrengthPct);
|
||||
nbt.setBoolean("barrierTargetOwner", targetOwner);
|
||||
|
||||
INBTCompound multNbt = NBT.compound();
|
||||
for (Map.Entry<String, Float> entry : damageMultipliers.entrySet()) {
|
||||
multNbt.setFloat(entry.getKey(), entry.getValue());
|
||||
}
|
||||
nbt.setCompound("barrierMultipliers", multNbt);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
maxHealth = nbt.hasKey("barrierMaxHealth") ? nbt.getFloat("barrierMaxHealth") : 100.0f;
|
||||
useHealth = !nbt.hasKey("barrierUseHealth") || nbt.getBoolean("barrierUseHealth");
|
||||
durationTicks = nbt.hasKey("barrierDuration") ? nbt.getInteger("barrierDuration") : 200;
|
||||
useDuration = !nbt.hasKey("barrierUseDuration") || nbt.getBoolean("barrierUseDuration");
|
||||
defaultMultiplier = nbt.hasKey("barrierDefaultMult") ? nbt.getFloat("barrierDefaultMult") : 1.0f;
|
||||
solid = nbt.hasKey("barrierSolid") && nbt.getBoolean("barrierSolid");
|
||||
knockbackEnabled = nbt.hasKey("barrierKnockback") && nbt.getBoolean("barrierKnockback");
|
||||
knockbackStrength = nbt.hasKey("barrierKnockbackStr") ? nbt.getFloat("barrierKnockbackStr") : 1.0f;
|
||||
absorbing = nbt.hasKey("barrierAbsorbing") && nbt.getBoolean("barrierAbsorbing");
|
||||
absorbRadius = nbt.hasKey("barrierAbsorbRadius") ? nbt.getFloat("barrierAbsorbRadius") : 0.0f;
|
||||
meleeEnabled = nbt.hasKey("barrierMelee") && nbt.getBoolean("barrierMelee");
|
||||
meleeDamageMultiplier = nbt.hasKey("barrierMeleeMult") ? nbt.getFloat("barrierMeleeMult") : 1.0f;
|
||||
reflect = nbt.hasKey("barrierReflect") && nbt.getBoolean("barrierReflect");
|
||||
setReflectStrengthPct(nbt.hasKey("barrierReflectStrPct") ? nbt.getFloat("barrierReflectStrPct") : 25.0f);
|
||||
targetOwner = nbt.hasKey("barrierTargetOwner") && nbt.getBoolean("barrierTargetOwner");
|
||||
|
||||
damageMultipliers.clear();
|
||||
if (nbt.hasKey("barrierMultipliers")) {
|
||||
INBTCompound multNbt = nbt.getCompound("barrierMultipliers");
|
||||
Set<String> keys = multNbt.getKeySet();
|
||||
for (String key : keys) {
|
||||
damageMultipliers.put(key, multNbt.getFloat(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public EnergyBarrierData copy() {
|
||||
EnergyBarrierData copy = new EnergyBarrierData(maxHealth, useHealth, durationTicks, useDuration);
|
||||
copy.defaultMultiplier = defaultMultiplier;
|
||||
copy.solid = solid;
|
||||
copy.knockbackEnabled = knockbackEnabled;
|
||||
copy.knockbackStrength = knockbackStrength;
|
||||
copy.absorbing = absorbing;
|
||||
copy.absorbRadius = absorbRadius;
|
||||
copy.meleeEnabled = meleeEnabled;
|
||||
copy.meleeDamageMultiplier = meleeDamageMultiplier;
|
||||
copy.reflect = reflect;
|
||||
copy.reflectStrengthPct = reflectStrengthPct;
|
||||
copy.targetOwner = targetOwner;
|
||||
copy.damageMultipliers = new HashMap<>(damageMultipliers);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
public class EnergyChargingData {
|
||||
|
||||
public int chargeDuration = 60;
|
||||
public int chargeDelay = 0;
|
||||
public int maxCharge = 100;
|
||||
public boolean hasCharge = true;
|
||||
public boolean chargeWindUpSync = true;
|
||||
|
||||
public EnergyChargingData() {
|
||||
}
|
||||
|
||||
public EnergyChargingData(int chargeDuration, int chargeDelay, int maxCharge, boolean hasCharge, boolean chargeWindUpSync) {
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeDelay = chargeDelay;
|
||||
this.maxCharge = maxCharge;
|
||||
this.hasCharge = hasCharge;
|
||||
this.chargeWindUpSync = chargeWindUpSync;
|
||||
}
|
||||
|
||||
public boolean hasCharge() {
|
||||
return hasCharge;
|
||||
}
|
||||
|
||||
public void setHasCharge(boolean hasCharge) {
|
||||
this.hasCharge = hasCharge;
|
||||
}
|
||||
|
||||
public boolean isChargeWindUpSync() {
|
||||
return chargeWindUpSync;
|
||||
}
|
||||
|
||||
public void setChargeWindUpSync(boolean chargeWindUpSync) {
|
||||
this.chargeWindUpSync = chargeWindUpSync;
|
||||
}
|
||||
|
||||
public int getChargeDuration() {
|
||||
return chargeDuration;
|
||||
}
|
||||
|
||||
public void setChargeDuration(int chargeDuration) {
|
||||
this.chargeDuration = chargeDuration;
|
||||
}
|
||||
|
||||
public int getChargeDelay() {
|
||||
return chargeDelay;
|
||||
}
|
||||
|
||||
public void setChargeDelay(int chargeDelay) {
|
||||
this.chargeDelay = chargeDelay;
|
||||
}
|
||||
|
||||
public int getMaxCharge() {
|
||||
return maxCharge;
|
||||
}
|
||||
|
||||
public void setMaxCharge(int maxCharge) {
|
||||
this.maxCharge = Math.max(0, maxCharge);
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setInteger("chargeDuration", chargeDuration);
|
||||
nbt.setInteger("chargeDelay", chargeDelay);
|
||||
nbt.setInteger("maxCharge", maxCharge);
|
||||
nbt.setBoolean("hasCharge", hasCharge);
|
||||
nbt.setBoolean("chargeWindUpSync", chargeWindUpSync);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
chargeDuration = nbt.hasKey("chargeDuration") ? nbt.getInteger("chargeDuration") : 60;
|
||||
chargeDelay = nbt.hasKey("chargeDelay") ? nbt.getInteger("chargeDelay") : 0;
|
||||
maxCharge = nbt.hasKey("maxCharge") ? nbt.getInteger("maxCharge") : 100;
|
||||
hasCharge = !nbt.hasKey("hasCharge") || nbt.getBoolean("hasCharge");
|
||||
chargeWindUpSync = !nbt.hasKey("chargeWindUpSync") || nbt.getBoolean("chargeWindUpSync");
|
||||
}
|
||||
|
||||
public EnergyChargingData copy() {
|
||||
return new EnergyChargingData(chargeDuration, chargeDelay, maxCharge, hasCharge, chargeWindUpSync);
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.enums.HitType;
|
||||
import noppes.npcs.api.ability.data.IEnergyCombatData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups combat properties shared by energy projectile abilities.
|
||||
* Used as a parameter object for entity constructors and ability configuration.
|
||||
*/
|
||||
public class EnergyCombatData implements IEnergyCombatData {
|
||||
public static final float MAX_EXPLOSION_RADIUS = 15.0f;
|
||||
public static final int DEFAULT_MAX_HITS = 5;
|
||||
public static final int MAX_HITS = 200;
|
||||
|
||||
public float damage = 7.0f;
|
||||
public float knockback = 1.0f;
|
||||
public float knockbackUp = 0.1f;
|
||||
public boolean explosive = false;
|
||||
public float explosionRadius = 3.0f;
|
||||
public float explosionDamageFalloff = 0.5f;
|
||||
public HitType hitType = HitType.SINGLE;
|
||||
public int multiHitDelayTicks = 5;
|
||||
public int maxHits = DEFAULT_MAX_HITS;
|
||||
|
||||
public EnergyCombatData() {
|
||||
}
|
||||
|
||||
public EnergyCombatData(float damage, float knockback, float knockbackUp,
|
||||
boolean explosive, float explosionRadius, float explosionDamageFalloff,
|
||||
HitType hitType, int multiHitDelay) {
|
||||
this(damage, knockback, knockbackUp, explosive, explosionRadius, explosionDamageFalloff, hitType, multiHitDelay, DEFAULT_MAX_HITS);
|
||||
}
|
||||
|
||||
public EnergyCombatData(float damage, float knockback, float knockbackUp,
|
||||
boolean explosive, float explosionRadius, float explosionDamageFalloff,
|
||||
HitType hitType, int multiHitDelay, int maxHits) {
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
this.explosive = explosive;
|
||||
this.explosionRadius = clampExplosionRadius(explosionRadius);
|
||||
this.explosionDamageFalloff = explosionDamageFalloff;
|
||||
this.hitType = hitType;
|
||||
this.multiHitDelayTicks = multiHitDelay;
|
||||
this.maxHits = clampMaxHits(maxHits);
|
||||
}
|
||||
|
||||
public EnergyCombatData(float damage, float knockback, float knockbackUp,
|
||||
boolean explosive, float explosionRadius, float explosionDamageFalloff) {
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
this.explosive = explosive;
|
||||
this.explosionRadius = clampExplosionRadius(explosionRadius);
|
||||
this.explosionDamageFalloff = explosionDamageFalloff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockback() {
|
||||
return knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockback(float knockback) {
|
||||
this.knockback = knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackUp() {
|
||||
return knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExplosive() {
|
||||
return explosive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExplosive(boolean explosive) {
|
||||
this.explosive = explosive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExplosionRadius() {
|
||||
return explosionRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExplosionRadius(float explosionRadius) {
|
||||
this.explosionRadius = clampExplosionRadius(explosionRadius);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExplosionDamageFalloff() {
|
||||
return explosionDamageFalloff;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExplosionDamageFalloff(float explosionDamageFalloff) {
|
||||
this.explosionDamageFalloff = explosionDamageFalloff;
|
||||
}
|
||||
|
||||
public int getMaxHits() {
|
||||
return maxHits;
|
||||
}
|
||||
|
||||
public void setMaxHits(int maxHits) {
|
||||
this.maxHits = clampMaxHits(maxHits);
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setFloat("damage", damage);
|
||||
nbt.setFloat("knockback", knockback);
|
||||
nbt.setFloat("knockbackUp", knockbackUp);
|
||||
nbt.setBoolean("explosive", explosive);
|
||||
nbt.setFloat("explosionRadius", explosionRadius);
|
||||
nbt.setFloat("explosionDamageFalloff", explosionDamageFalloff);
|
||||
nbt.setInteger("hitType", hitType.ordinal());
|
||||
nbt.setInteger("multiHitDelayTicks", multiHitDelayTicks);
|
||||
nbt.setInteger("maxHits", maxHits);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
damage = nbt.hasKey("damage") ? nbt.getFloat("damage") : 7.0f;
|
||||
knockback = nbt.hasKey("knockback") ? nbt.getFloat("knockback") : 1.0f;
|
||||
knockbackUp = nbt.hasKey("knockbackUp") ? nbt.getFloat("knockbackUp") : 0.1f;
|
||||
explosive = nbt.hasKey("explosive") && nbt.getBoolean("explosive");
|
||||
explosionRadius = nbt.hasKey("explosionRadius") ? nbt.getFloat("explosionRadius") : 3.0f;
|
||||
explosionDamageFalloff = nbt.hasKey("explosionDamageFalloff") ? nbt.getFloat("explosionDamageFalloff") : 0.5f;
|
||||
hitType = HitType.fromOrdinal(nbt.hasKey("hitType") ? nbt.getInteger("hitType") : 0);
|
||||
multiHitDelayTicks = nbt.hasKey("multiHitDelayTicks") ? nbt.getInteger("multiHitDelayTicks") : 5;
|
||||
maxHits = nbt.hasKey("maxHits") ? nbt.getInteger("maxHits") : DEFAULT_MAX_HITS;
|
||||
|
||||
// Sanitize
|
||||
if (Float.isNaN(damage) || Float.isInfinite(damage)) damage = 7.0f;
|
||||
if (Float.isNaN(knockback) || Float.isInfinite(knockback) || knockback < 0) knockback = 1.0f;
|
||||
if (Float.isNaN(explosionRadius) || Float.isInfinite(explosionRadius) || explosionRadius < 0) explosionRadius = 3.0f;
|
||||
explosionRadius = clampExplosionRadius(explosionRadius);
|
||||
if (multiHitDelayTicks < 1) multiHitDelayTicks = 1;
|
||||
maxHits = clampMaxHits(maxHits);
|
||||
}
|
||||
|
||||
private static float clampExplosionRadius(float explosionRadius) {
|
||||
if (Float.isNaN(explosionRadius) || Float.isInfinite(explosionRadius)) return 0.0f;
|
||||
return Math.max(0.0f, Math.min(MAX_EXPLOSION_RADIUS, explosionRadius));
|
||||
}
|
||||
|
||||
private static int clampMaxHits(int maxHits) {
|
||||
return Math.max(1, Math.min(MAX_HITS, maxHits));
|
||||
}
|
||||
|
||||
public EnergyCombatData copy() {
|
||||
EnergyCombatData copy = new EnergyCombatData(damage, knockback, knockbackUp,
|
||||
explosive, explosionRadius, explosionDamageFalloff);
|
||||
copy.hitType = hitType;
|
||||
copy.multiHitDelayTicks = multiHitDelayTicks;
|
||||
copy.maxHits = maxHits;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.api.ability.data.IEnergyDisplayData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups visual color properties shared by all energy abilities.
|
||||
* Used as a parameter object for entity constructors and ability configuration.
|
||||
*/
|
||||
public class EnergyDisplayData implements IEnergyDisplayData {
|
||||
public int innerColor = 0xFFFFFF;
|
||||
public int outerColor = 0x8888FF;
|
||||
public boolean outerColorEnabled = true;
|
||||
public float outerColorWidth = 0.4f;
|
||||
public float outerColorAlpha = 0.5f;
|
||||
public float innerAlpha = 1.0f;
|
||||
public float rotationSpeed = 4.0f;
|
||||
|
||||
public EnergyDisplayData() {
|
||||
}
|
||||
|
||||
public EnergyDisplayData(int innerColor, int outerColor) {
|
||||
this.innerColor = innerColor;
|
||||
this.outerColor = outerColor;
|
||||
}
|
||||
|
||||
public EnergyDisplayData(int innerColor, int outerColor, boolean outerColorEnabled,
|
||||
float outerColorWidth, float outerColorAlpha, float rotationSpeed) {
|
||||
this.innerColor = innerColor;
|
||||
this.outerColor = outerColor;
|
||||
this.outerColorEnabled = outerColorEnabled;
|
||||
this.outerColorWidth = outerColorWidth;
|
||||
this.outerColorAlpha = outerColorAlpha;
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
}
|
||||
|
||||
public EnergyDisplayData(int innerColor, int outerColor, boolean outerColorEnabled,
|
||||
float outerColorWidth, float outerColorAlpha, float innerAlpha, float rotationSpeed) {
|
||||
this(innerColor, outerColor, outerColorEnabled, outerColorWidth, outerColorAlpha, rotationSpeed);
|
||||
this.innerAlpha = innerAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInnerColor() {
|
||||
return innerColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInnerColor(int innerColor) {
|
||||
this.innerColor = innerColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOuterColor() {
|
||||
return outerColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOuterColor(int outerColor) {
|
||||
this.outerColor = outerColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOuterColorEnabled() {
|
||||
return outerColorEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOuterColorEnabled(boolean outerColorEnabled) {
|
||||
this.outerColorEnabled = outerColorEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getOuterColorWidth() {
|
||||
return outerColorWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOuterColorWidth(float outerColorWidth) {
|
||||
this.outerColorWidth = outerColorWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getOuterColorAlpha() {
|
||||
return outerColorAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOuterColorAlpha(float outerColorAlpha) {
|
||||
this.outerColorAlpha = outerColorAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getInnerAlpha() {
|
||||
return innerAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInnerAlpha(float innerAlpha) {
|
||||
this.innerAlpha = innerAlpha;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotationSpeed() {
|
||||
return rotationSpeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRotationSpeed(float rotationSpeed) {
|
||||
this.rotationSpeed = rotationSpeed;
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setInteger("innerColor", innerColor);
|
||||
nbt.setInteger("outerColor", outerColor);
|
||||
nbt.setBoolean("outerColorEnabled", outerColorEnabled);
|
||||
nbt.setFloat("outerColorWidth", outerColorWidth);
|
||||
nbt.setFloat("outerColorAlpha", outerColorAlpha);
|
||||
nbt.setFloat("innerAlpha", innerAlpha);
|
||||
nbt.setFloat("rotationSpeed", rotationSpeed);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF;
|
||||
outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0x8888FF;
|
||||
outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled");
|
||||
outerColorWidth = nbt.hasKey("outerColorWidth") ? nbt.getFloat("outerColorWidth") : 0.4f;
|
||||
outerColorAlpha = nbt.hasKey("outerColorAlpha") ? nbt.getFloat("outerColorAlpha") : 0.5f;
|
||||
innerAlpha = nbt.hasKey("innerAlpha") ? nbt.getFloat("innerAlpha") : 1.0f;
|
||||
rotationSpeed = nbt.hasKey("rotationSpeed") ? nbt.getFloat("rotationSpeed") : 4.0f;
|
||||
}
|
||||
|
||||
public EnergyDisplayData copy() {
|
||||
EnergyDisplayData copy = new EnergyDisplayData(innerColor, outerColor, outerColorEnabled, outerColorWidth, outerColorAlpha, innerAlpha, rotationSpeed);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.api.ability.data.IEnergyHomingData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups homing/movement properties for energy projectile abilities.
|
||||
* Used by Orb, Disc, and Beam (not Laser or Sweeper).
|
||||
*/
|
||||
public class EnergyHomingData implements IEnergyHomingData {
|
||||
public float speed = 0.5f;
|
||||
public boolean homing = true;
|
||||
public float homingStrength = 0.15f;
|
||||
public float homingRange = 20.0f;
|
||||
|
||||
public EnergyHomingData() {
|
||||
}
|
||||
|
||||
public EnergyHomingData(float speed, boolean homing, float homingStrength, float homingRange) {
|
||||
this.speed = speed;
|
||||
this.homing = homing;
|
||||
this.homingStrength = homingStrength;
|
||||
this.homingRange = homingRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = Math.max(0.01f, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHoming() {
|
||||
return homing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHoming(boolean homing) {
|
||||
this.homing = homing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHomingStrength() {
|
||||
return homingStrength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomingStrength(float homingStrength) {
|
||||
this.homingStrength = homingStrength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHomingRange() {
|
||||
return homingRange;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHomingRange(float homingRange) {
|
||||
this.homingRange = homingRange;
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setFloat("speed", speed);
|
||||
nbt.setBoolean("homing", homing);
|
||||
nbt.setFloat("homingStrength", homingStrength);
|
||||
nbt.setFloat("homingRange", homingRange);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
speed = nbt.hasKey("speed") ? nbt.getFloat("speed") : 0.5f;
|
||||
homing = !nbt.hasKey("homing") || nbt.getBoolean("homing");
|
||||
homingStrength = nbt.hasKey("homingStrength") ? nbt.getFloat("homingStrength") : 0.15f;
|
||||
homingRange = nbt.hasKey("homingRange") ? nbt.getFloat("homingRange") : 20.0f;
|
||||
|
||||
// Sanitize speed to prevent stuck projectiles
|
||||
if (Float.isNaN(speed) || Float.isInfinite(speed) || speed <= 0) speed = 0.5f;
|
||||
}
|
||||
|
||||
public EnergyHomingData copy() {
|
||||
return new EnergyHomingData(speed, homing, homingStrength, homingRange);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.api.ability.data.IEnergyLifespanData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups lifespan/range properties for energy projectile abilities.
|
||||
* Used as a parameter object for entity constructors and ability configuration.
|
||||
*/
|
||||
public class EnergyLifespanData implements IEnergyLifespanData {
|
||||
public float maxDistance = 150.0f;
|
||||
public int maxLifetime = 200;
|
||||
|
||||
public EnergyLifespanData() {
|
||||
}
|
||||
|
||||
public EnergyLifespanData(float maxDistance, int maxLifetime) {
|
||||
this.maxDistance = maxDistance;
|
||||
this.maxLifetime = maxLifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxDistance() {
|
||||
return maxDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxDistance(float maxDistance) {
|
||||
this.maxDistance = Float.isNaN(maxDistance) || maxDistance <= 0 ? 150.0f : maxDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLifetime() {
|
||||
return maxLifetime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaxLifetime(int maxLifetime) {
|
||||
this.maxLifetime = maxLifetime <= 0 ? 200 : maxLifetime;
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setFloat("maxDistance", maxDistance);
|
||||
nbt.setInteger("maxLifetime", maxLifetime);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
maxDistance = nbt.getFloat("maxDistance");
|
||||
maxLifetime = nbt.getInteger("maxLifetime");
|
||||
|
||||
// Sanitize: ensure minimum values so entities don't die instantly or live forever
|
||||
if (Float.isNaN(maxDistance) || Float.isInfinite(maxDistance) || maxDistance <= 0) maxDistance = 150.0f;
|
||||
if (maxLifetime <= 0) maxLifetime = 200;
|
||||
}
|
||||
|
||||
public EnergyLifespanData copy() {
|
||||
return new EnergyLifespanData(maxDistance, maxLifetime);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.api.ability.data.IEnergyLightningData;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups lightning visual effect properties for energy abilities.
|
||||
* Used as a parameter object for entity constructors and ability configuration.
|
||||
*/
|
||||
public class EnergyLightningData implements IEnergyLightningData {
|
||||
public boolean lightningEffect = false;
|
||||
public float lightningDensity = 0.15f;
|
||||
public float lightningRadius = 0.5f;
|
||||
public int lightningFadeTime = 6;
|
||||
|
||||
public EnergyLightningData() {
|
||||
}
|
||||
|
||||
public EnergyLightningData(boolean lightningEffect, float lightningDensity,
|
||||
float lightningRadius, int lightningFadeTime) {
|
||||
this.lightningEffect = lightningEffect;
|
||||
this.lightningDensity = lightningDensity;
|
||||
this.lightningRadius = lightningRadius;
|
||||
this.lightningFadeTime = lightningFadeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLightningEffect() {
|
||||
return lightningEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightningEffect(boolean lightningEffect) {
|
||||
this.lightningEffect = lightningEffect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLightningDensity() {
|
||||
return lightningDensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightningDensity(float lightningDensity) {
|
||||
this.lightningDensity = lightningDensity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getLightningRadius() {
|
||||
return lightningRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightningRadius(float lightningRadius) {
|
||||
this.lightningRadius = lightningRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightningFadeTime() {
|
||||
return lightningFadeTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLightningFadeTime(int lightningFadeTime) {
|
||||
this.lightningFadeTime = Math.max(1, lightningFadeTime);
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setBoolean("lightningEffect", lightningEffect);
|
||||
nbt.setFloat("lightningDensity", lightningDensity);
|
||||
nbt.setFloat("lightningRadius", lightningRadius);
|
||||
nbt.setInteger("lightningFadeTime", lightningFadeTime);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
lightningEffect = nbt.hasKey("lightningEffect") && nbt.getBoolean("lightningEffect");
|
||||
lightningDensity = nbt.hasKey("lightningDensity") ? nbt.getFloat("lightningDensity") : 0.15f;
|
||||
lightningRadius = nbt.hasKey("lightningRadius") ? nbt.getFloat("lightningRadius") : 0.5f;
|
||||
lightningFadeTime = nbt.hasKey("lightningFadeTime") ? nbt.getInteger("lightningFadeTime") : 6;
|
||||
if (lightningFadeTime <= 0) lightningFadeTime = 1;
|
||||
}
|
||||
|
||||
public EnergyLightningData copy() {
|
||||
return new EnergyLightningData(lightningEffect, lightningDensity, lightningRadius, lightningFadeTime);
|
||||
}
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package kamkeel.npcs.controllers.data.ability.data.energy;
|
||||
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
/**
|
||||
* Groups panel-specific properties for energy wall/shield abilities.
|
||||
* Handles dimensions, positioning, and launch behavior.
|
||||
*/
|
||||
public class EnergyPanelData {
|
||||
public float panelWidth = 3.0f;
|
||||
public float panelHeight = 3.0f;
|
||||
public float heightOffset = 0.0f;
|
||||
public float offsetX = 0.0f;
|
||||
public float offsetZ = 0.0f;
|
||||
|
||||
// Launch properties (Wall only)
|
||||
public boolean launching = false;
|
||||
public float launchSpeed = 0.5f;
|
||||
public float launchDamage = 8.0f;
|
||||
public float launchKnockback = 2.0f;
|
||||
|
||||
public EnergyPanelData() {
|
||||
}
|
||||
|
||||
public EnergyPanelData(float panelWidth, float panelHeight, float heightOffset) {
|
||||
this.panelWidth = panelWidth;
|
||||
this.panelHeight = panelHeight;
|
||||
this.heightOffset = heightOffset;
|
||||
}
|
||||
|
||||
// ==================== GETTERS & SETTERS ====================
|
||||
|
||||
public float getPanelWidth() {
|
||||
return panelWidth;
|
||||
}
|
||||
|
||||
public void setPanelWidth(float panelWidth) {
|
||||
this.panelWidth = Math.max(0.5f, panelWidth);
|
||||
}
|
||||
|
||||
public float getPanelHeight() {
|
||||
return panelHeight;
|
||||
}
|
||||
|
||||
public void setPanelHeight(float panelHeight) {
|
||||
this.panelHeight = Math.max(0.5f, panelHeight);
|
||||
}
|
||||
|
||||
public float getHeightOffset() {
|
||||
return heightOffset;
|
||||
}
|
||||
|
||||
public void setHeightOffset(float heightOffset) {
|
||||
this.heightOffset = heightOffset;
|
||||
}
|
||||
|
||||
public boolean isLaunching() {
|
||||
return launching;
|
||||
}
|
||||
|
||||
public void setLaunching(boolean launching) {
|
||||
this.launching = launching;
|
||||
}
|
||||
|
||||
public float getLaunchSpeed() {
|
||||
return launchSpeed;
|
||||
}
|
||||
|
||||
public void setLaunchSpeed(float launchSpeed) {
|
||||
this.launchSpeed = Math.max(0.1f, launchSpeed);
|
||||
}
|
||||
|
||||
public float getLaunchDamage() {
|
||||
return launchDamage;
|
||||
}
|
||||
|
||||
public void setLaunchDamage(float launchDamage) {
|
||||
this.launchDamage = Math.max(0, launchDamage);
|
||||
}
|
||||
|
||||
public float getLaunchKnockback() {
|
||||
return launchKnockback;
|
||||
}
|
||||
|
||||
public void setLaunchKnockback(float launchKnockback) {
|
||||
this.launchKnockback = Math.max(0, launchKnockback);
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
public void writeNBT(INBTCompound nbt) {
|
||||
nbt.setFloat("panelWidth", panelWidth);
|
||||
nbt.setFloat("panelHeight", panelHeight);
|
||||
nbt.setFloat("panelHeightOffset", heightOffset);
|
||||
nbt.setFloat("panelOffsetX", offsetX);
|
||||
nbt.setFloat("panelOffsetZ", offsetZ);
|
||||
nbt.setBoolean("panelLaunching", launching);
|
||||
nbt.setFloat("panelLaunchSpeed", launchSpeed);
|
||||
nbt.setFloat("panelLaunchDamage", launchDamage);
|
||||
nbt.setFloat("panelLaunchKnockback", launchKnockback);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
panelWidth = nbt.hasKey("panelWidth") ? nbt.getFloat("panelWidth") : 3.0f;
|
||||
panelHeight = nbt.hasKey("panelHeight") ? nbt.getFloat("panelHeight") : 3.0f;
|
||||
heightOffset = nbt.hasKey("panelHeightOffset") ? nbt.getFloat("panelHeightOffset") : 0.0f;
|
||||
offsetX = nbt.hasKey("panelOffsetX") ? nbt.getFloat("panelOffsetX") : 0.0f;
|
||||
offsetZ = nbt.hasKey("panelOffsetZ") ? nbt.getFloat("panelOffsetZ") : 0.0f;
|
||||
launching = nbt.hasKey("panelLaunching") && nbt.getBoolean("panelLaunching");
|
||||
launchSpeed = nbt.hasKey("panelLaunchSpeed") ? nbt.getFloat("panelLaunchSpeed") : 0.5f;
|
||||
launchDamage = nbt.hasKey("panelLaunchDamage") ? nbt.getFloat("panelLaunchDamage") : 8.0f;
|
||||
launchKnockback = nbt.hasKey("panelLaunchKnockback") ? nbt.getFloat("panelLaunchKnockback") : 2.0f;
|
||||
}
|
||||
|
||||
public EnergyPanelData copy() {
|
||||
EnergyPanelData copy = new EnergyPanelData(panelWidth, panelHeight, heightOffset);
|
||||
copy.offsetX = offsetX;
|
||||
copy.offsetZ = offsetZ;
|
||||
copy.launching = launching;
|
||||
copy.launchSpeed = launchSpeed;
|
||||
copy.launchDamage = launchDamage;
|
||||
copy.launchKnockback = launchKnockback;
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
public class ProfileOperation {
|
||||
private final EnumProfileOperation result;
|
||||
private final String message;
|
||||
|
||||
public ProfileOperation(EnumProfileOperation result, String message) {
|
||||
this.result = result;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public EnumProfileOperation getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static ProfileOperation success(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.SUCCESS, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation error(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.ERROR, message);
|
||||
}
|
||||
|
||||
public static ProfileOperation locked(String message) {
|
||||
return new ProfileOperation(EnumProfileOperation.LOCKED, message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
package kamkeel.npcs.controllers.data.profile;
|
||||
|
||||
import noppes.npcs.api.handler.data.ISlot;
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class Slot implements ISlot {
|
||||
private int id;
|
||||
private String name;
|
||||
private long lastLoaded;
|
||||
private boolean temporary;
|
||||
private Map<String, INBTCompound> components = new HashMap<>();
|
||||
|
||||
public Slot(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Slot(int id, String name, long lastLoaded, boolean temporary, Map<String, INBTCompound> components) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.lastLoaded = lastLoaded;
|
||||
this.temporary = temporary;
|
||||
this.components = components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastLoaded() {
|
||||
return lastLoaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastLoaded(long time) {
|
||||
this.lastLoaded = time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTemporary() {
|
||||
return temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTemporary(boolean temporary) {
|
||||
this.temporary = temporary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, INBTCompound> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComponentData(String key, INBTCompound data) {
|
||||
components.put(key, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTCompound getComponentData(String key) {
|
||||
return components.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public INBTCompound toNBT() {
|
||||
INBTCompound slotNBT = NBT.compound();
|
||||
slotNBT.setString("Name", name);
|
||||
slotNBT.setLong("LastLoaded", lastLoaded);
|
||||
slotNBT.setBoolean("Temporary", temporary);
|
||||
INBTCompound compCompound = NBT.compound();
|
||||
for (Map.Entry<String, INBTCompound> entry : components.entrySet()) {
|
||||
compCompound.setCompound(entry.getKey(), entry.getValue());
|
||||
}
|
||||
slotNBT.setCompound("Components", compCompound);
|
||||
return slotNBT;
|
||||
}
|
||||
|
||||
public static Slot fromNBT(int id, INBTCompound slotNBT) {
|
||||
String name = slotNBT.getString("Name");
|
||||
long lastLoaded = slotNBT.getLong("LastLoaded");
|
||||
boolean temporary = slotNBT.getBoolean("Temporary");
|
||||
Slot slot = new Slot(id, name);
|
||||
slot.setLastLoaded(lastLoaded);
|
||||
slot.setTemporary(temporary);
|
||||
if (slotNBT.hasKey("Components")) {
|
||||
INBTCompound compCompound = slotNBT.getCompound("Components");
|
||||
Set<String> keys = compCompound.getKeySet();
|
||||
for (String key : keys) {
|
||||
slot.setComponentData(key, compCompound.getCompound(key));
|
||||
}
|
||||
}
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
package kamkeel.npcs.controllers.data.telegraph;
|
||||
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.core.NBT;
|
||||
|
||||
/**
|
||||
* Telegraph configuration - defines a visual warning shape.
|
||||
* Telegraphs warn players about incoming attacks or mark areas of effect.
|
||||
*/
|
||||
public class Telegraph {
|
||||
|
||||
// Identity
|
||||
private String id = "";
|
||||
private TelegraphType type = TelegraphType.CIRCLE;
|
||||
|
||||
// Shape parameters
|
||||
private float radius = 3.0f;
|
||||
private float innerRadius = 0.0f;
|
||||
private float length = 5.0f;
|
||||
private float width = 2.0f;
|
||||
private float angle = 45.0f;
|
||||
|
||||
// Timing
|
||||
private int durationTicks = 40;
|
||||
|
||||
// Visuals
|
||||
private int color = 0x80FF0000; // Semi-transparent red
|
||||
private int warningColor = 0xC0FF0000; // More opaque red
|
||||
private int warningStartTick = 10;
|
||||
private boolean animated = true;
|
||||
private float heightOffset = 0.1f;
|
||||
private int groundSearchRange = 3;
|
||||
|
||||
// Positioning
|
||||
private boolean atTarget = true;
|
||||
private boolean followsTarget = false;
|
||||
private boolean followsCaster = false;
|
||||
private float offsetForward = 0.0f;
|
||||
|
||||
public Telegraph() {
|
||||
}
|
||||
|
||||
public Telegraph(String id, TelegraphType type) {
|
||||
this.id = id;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Telegraph(Telegraph other) {
|
||||
this.id = other.id;
|
||||
this.type = other.type;
|
||||
this.radius = other.radius;
|
||||
this.innerRadius = other.innerRadius;
|
||||
this.length = other.length;
|
||||
this.width = other.width;
|
||||
this.angle = other.angle;
|
||||
this.durationTicks = other.durationTicks;
|
||||
this.color = other.color;
|
||||
this.warningColor = other.warningColor;
|
||||
this.warningStartTick = other.warningStartTick;
|
||||
this.animated = other.animated;
|
||||
this.heightOffset = other.heightOffset;
|
||||
this.groundSearchRange = other.groundSearchRange;
|
||||
this.atTarget = other.atTarget;
|
||||
this.followsTarget = other.followsTarget;
|
||||
this.followsCaster = other.followsCaster;
|
||||
this.offsetForward = other.offsetForward;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public INBTCompound writeNBT() {
|
||||
INBTCompound nbt = NBT.compound();
|
||||
nbt.setString("id", id);
|
||||
nbt.setString("type", type.name());
|
||||
nbt.setFloat("radius", radius);
|
||||
nbt.setFloat("innerRadius", innerRadius);
|
||||
nbt.setFloat("length", length);
|
||||
nbt.setFloat("width", width);
|
||||
nbt.setFloat("angle", angle);
|
||||
nbt.setInteger("durationTicks", durationTicks);
|
||||
nbt.setInteger("color", color);
|
||||
nbt.setInteger("warningColor", warningColor);
|
||||
nbt.setInteger("warningStartTick", warningStartTick);
|
||||
nbt.setBoolean("animated", animated);
|
||||
nbt.setFloat("heightOffset", heightOffset);
|
||||
nbt.setInteger("groundSearchRange", groundSearchRange);
|
||||
nbt.setBoolean("atTarget", atTarget);
|
||||
nbt.setBoolean("followsTarget", followsTarget);
|
||||
nbt.setBoolean("followsCaster", followsCaster);
|
||||
nbt.setFloat("offsetForward", offsetForward);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound nbt) {
|
||||
this.id = nbt.getString("id");
|
||||
if (nbt.hasKey("type")) {
|
||||
try {
|
||||
this.type = TelegraphType.valueOf(nbt.getString("type"));
|
||||
} catch (Exception e) {
|
||||
this.type = TelegraphType.CIRCLE;
|
||||
}
|
||||
}
|
||||
this.radius = nbt.getFloat("radius");
|
||||
this.innerRadius = nbt.getFloat("innerRadius");
|
||||
this.length = nbt.getFloat("length");
|
||||
this.width = nbt.getFloat("width");
|
||||
this.angle = nbt.getFloat("angle");
|
||||
this.durationTicks = nbt.getInteger("durationTicks");
|
||||
this.color = nbt.getInteger("color");
|
||||
this.warningColor = nbt.getInteger("warningColor");
|
||||
this.warningStartTick = nbt.getInteger("warningStartTick");
|
||||
this.animated = nbt.getBoolean("animated");
|
||||
this.heightOffset = nbt.getFloat("heightOffset");
|
||||
if (nbt.hasKey("groundSearchRange")) {
|
||||
this.groundSearchRange = nbt.getInteger("groundSearchRange");
|
||||
}
|
||||
this.atTarget = nbt.getBoolean("atTarget");
|
||||
this.followsTarget = nbt.getBoolean("followsTarget");
|
||||
this.followsCaster = nbt.getBoolean("followsCaster");
|
||||
this.offsetForward = nbt.getFloat("offsetForward");
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// FACTORY METHODS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public static Telegraph circle(float radius) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.CIRCLE);
|
||||
t.radius = radius;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph ring(float outerRadius, float innerRadius) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.RING);
|
||||
t.radius = outerRadius;
|
||||
t.innerRadius = innerRadius;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph line(float length, float width) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.LINE);
|
||||
t.length = length;
|
||||
t.width = width;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph cone(float length, float angle) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.CONE);
|
||||
t.length = length;
|
||||
t.angle = angle;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph cone(float length, float angle, float innerRadius) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.CONE);
|
||||
t.length = length;
|
||||
t.angle = angle;
|
||||
t.innerRadius = innerRadius;
|
||||
return t;
|
||||
}
|
||||
|
||||
public static Telegraph point() {
|
||||
return new Telegraph("", TelegraphType.POINT);
|
||||
}
|
||||
|
||||
public static Telegraph square(float radius) {
|
||||
Telegraph t = new Telegraph("", TelegraphType.SQUARE);
|
||||
t.radius = radius;
|
||||
return t;
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// GETTERS & SETTERS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public TelegraphType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(TelegraphType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public float getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
public void setRadius(float radius) {
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
public float getInnerRadius() {
|
||||
return innerRadius;
|
||||
}
|
||||
|
||||
public void setInnerRadius(float innerRadius) {
|
||||
this.innerRadius = innerRadius;
|
||||
}
|
||||
|
||||
public float getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(float length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(float width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public float getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
public void setAngle(float angle) {
|
||||
this.angle = angle;
|
||||
}
|
||||
|
||||
public int getDurationTicks() {
|
||||
return durationTicks;
|
||||
}
|
||||
|
||||
public void setDurationTicks(int durationTicks) {
|
||||
this.durationTicks = durationTicks;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getWarningColor() {
|
||||
return warningColor;
|
||||
}
|
||||
|
||||
public void setWarningColor(int warningColor) {
|
||||
this.warningColor = warningColor;
|
||||
}
|
||||
|
||||
public int getWarningStartTick() {
|
||||
return warningStartTick;
|
||||
}
|
||||
|
||||
public void setWarningStartTick(int warningStartTick) {
|
||||
this.warningStartTick = warningStartTick;
|
||||
}
|
||||
|
||||
public boolean isAnimated() {
|
||||
return animated;
|
||||
}
|
||||
|
||||
public void setAnimated(boolean animated) {
|
||||
this.animated = animated;
|
||||
}
|
||||
|
||||
public float getHeightOffset() {
|
||||
return heightOffset;
|
||||
}
|
||||
|
||||
public void setHeightOffset(float heightOffset) {
|
||||
this.heightOffset = heightOffset;
|
||||
}
|
||||
|
||||
public int getGroundSearchRange() {
|
||||
return groundSearchRange;
|
||||
}
|
||||
|
||||
public void setGroundSearchRange(int groundSearchRange) {
|
||||
this.groundSearchRange = groundSearchRange;
|
||||
}
|
||||
|
||||
public boolean isAtTarget() {
|
||||
return atTarget;
|
||||
}
|
||||
|
||||
public void setAtTarget(boolean atTarget) {
|
||||
this.atTarget = atTarget;
|
||||
}
|
||||
|
||||
public boolean isFollowsTarget() {
|
||||
return followsTarget;
|
||||
}
|
||||
|
||||
public void setFollowsTarget(boolean followsTarget) {
|
||||
this.followsTarget = followsTarget;
|
||||
}
|
||||
|
||||
public boolean isFollowsCaster() {
|
||||
return followsCaster;
|
||||
}
|
||||
|
||||
public void setFollowsCaster(boolean followsCaster) {
|
||||
this.followsCaster = followsCaster;
|
||||
}
|
||||
|
||||
public float getOffsetForward() {
|
||||
return offsetForward;
|
||||
}
|
||||
|
||||
public void setOffsetForward(float offsetForward) {
|
||||
this.offsetForward = offsetForward;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package kamkeel.npcs.developer;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Developer {
|
||||
|
||||
public static HashSet<UUID> Universal = new HashSet<>();
|
||||
public static HashSet<UUID> ScriptUser = new HashSet<>();
|
||||
public static HashSet<UUID> WandUser = new HashSet<>();
|
||||
public static HashSet<UUID> QuestMaker = new HashSet<>();
|
||||
public static Developer Instance;
|
||||
|
||||
public Developer() {
|
||||
Instance = this;
|
||||
// Temp for testing
|
||||
Universal.add(UUID.fromString("29cc52dd-2c50-4e8f-a388-be6c497cf0b4"));
|
||||
}
|
||||
|
||||
public boolean hasUniversal(UUID uuid) {
|
||||
if (Universal == null) {
|
||||
Universal = new HashSet<>();
|
||||
}
|
||||
return Universal.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasScriptUser(UUID uuid) {
|
||||
if (ScriptUser == null) {
|
||||
ScriptUser = new HashSet<>();
|
||||
}
|
||||
return ScriptUser.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasWandUser(UUID uuid) {
|
||||
return WandUser.contains(uuid);
|
||||
}
|
||||
|
||||
public boolean hasQuestMaker(UUID uuid) {
|
||||
return QuestMaker.contains(uuid);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumChannelType {
|
||||
REQUEST,
|
||||
PLAYER,
|
||||
DATA,
|
||||
INFO
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumConfigOperation {
|
||||
FONT,
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
// Packets to the Client
|
||||
public enum EnumDataPacket {
|
||||
// Synchronization
|
||||
SYNC,
|
||||
SYNC_EFFECTS,
|
||||
CONFIG_COMMAND,
|
||||
|
||||
// Messages
|
||||
CHAT_ALERT,
|
||||
ACHIEVEMENT,
|
||||
CHATBUBBLE,
|
||||
SOUND,
|
||||
DIALOG,
|
||||
QUEST_COMPLETION,
|
||||
|
||||
|
||||
// NPC
|
||||
EDIT_NPC,
|
||||
UPDATE_NPC,
|
||||
ROLE_NPC,
|
||||
DELETE_NPC,
|
||||
CLONE_NPC,
|
||||
WEAPON_NPC,
|
||||
|
||||
// Data
|
||||
SCROLL_LIST,
|
||||
SCROLL_DATA,
|
||||
SCROLL_GROUP,
|
||||
SCROLL_SELECTED,
|
||||
PARTY_DATA,
|
||||
|
||||
// GUI
|
||||
GUI_OPEN,
|
||||
GUI_REDSTONE,
|
||||
GUI_WAYPOINT,
|
||||
GUI_TELEPORTER,
|
||||
GUI_BOOK,
|
||||
GUI_DATA,
|
||||
PLAYER_DATA,
|
||||
GUI_ERROR,
|
||||
GUI_CLOSE,
|
||||
ISGUIOPEN,
|
||||
|
||||
// Visual
|
||||
SCRIPTED_PARTICLE,
|
||||
PARTICLE,
|
||||
PLAYER_UPDATE_SKIN_OVERLAYS,
|
||||
UPDATE_ANIMATIONS,
|
||||
SCRIPT_OVERLAY_DATA,
|
||||
SCRIPT_OVERLAY_CLOSE,
|
||||
OVERLAY_QUEST_TRACKING,
|
||||
MARK_DATA,
|
||||
|
||||
// Other
|
||||
VILLAGER_LIST,
|
||||
SWING_PLAYER_ARM,
|
||||
DISABLE_MOUSE_INPUT,
|
||||
LOGIN,
|
||||
|
||||
// Ability System
|
||||
TELEGRAPH_SPAWN,
|
||||
TELEGRAPH_REMOVE,
|
||||
PLAYER_ABILITY_SYNC,
|
||||
PLAYER_ABILITY_STATE,
|
||||
ABILITY_HOTBAR_SYNC,
|
||||
ABILITY_COOLDOWN_SYNC,
|
||||
|
||||
// Profile System
|
||||
PROFILE_SHARED_QUEST,
|
||||
|
||||
// Auction System
|
||||
AUCTION_DATA,
|
||||
|
||||
// Energy Charge Preview
|
||||
ENERGY_CHARGE_SPAWN,
|
||||
ENERGY_CHARGE_REMOVE,
|
||||
|
||||
// Energy Explosion Preview
|
||||
ENERGY_EXPLOSION_SPAWN,
|
||||
|
||||
// Energy Projectile Reflection Sync
|
||||
PROJECTILE_REFLECT,
|
||||
|
||||
// Energy Projectile Client Sync (position, motion, visual, and movement properties)
|
||||
PROJECTILE_CLIENT_SYNC,
|
||||
|
||||
// Energy Barrier Client Sync (visual properties and barrier-specific data)
|
||||
BARRIER_CLIENT_SYNC,
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumItemPacketType {
|
||||
WAND,
|
||||
MOUNTER,
|
||||
CLONER,
|
||||
TELEPORTER,
|
||||
SCRIPTER,
|
||||
PATHER,
|
||||
BLOCK,
|
||||
BRUSH,
|
||||
HAMMER,
|
||||
MAGIC_BOOK
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
|
||||
public enum EnumPlayerPacket {
|
||||
FollowerAction,
|
||||
Transport,
|
||||
BankAction,
|
||||
DialogSelect,
|
||||
GetPlayerValue,
|
||||
MailBoxAction,
|
||||
MailSend,
|
||||
SaveSign,
|
||||
SaveBook,
|
||||
CompanionAction,
|
||||
GetRole,
|
||||
GetTraderData,
|
||||
InputDevice,
|
||||
SpecialKeyState,
|
||||
ScreenSize,
|
||||
MagicCycles,
|
||||
|
||||
CustomGuiButton,
|
||||
CustomGuiScrollClick,
|
||||
CustomGuiClose,
|
||||
CustomGuiUnfocused,
|
||||
|
||||
GuiPaintbrush,
|
||||
GuiMagicBook,
|
||||
|
||||
ProfileCreate,
|
||||
ProfileRemove,
|
||||
ProfileRename,
|
||||
ProfileChange,
|
||||
ProfileGet,
|
||||
ProfileGetInfo,
|
||||
SyncRevisionInfo,
|
||||
|
||||
// Auction
|
||||
AuctionAction,
|
||||
|
||||
// Ability Hotbar
|
||||
AbilityHotbarSave,
|
||||
AbilityHotbarSelect,
|
||||
AbilityToggle,
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumRequestPacket {
|
||||
NPCDelete,
|
||||
RemoteMainMenu,
|
||||
RemoteGlobalMenu,
|
||||
NpcClose,
|
||||
RemoteDelete,
|
||||
RemoteFreeze,
|
||||
RemoteFreezeGet,
|
||||
RemoteReset,
|
||||
SpawnMob,
|
||||
MobSpawner,
|
||||
|
||||
DimensionsGet,
|
||||
|
||||
MainmenuAISave,
|
||||
MainmenuAIGet,
|
||||
MainmenuInvSave,
|
||||
MainmenuInvGet,
|
||||
MainmenuStatsSave,
|
||||
MainmenuStatsGet,
|
||||
MainmenuDisplaySave,
|
||||
MainmenuDisplayGet,
|
||||
ModelDataSave,
|
||||
MainmenuAdvancedSave,
|
||||
MainmenuAdvancedGet,
|
||||
MainmenuAdvancedMarkData,
|
||||
|
||||
DialogNpcSet,
|
||||
DialogNpcRemove,
|
||||
DialogNpcGet,
|
||||
DialogCategorySave,
|
||||
DialogCategoriesGet,
|
||||
DialogCategoryRemove,
|
||||
DialogCategoryGet,
|
||||
DialogSave,
|
||||
DialogsGet,
|
||||
DialogGet,
|
||||
DialogRemove,
|
||||
|
||||
TransportSave,
|
||||
TransportCategoriesGet,
|
||||
TransportCategorySave,
|
||||
TransportCategoryRemove,
|
||||
TransportRemove,
|
||||
TransportGetLocation,
|
||||
TransportsGet,
|
||||
|
||||
FactionSet,
|
||||
FactionSave,
|
||||
FactionsGet,
|
||||
FactionGet,
|
||||
FactionRemove,
|
||||
|
||||
TagSet,
|
||||
TagSave,
|
||||
TagsGet,
|
||||
TagGet,
|
||||
NpcTagsGet,
|
||||
TagRemove,
|
||||
|
||||
QuestUntrack,
|
||||
QuestLogToServer,
|
||||
QuestCategorySave,
|
||||
QuestCategoriesGet,
|
||||
QuestRemove,
|
||||
QuestCategoryRemove,
|
||||
QuestRewardSave,
|
||||
QuestSave,
|
||||
QuestsGetFromQuest,
|
||||
QuestsGet,
|
||||
QuestDialogGetTitle,
|
||||
QuestOpenGui,
|
||||
QuestGet,
|
||||
|
||||
RecipeSave,
|
||||
RecipeRemove,
|
||||
RecipesGet,
|
||||
RecipeGet,
|
||||
|
||||
NaturalSpawnSave,
|
||||
NaturalSpawnGet,
|
||||
NaturalSpawnRemove,
|
||||
NaturalSpawnGetAll,
|
||||
|
||||
MerchantUpdate,
|
||||
MountPacket,
|
||||
MovingPathSave,
|
||||
MovingPathGet,
|
||||
|
||||
AnimationsGet,
|
||||
AnimationGet,
|
||||
AnimationRemove,
|
||||
AnimationSave,
|
||||
AnimationClone,
|
||||
BuiltInAnimationGet,
|
||||
|
||||
RemoteNpcsGet,
|
||||
RemoteTpToNpc,
|
||||
TileEntitySave,
|
||||
TileEntityGet,
|
||||
Gui,
|
||||
IsGuiOpen,
|
||||
CacheAnimation,
|
||||
|
||||
PartyLogToServer,
|
||||
PartySave,
|
||||
PartyInfo,
|
||||
PartyDisband,
|
||||
PartyKick,
|
||||
PartyLeave,
|
||||
PartyInvite,
|
||||
PartyAcceptInvite,
|
||||
PartyIgnoreInvite,
|
||||
PartySetLeader,
|
||||
PartySetQuest,
|
||||
|
||||
LinkedNPCRemove,
|
||||
LinkedNPCAdd,
|
||||
LinkedGetAll,
|
||||
LinkedSet,
|
||||
LinkedGet,
|
||||
LinkedItemSave,
|
||||
LinkedItemRemove,
|
||||
LinkedItemBuild,
|
||||
LinkedItemScript,
|
||||
|
||||
BankGet,
|
||||
BanksGet,
|
||||
BankSave,
|
||||
BankRemove,
|
||||
|
||||
QuestCategoryGet,
|
||||
|
||||
PlayerDataInfo,
|
||||
PlayerDataGetNames,
|
||||
PlayerDataDeleteInfo,
|
||||
PlayerDataRemove,
|
||||
PlayerDataMapRegen,
|
||||
PlayerDataSave,
|
||||
|
||||
JobSave,
|
||||
JobGet,
|
||||
JobSpawnerAdd,
|
||||
JobSpawnerRemove,
|
||||
|
||||
RoleCompanionUpdate,
|
||||
RoleSave,
|
||||
RoleGet,
|
||||
|
||||
MailOpenSetup,
|
||||
|
||||
TransformSave,
|
||||
TransformGet,
|
||||
TransformLoad,
|
||||
|
||||
TraderMarketSave,
|
||||
|
||||
CloneList,
|
||||
CloneSave,
|
||||
CloneRemove,
|
||||
CloneTagList,
|
||||
CloneAllTags,
|
||||
CloneAllTagsShort,
|
||||
ClonePreSave,
|
||||
CloneFolderList,
|
||||
CloneFolderCrud,
|
||||
CloneMove,
|
||||
|
||||
EventScript,
|
||||
PlayerScript,
|
||||
ForgeScript,
|
||||
GlobalNPCScript,
|
||||
ItemScript,
|
||||
ItemScriptError,
|
||||
BlockScript,
|
||||
NPCScript,
|
||||
ScriptInfo,
|
||||
ScriptFiles,
|
||||
EffectScript,
|
||||
|
||||
DimensionTeleport,
|
||||
|
||||
EffectList,
|
||||
EffectGet,
|
||||
EffectScriptGet,
|
||||
EffectRemove,
|
||||
EffectSave,
|
||||
|
||||
ColorSet,
|
||||
ColorBrush,
|
||||
|
||||
MagicCycleRemove,
|
||||
MagicCycleSave,
|
||||
MagicGetAll,
|
||||
MagicRemove,
|
||||
MagicGet,
|
||||
MagicSave,
|
||||
NpcMagicGet,
|
||||
NpcMagicSave,
|
||||
NpcAbilitiesGet,
|
||||
NpcAbilitiesSave,
|
||||
AbilitiesGetAll,
|
||||
CustomAbilitiesGet,
|
||||
CustomAbilityGet,
|
||||
CustomAbilityRemove,
|
||||
CustomAbilitySave,
|
||||
BuiltInAbilityGet,
|
||||
ChainedAbilitiesGet,
|
||||
ChainedAbilityGet,
|
||||
ChainedAbilitySave,
|
||||
ChainedAbilityRemove,
|
||||
Hammer,
|
||||
|
||||
RecipeScript,
|
||||
ManageAuctionAction,
|
||||
AbilityScript,
|
||||
ChainedAbilityScript,
|
||||
|
||||
CategorySave,
|
||||
CategoryRemove,
|
||||
CategoryMoveItem,
|
||||
CategoryListRequest,
|
||||
CategoryItemsRequest,
|
||||
AbilityCategoryMoveItem,
|
||||
|
||||
CustomAbilityClone,
|
||||
ChainedAbilityClone,
|
||||
CopyAbilityScripts,
|
||||
LinkedItemClone,
|
||||
EffectClone,
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSoundOperation {
|
||||
CONTINUE_SOUNDS,
|
||||
PAUSE_SOUNDS,
|
||||
PLAY_MUSIC,
|
||||
PLAY_SOUND,
|
||||
PLAY_SOUND_TO,
|
||||
PLAY_SOUND_TO_NO_ID,
|
||||
STOP_SOUND_FOR,
|
||||
STOP_SOUNDS
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSyncAction {
|
||||
RELOAD,
|
||||
UPDATE,
|
||||
REMOVE
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package kamkeel.npcs.network.enums;
|
||||
|
||||
public enum EnumSyncType {
|
||||
FACTION,
|
||||
DIALOG,
|
||||
DIALOG_CATEGORY,
|
||||
QUEST,
|
||||
QUEST_CATEGORY,
|
||||
PLAYERDATA,
|
||||
MAGIC,
|
||||
MAGIC_CYCLE,
|
||||
WORKBENCH_RECIPES,
|
||||
CARPENTRY_RECIPES,
|
||||
ANVIL_RECIPES,
|
||||
CUSTOM_EFFECTS,
|
||||
CUSTOM_ABILITY,
|
||||
CHAINED_ABILITY
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
package kamkeel.npcs.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Formatter;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.StreamHandler;
|
||||
|
||||
/**
|
||||
* Debug logging system for CNPC+ entities.
|
||||
* Writes to logs/cnpc_debug/[type]_[side].log (file only, no console output).
|
||||
* Toggle at runtime via /cnpcdebugger [type] (client) or /kam debug [type] (server).
|
||||
*/
|
||||
public class CNPCDebug {
|
||||
|
||||
private static final String DIR = "logs/cnpc_debug";
|
||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm:ss");
|
||||
|
||||
// Runtime toggle state per type, separate for client and server
|
||||
private static final Map<String, Boolean> serverToggles = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Boolean> clientToggles = new ConcurrentHashMap<>();
|
||||
|
||||
// Per-type file handlers (lazily initialized)
|
||||
private static final Map<String, Handler> serverHandlers = new ConcurrentHashMap<>();
|
||||
private static final Map<String, Handler> clientHandlers = new ConcurrentHashMap<>();
|
||||
|
||||
// ==================== TOGGLE API ====================
|
||||
|
||||
/**
|
||||
* Toggle server-side debug for given type. Returns new state.
|
||||
*/
|
||||
public static boolean toggleServer(String type) {
|
||||
type = type.toLowerCase();
|
||||
boolean newState = !isServerEnabled(type);
|
||||
serverToggles.put(type, newState);
|
||||
if (newState) {
|
||||
ensureHandler(type, false);
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle client-side debug for given type. Returns new state.
|
||||
*/
|
||||
public static boolean toggleClient(String type) {
|
||||
type = type.toLowerCase();
|
||||
boolean newState = !isClientEnabled(type);
|
||||
clientToggles.put(type, newState);
|
||||
if (newState) {
|
||||
ensureHandler(type, true);
|
||||
}
|
||||
return newState;
|
||||
}
|
||||
|
||||
public static boolean isServerEnabled(String type) {
|
||||
Boolean val = serverToggles.get(type.toLowerCase());
|
||||
return val != null && val;
|
||||
}
|
||||
|
||||
public static boolean isClientEnabled(String type) {
|
||||
Boolean val = clientToggles.get(type.toLowerCase());
|
||||
return val != null && val;
|
||||
}
|
||||
|
||||
// ==================== LOGGING API ====================
|
||||
|
||||
/**
|
||||
* Log a debug message for the given type on the given side.
|
||||
* Callers should guard with isServerEnabled/isClientEnabled for performance.
|
||||
*/
|
||||
public static void log(String type, boolean client, String msg) {
|
||||
type = type.toLowerCase();
|
||||
Map<String, Boolean> toggles = client ? clientToggles : serverToggles;
|
||||
Boolean enabled = toggles.get(type);
|
||||
if (enabled == null || !enabled) return;
|
||||
|
||||
Handler handler = ensureHandler(type, client);
|
||||
if (handler == null) return;
|
||||
|
||||
String side = client ? "CLIENT" : "SERVER";
|
||||
String timestamp;
|
||||
synchronized (DATE_FORMAT) {
|
||||
timestamp = DATE_FORMAT.format(new Date());
|
||||
}
|
||||
String formatted = "[" + timestamp + "][" + side + "][DEBUG-" + type.toUpperCase() + "] " + msg + System.lineSeparator();
|
||||
|
||||
LogRecord record = new LogRecord(Level.INFO, formatted);
|
||||
handler.publish(record);
|
||||
handler.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log on server side.
|
||||
*/
|
||||
public static void logServer(String type, String msg) {
|
||||
log(type, false, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log on client side.
|
||||
*/
|
||||
public static void logClient(String type, String msg) {
|
||||
log(type, true, msg);
|
||||
}
|
||||
|
||||
// ==================== INTERNALS ====================
|
||||
|
||||
private static Handler ensureHandler(String type, boolean client) {
|
||||
Map<String, Handler> handlers = client ? clientHandlers : serverHandlers;
|
||||
Handler existing = handlers.get(type);
|
||||
if (existing != null) return existing;
|
||||
|
||||
synchronized (CNPCDebug.class) {
|
||||
existing = handlers.get(type);
|
||||
if (existing != null) return existing;
|
||||
|
||||
try {
|
||||
File dir = new File(DIR);
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
|
||||
String side = client ? "client" : "server";
|
||||
File file = new File(dir, type + "_" + side + ".log");
|
||||
|
||||
// Rotate old log
|
||||
if (file.exists()) {
|
||||
File backup = new File(dir, type + "_" + side + "-prev.log");
|
||||
if (backup.exists()) backup.delete();
|
||||
file.renameTo(backup);
|
||||
}
|
||||
|
||||
Handler handler = new StreamHandler(new FileOutputStream(file), new Formatter() {
|
||||
@Override
|
||||
public String format(LogRecord record) {
|
||||
return record.getMessage();
|
||||
}
|
||||
});
|
||||
handler.setLevel(Level.ALL);
|
||||
handlers.put(type, handler);
|
||||
|
||||
// Log header
|
||||
String timestamp;
|
||||
synchronized (DATE_FORMAT) {
|
||||
timestamp = DATE_FORMAT.format(new Date());
|
||||
}
|
||||
LogRecord header = new LogRecord(Level.INFO,
|
||||
"[" + timestamp + "][" + (client ? "CLIENT" : "SERVER") + "][DEBUG-" + type.toUpperCase() + "] Debug logging started" + System.lineSeparator());
|
||||
handler.publish(header);
|
||||
handler.flush();
|
||||
|
||||
return handler;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,522 @@
|
||||
package noppes.npcs;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Core NBT serialization utilities for Map/Set/List collections.
|
||||
* Uses INBTCompound/INBTList abstractions.
|
||||
*
|
||||
* NOTE: ItemStack-related methods, IScriptUnit methods, and raw NBT type methods
|
||||
* (nbtDoubleList, getIntAt) remain in the mc1710 version only since they require
|
||||
* direct MC types.
|
||||
*/
|
||||
public class NBTTags {
|
||||
|
||||
public static int TAG_End = 0;
|
||||
public static int TAG_Byte = 1;
|
||||
public static int TAG_Short = 2;
|
||||
public static int TAG_Int = 3;
|
||||
public static int TAG_Long = 4;
|
||||
public static int TAG_Float = 5;
|
||||
public static int TAG_Double = 6;
|
||||
public static int TAG_Byte_Array = 7;
|
||||
public static int TAG_String = 8;
|
||||
public static int TAG_List = 9;
|
||||
public static int TAG_Compound = 10;
|
||||
public static int TAG_Int_Array = 11;
|
||||
|
||||
// TODO: ItemStack methods stay in mc1710 version:
|
||||
// OLD: getItemStackList(NBTTagList) - uses NoppesUtilServer.readItem()
|
||||
// OLD: getItemStackArray(NBTTagList) - uses NoppesUtilServer.readItem()
|
||||
// OLD: nbtItemStackList(HashMap<Integer, ItemStack>) - uses NoppesUtilServer.writeItem()
|
||||
// OLD: nbtItemStackArray(ItemStack[]) - uses NoppesUtilServer.writeItem()
|
||||
|
||||
public static ArrayList<int[]> getIntegerArraySet(INBTList tagList) {
|
||||
ArrayList<int[]> set = new ArrayList<int[]>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound compound = tagList.getCompound(i);
|
||||
set.add(compound.getIntArray("Array"));
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Boolean> getBooleanList(INBTList tagList) {
|
||||
HashMap<Integer, Boolean> list = new HashMap<Integer, Boolean>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getBoolean("Boolean"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Integer> getIntegerIntegerMap(INBTList tagList) {
|
||||
HashMap<Integer, Integer> list = new HashMap<Integer, Integer>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getInteger("Integer"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Float> getIntegerFloatMap(INBTList tagList) {
|
||||
HashMap<Integer, Float> list = new HashMap<Integer, Float>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getFloat("Float"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Double> getIntegerDoubleMap(INBTList tagList) {
|
||||
HashMap<Integer, Double> list = new HashMap<Integer, Double>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getDouble("Double"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Long> getIntegerLongMap(INBTList tagList) {
|
||||
HashMap<Integer, Long> list = new HashMap<Integer, Long>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getLong("Long"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashSet<String> getStringSet(INBTList tagList) {
|
||||
HashSet<String> list = new HashSet<>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.add(nbttagcompound.getString("String"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, Byte> getIntegerByteMap(INBTList tagList) {
|
||||
HashMap<Integer, Byte> list = new HashMap<Integer, Byte>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getByte("Byte"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerByteMap(Map<Integer, Byte> lines) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (lines == null)
|
||||
return nbttaglist;
|
||||
for (int slot : lines.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setByte("Byte", lines.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringSet(HashSet<String> collection) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (collection == null)
|
||||
return nbttaglist;
|
||||
for (String slot : collection) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("String", slot);
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static HashSet<Integer> getIntegerSet(INBTList tagList) {
|
||||
HashSet<Integer> list = new HashSet<Integer>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.add(nbttagcompound.getInteger("Integer"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerSet(HashSet<Integer> set) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (set == null)
|
||||
return nbttaglist;
|
||||
for (int slot : set) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Integer", slot);
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static HashMap<String, String> getStringStringMap(INBTList tagList) {
|
||||
HashMap<String, String> list = new HashMap<String, String>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getString("Value"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<Integer, String> getIntegerStringMap(INBTList tagList) {
|
||||
HashMap<Integer, String> list = new HashMap<Integer, String>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getString("Value"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<String, Integer> getStringIntegerMap(INBTList tagList) {
|
||||
HashMap<String, Integer> list = new HashMap<String, Integer>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getInteger("Value"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<String, int[]> getStringIntegerArrayMap(INBTList tagList) {
|
||||
HashMap<String, int[]> list = new HashMap<String, int[]>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getIntArray("Value"));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<String, int[]> getStringIntegerArrayMap(INBTList tagList, int arrayLength) {
|
||||
HashMap<String, int[]> list = new HashMap<String, int[]>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
int[] a = nbttagcompound.getIntArray("Value");
|
||||
if (a.length != arrayLength) a = new int[arrayLength];
|
||||
list.put(nbttagcompound.getString("Slot"), a);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static HashMap<String, Vector<String>> getVectorMap(INBTList tagList) {
|
||||
HashMap<String, Vector<String>> map = new HashMap<String, Vector<String>>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
Vector<String> values = new Vector<String>();
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
INBTList list = nbttagcompound.getList("Values", 10);
|
||||
for (int j = 0; j < list.size(); j++) {
|
||||
INBTCompound value = list.getCompound(j);
|
||||
values.add(value.getString("Value"));
|
||||
}
|
||||
|
||||
map.put(nbttagcompound.getString("Key"), values);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> getStringList(INBTList tagList) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
String line = nbttagcompound.getString("Line");
|
||||
list.add(line);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static String[] getStringArray(INBTList tagList, int size) {
|
||||
String[] arr = new String[size];
|
||||
for (int i = 0; i < tagList.size(); i++) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
String line = nbttagcompound.getString("Value");
|
||||
int slot = nbttagcompound.getInteger("Slot");
|
||||
arr[slot] = line;
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerArraySet(List<int[]> set) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (set == null)
|
||||
return nbttaglist;
|
||||
for (int[] arr : set) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setIntArray("Array", arr);
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtBooleanList(HashMap<Integer, Boolean> updatedSlots) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (updatedSlots == null)
|
||||
return nbttaglist;
|
||||
HashMap<Integer, Boolean> inventory2 = updatedSlots;
|
||||
for (Integer slot : inventory2.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setBoolean("Boolean", inventory2.get(slot));
|
||||
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerIntegerMap(Map<Integer, Integer> lines) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (lines == null)
|
||||
return nbttaglist;
|
||||
for (int slot : lines.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setInteger("Integer", lines.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerFloatMap(Map<Integer, Float> lines) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (lines == null)
|
||||
return nbttaglist;
|
||||
for (int slot : lines.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setDouble("Float", lines.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerDoubleMap(Map<Integer, Double> lines) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (lines == null)
|
||||
return nbttaglist;
|
||||
for (int slot : lines.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setDouble("Double", lines.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerLongMap(Map<Integer, Long> lines) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (lines == null)
|
||||
return nbttaglist;
|
||||
for (int slot : lines.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setLong("Long", lines.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtVectorMap(Map<String, Vector<String>> map) {
|
||||
INBTList list = NBT.list();
|
||||
if (map == null)
|
||||
return list;
|
||||
for (String key : map.keySet()) {
|
||||
INBTCompound compound = NBT.compound();
|
||||
compound.setString("Key", key);
|
||||
INBTList values = NBT.list();
|
||||
for (String value : map.get(key)) {
|
||||
INBTCompound comp = NBT.compound();
|
||||
comp.setString("Value", value);
|
||||
values.addCompound(comp);
|
||||
}
|
||||
compound.setList("Values", values);
|
||||
list.addCompound(compound);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringStringMap(Map<String, String> map) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (map == null)
|
||||
return nbttaglist;
|
||||
for (String slot : map.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("Slot", slot);
|
||||
nbttagcompound.setString("Value", map.get(slot));
|
||||
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringIntegerMap(Map<String, Integer> map) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (map == null)
|
||||
return nbttaglist;
|
||||
for (String slot : map.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("Slot", slot);
|
||||
nbttagcompound.setInteger("Value", map.get(slot));
|
||||
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringIntegerArrayMap(Map<String, int[]> map) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (map == null)
|
||||
return nbttaglist;
|
||||
for (String slot : map.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("Slot", slot);
|
||||
nbttagcompound.setIntArray("Value", map.get(slot));
|
||||
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtIntegerStringMap(HashMap<Integer, String> map) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (map == null)
|
||||
return nbttaglist;
|
||||
for (int slot : map.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("Slot", slot);
|
||||
nbttagcompound.setString("Value", map.get(slot));
|
||||
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringArray(String[] list) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (list == null)
|
||||
return nbttaglist;
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
if (list[i] == null)
|
||||
continue;
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("Value", list[i]);
|
||||
nbttagcompound.setInteger("Slot", i);
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public static INBTList nbtStringList(List<String> list) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
for (String s : list) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setString("Line", s);
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
// TODO: nbtDoubleList stays in mc1710 version - uses NBTTagDouble directly
|
||||
// OLD: public static NBTTagList nbtDoubleList(double... par1ArrayOfDouble)
|
||||
|
||||
public static INBTCompound NBTMerge(INBTCompound data, INBTCompound merge) {
|
||||
INBTCompound compound = data.copy();
|
||||
Set<String> names = merge.getKeySet();
|
||||
for (String name : names) {
|
||||
int type = merge.getTagType(name);
|
||||
if (type == TAG_Compound)
|
||||
compound.setCompound(name, NBTMerge(compound.getCompound(name), merge.getCompound(name)));
|
||||
else {
|
||||
// For non-compound types, copy from merge.
|
||||
// We need to handle by type since INBTCompound doesn't have a raw getTag/setTag.
|
||||
copyTag(compound, merge, name, type);
|
||||
}
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy a single tag from source to dest by type.
|
||||
* Used by NBTMerge for non-compound types.
|
||||
*/
|
||||
private static void copyTag(INBTCompound dest, INBTCompound source, String key, int type) {
|
||||
switch (type) {
|
||||
case 1: // Byte
|
||||
dest.setByte(key, source.getByte(key));
|
||||
break;
|
||||
case 2: // Short
|
||||
dest.setShort(key, source.getShort(key));
|
||||
break;
|
||||
case 3: // Int
|
||||
dest.setInteger(key, source.getInteger(key));
|
||||
break;
|
||||
case 4: // Long
|
||||
dest.setLong(key, source.getLong(key));
|
||||
break;
|
||||
case 5: // Float
|
||||
dest.setFloat(key, source.getFloat(key));
|
||||
break;
|
||||
case 6: // Double
|
||||
dest.setDouble(key, source.getDouble(key));
|
||||
break;
|
||||
case 7: // Byte Array
|
||||
dest.setByteArray(key, source.getByteArray(key));
|
||||
break;
|
||||
case 8: // String
|
||||
dest.setString(key, source.getString(key));
|
||||
break;
|
||||
case 9: // List
|
||||
dest.setList(key, source.getList(key, 0));
|
||||
break;
|
||||
case 10: // Compound (handled above in NBTMerge)
|
||||
dest.setCompound(key, source.getCompound(key));
|
||||
break;
|
||||
case 11: // Int Array
|
||||
dest.setIntArray(key, source.getIntArray(key));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static TreeMap<Long, String> GetLongStringMap(INBTList tagList) {
|
||||
TreeMap<Long, String> list = new TreeMap<>();
|
||||
|
||||
for (int i = 0; i < tagList.size(); ++i) {
|
||||
INBTCompound nbttagcompound = tagList.getCompound(i);
|
||||
list.put(nbttagcompound.getLong("Long"), nbttagcompound.getString("String"));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static INBTList NBTLongStringMap(Map<Long, String> map) {
|
||||
INBTList nbttaglist = NBT.list();
|
||||
if (map == null) {
|
||||
return nbttaglist;
|
||||
} else {
|
||||
for (long slot : map.keySet()) {
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setLong("Long", slot);
|
||||
nbttagcompound.setString("String", map.get(slot));
|
||||
nbttaglist.addCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
return nbttaglist;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Script methods stay in mc1710 version - use IScriptHandler/IScriptUnit/NBTTagCompound directly
|
||||
// OLD: public static List<IScriptUnit> GetScriptOld(NBTTagList list, IScriptHandler handler)
|
||||
// OLD: public static List<IScriptUnit> GetScript(NBTTagCompound compound, IScriptHandler handler)
|
||||
// OLD: public static NBTTagList NBTScript(List<IScriptUnit> scripts)
|
||||
|
||||
// TODO: getIntAt stays in mc1710 version - uses NBTTagInt.func_150287_d() directly
|
||||
// OLD: public static int getIntAt(NBTTagList tagList, int index)
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class APIRegistry {
|
||||
public static final APIRegistry Instance = new APIRegistry();
|
||||
|
||||
private final LinkedHashMap<String, String> entries = new LinkedHashMap<>();
|
||||
|
||||
public void register(String name, String url) {
|
||||
entries.put(name, url);
|
||||
}
|
||||
|
||||
public void unregister(String name) {
|
||||
entries.remove(name);
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, String> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return entries.size();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.controllers.data.Category;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Filesystem-based category manager for organizing items into named groups.
|
||||
* Categories are subdirectories within the controller's base directory.
|
||||
* Items without a category mapping are "Uncategorized" (root-level files).
|
||||
*
|
||||
* One instance per controller (Effect, Animation, LinkedItem, Form, Aura, Outline, etc.)
|
||||
*/
|
||||
public class CategoryManager {
|
||||
public static final int UNCATEGORIZED_ID = 0;
|
||||
public static final String UNCATEGORIZED_NAME = "Uncategorized";
|
||||
|
||||
private File baseDir;
|
||||
private final HashMap<Integer, Category> categories = new HashMap<>();
|
||||
private final HashMap<Integer, Integer> itemCategoryMap = new HashMap<>();
|
||||
private int lastUsedCatID = 0;
|
||||
|
||||
/**
|
||||
* Scan the base directory for subdirectories and create Category objects.
|
||||
* Call at the start of controller loading, before loading items.
|
||||
*/
|
||||
public void loadCategories(File baseDir) {
|
||||
loadCategories(baseDir, new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scan the base directory for subdirectories and create Category objects,
|
||||
* excluding any subdirectories whose names match excludeDirs.
|
||||
*/
|
||||
public void loadCategories(File baseDir, String... excludeDirs) {
|
||||
this.baseDir = baseDir;
|
||||
categories.clear();
|
||||
itemCategoryMap.clear();
|
||||
lastUsedCatID = 0;
|
||||
|
||||
if (!baseDir.exists()) return;
|
||||
|
||||
Set<String> excludeSet = new HashSet<>(Arrays.asList(excludeDirs));
|
||||
File[] files = baseDir.listFiles();
|
||||
if (files == null) return;
|
||||
for (File sub : files) {
|
||||
if (!sub.isDirectory()) continue;
|
||||
if (excludeSet.contains(sub.getName())) continue;
|
||||
lastUsedCatID++;
|
||||
categories.put(lastUsedCatID, new Category(lastUsedCatID, sub.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an item as belonging to a category.
|
||||
* Call when loading items from a subdirectory.
|
||||
*/
|
||||
public void registerItem(int itemId, int catId) {
|
||||
if (catId > UNCATEGORIZED_ID) {
|
||||
itemCategoryMap.put(itemId, catId);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeItem(int itemId) {
|
||||
itemCategoryMap.remove(itemId);
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return baseDir != null;
|
||||
}
|
||||
|
||||
public File getItemDir(int itemId) {
|
||||
int catId = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
return getCategoryDir(catId);
|
||||
}
|
||||
|
||||
public File getCategoryDir(int catId) {
|
||||
if (catId == UNCATEGORIZED_ID) return baseDir;
|
||||
Category cat = categories.get(catId);
|
||||
if (cat != null) return new File(baseDir, cat.title);
|
||||
return baseDir;
|
||||
}
|
||||
|
||||
public HashMap<Integer, Category> getCategories() {
|
||||
return categories;
|
||||
}
|
||||
|
||||
// ========== Category CRUD ==========
|
||||
|
||||
public Category createCategory(String name) {
|
||||
if (baseDir == null) return null;
|
||||
while (hasCategoryName(name)) name += "_";
|
||||
lastUsedCatID++;
|
||||
Category cat = new Category(lastUsedCatID, name);
|
||||
categories.put(cat.id, cat);
|
||||
File dir = new File(baseDir, name);
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
return cat;
|
||||
}
|
||||
|
||||
public void saveCategory(Category cat) {
|
||||
if (cat.id <= 0 || baseDir == null) return;
|
||||
Category existing = categories.get(cat.id);
|
||||
if (existing != null && !existing.title.equals(cat.title)) {
|
||||
String newTitle = cat.title;
|
||||
while (hasCategoryName(newTitle)) newTitle += "_";
|
||||
File oldDir = new File(baseDir, existing.title);
|
||||
File newDir = new File(baseDir, newTitle);
|
||||
if (oldDir.exists() && !newDir.exists()) {
|
||||
oldDir.renameTo(newDir);
|
||||
}
|
||||
cat.title = newTitle;
|
||||
}
|
||||
categories.put(cat.id, cat);
|
||||
}
|
||||
|
||||
public boolean removeCategory(int catId) {
|
||||
return removeCategory(catId, null);
|
||||
}
|
||||
|
||||
public boolean removeCategory(int catId, Set<Integer> allItemIds) {
|
||||
if (baseDir == null) return false;
|
||||
if (catId <= UNCATEGORIZED_ID) return false;
|
||||
Category cat = categories.get(catId);
|
||||
if (cat == null) return false;
|
||||
|
||||
// Server-side guard: refuse to delete if category has items
|
||||
if (allItemIds != null) {
|
||||
if (!isCategoryEmpty(catId, allItemIds)) return false;
|
||||
} else {
|
||||
// Without item set, check if any items are mapped to this category
|
||||
if (itemCategoryMap.containsValue(catId)) return false;
|
||||
}
|
||||
|
||||
// Also check filesystem — directory must be empty or non-existent
|
||||
File dir = new File(baseDir, cat.title);
|
||||
if (dir.exists()) {
|
||||
String[] contents = dir.list();
|
||||
if (contents != null && contents.length > 0) {
|
||||
return false;
|
||||
}
|
||||
dir.delete();
|
||||
}
|
||||
|
||||
categories.remove(catId);
|
||||
Iterator<Map.Entry<Integer, Integer>> it = itemCategoryMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
if (it.next().getValue() == catId) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void moveItem(int itemId, String fileName, int destCatId) {
|
||||
if (baseDir == null) return;
|
||||
int oldCatId = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
if (oldCatId == destCatId) return;
|
||||
|
||||
File oldDir = getCategoryDir(oldCatId);
|
||||
File newDir = getCategoryDir(destCatId);
|
||||
if (!newDir.exists()) newDir.mkdirs();
|
||||
|
||||
File oldFile = new File(oldDir, fileName);
|
||||
File newFile = new File(newDir, fileName);
|
||||
if (oldFile.exists()) {
|
||||
oldFile.renameTo(newFile);
|
||||
}
|
||||
|
||||
if (destCatId == UNCATEGORIZED_ID) {
|
||||
itemCategoryMap.remove(itemId);
|
||||
} else {
|
||||
itemCategoryMap.put(itemId, destCatId);
|
||||
}
|
||||
}
|
||||
|
||||
// ========== Query ==========
|
||||
|
||||
public boolean hasCategoryName(String name) {
|
||||
for (Category cat : categories.values()) {
|
||||
if (cat.title.equalsIgnoreCase(name)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCategoryEmpty(int catId, Set<Integer> allItemIds) {
|
||||
if (catId == UNCATEGORIZED_ID) {
|
||||
for (int id : allItemIds) {
|
||||
if (!itemCategoryMap.containsKey(id)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
for (Map.Entry<Integer, Integer> entry : itemCategoryMap.entrySet()) {
|
||||
if (entry.getValue() == catId && allItemIds.contains(entry.getKey())) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public Category getCategory(int catId) {
|
||||
return categories.get(catId);
|
||||
}
|
||||
|
||||
public int getItemCategory(int itemId) {
|
||||
return itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
}
|
||||
|
||||
public List<Integer> getItemsInCategory(int catId, Set<Integer> allItemIds) {
|
||||
List<Integer> result = new ArrayList<>();
|
||||
for (int itemId : allItemIds) {
|
||||
int assignedCat = itemCategoryMap.getOrDefault(itemId, UNCATEGORIZED_ID);
|
||||
if (assignedCat == catId) {
|
||||
result.add(itemId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ========== Scroll Data ==========
|
||||
|
||||
public Map<String, Integer> getCategoryScrollData() {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
map.put(UNCATEGORIZED_NAME, UNCATEGORIZED_ID);
|
||||
for (Category cat : categories.values()) {
|
||||
map.put(cat.title, cat.id);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search all directories (root + subdirectories) for a file and delete it.
|
||||
*/
|
||||
public void deleteFile(String fileName) {
|
||||
if (baseDir == null || !baseDir.exists()) return;
|
||||
|
||||
File file = new File(baseDir, fileName);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
return;
|
||||
}
|
||||
|
||||
File[] subs = baseDir.listFiles();
|
||||
if (subs != null) {
|
||||
for (File sub : subs) {
|
||||
if (!sub.isDirectory()) continue;
|
||||
File subFile = new File(sub, fileName);
|
||||
if (subFile.exists()) {
|
||||
subFile.delete();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.controllers.data.Faction;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class FactionController {
|
||||
public HashMap<Integer, Faction> factionsSync = new HashMap<Integer, Faction>();
|
||||
public HashMap<Integer, Faction> factions;
|
||||
|
||||
private static FactionController instance = new FactionController();
|
||||
|
||||
private int lastUsedID = 0;
|
||||
|
||||
// TODO: mc1710 version implements IFactionHandler and adds:
|
||||
// OLD: public List<IFaction> list()
|
||||
// OLD: public IFaction delete(int id) — also calls SyncController.syncRemove(EnumSyncType.FACTION, id)
|
||||
// OLD: public IFaction create(String name, int defaultPoints)
|
||||
|
||||
public FactionController() {
|
||||
instance = this;
|
||||
factions = new HashMap<Integer, Faction>();
|
||||
}
|
||||
|
||||
public static FactionController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Faction getFaction(int faction) {
|
||||
return factions.get(faction);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
factions = new HashMap<Integer, Faction>();
|
||||
lastUsedID = 0;
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
if (saveDir == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
File file = new File(saveDir, "factions.dat");
|
||||
if (file.exists()) {
|
||||
loadFactionsFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "factions.dat_old");
|
||||
if (file.exists()) {
|
||||
loadFactionsFile(file);
|
||||
}
|
||||
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
|
||||
if (factions.isEmpty()) {
|
||||
factions.put(0, new Faction(0, "Friendly", 0x00DD00, 2000));
|
||||
factions.put(1, new Faction(1, "Neutral", 0xF2DD00, 1000));
|
||||
factions.put(2, new Faction(2, "Aggressive", 0xDD0000, 0));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadFactionsFile(File file) throws Exception {
|
||||
// OLD: DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
|
||||
// OLD: loadFactions(var1);
|
||||
// OLD: var1.close();
|
||||
INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
loadFactions(nbttagcompound1);
|
||||
}
|
||||
|
||||
public void loadFactions(INBTCompound nbttagcompound1) {
|
||||
HashMap<Integer, Faction> factions = new HashMap<Integer, Faction>();
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
INBTList list = nbttagcompound1.getList("NPCFactions", 10);
|
||||
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
INBTCompound nbttagcompound = list.getCompound(i);
|
||||
Faction faction = new Faction();
|
||||
faction.readNBT(nbttagcompound);
|
||||
factions.put(faction.id, faction);
|
||||
}
|
||||
}
|
||||
this.factions = factions;
|
||||
}
|
||||
|
||||
public INBTCompound getNBT() {
|
||||
INBTList list = NBT.list();
|
||||
for (int slot : factions.keySet()) {
|
||||
Faction faction = factions.get(slot);
|
||||
INBTCompound nbtfactions = NBT.compound();
|
||||
faction.writeNBT(nbtfactions);
|
||||
list.addCompound(nbtfactions);
|
||||
}
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("lastID", lastUsedID);
|
||||
nbttagcompound.setList("NPCFactions", list);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void saveFactions() {
|
||||
try {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
File file = new File(saveDir, "factions.dat_new");
|
||||
File file1 = new File(saveDir, "factions.dat_old");
|
||||
File file2 = new File(saveDir, "factions.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(getNBT(), file);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// OLD: LogWriter.except(e);
|
||||
PlatformServiceHolder.get().logError("Error saving faction data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Faction get(int faction) {
|
||||
return factions.get(faction);
|
||||
}
|
||||
|
||||
public void saveFaction(Faction faction) {
|
||||
|
||||
if (faction.id < 0) {
|
||||
faction.id = getUnusedId();
|
||||
while (hasName(faction.name))
|
||||
faction.name += "_";
|
||||
} else {
|
||||
Faction existing = factions.get(faction.id);
|
||||
if (existing != null && !existing.name.equals(faction.name))
|
||||
while (hasName(faction.name))
|
||||
faction.name += "_";
|
||||
}
|
||||
factions.remove(faction.id);
|
||||
factions.put(faction.id, faction);
|
||||
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: NBTTagCompound facCompound = new NBTTagCompound();
|
||||
// OLD: faction.writeNBT(facCompound);
|
||||
// OLD: SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
|
||||
saveFactions();
|
||||
}
|
||||
|
||||
public Faction create(Faction faction) {
|
||||
this.saveFaction(faction);
|
||||
return faction;
|
||||
}
|
||||
|
||||
public Faction create(String name, int color) {
|
||||
Faction faction = new Faction();
|
||||
faction.name = name;
|
||||
faction.color = color;
|
||||
this.saveFaction(faction);
|
||||
return faction;
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
if (lastUsedID == 0) {
|
||||
for (int catid : factions.keySet())
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
if (id >= 0 && this.factions.size() > 1) {
|
||||
Faction faction = this.factions.remove(id);
|
||||
if (faction != null) {
|
||||
this.saveFactions();
|
||||
faction.id = -1;
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: SyncController.syncRemove(EnumSyncType.FACTION, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int getFirstFactionId() {
|
||||
return factions.keySet().iterator().next();
|
||||
}
|
||||
|
||||
public Faction getFirstFaction() {
|
||||
return factions.values().iterator().next();
|
||||
}
|
||||
|
||||
public boolean hasName(String newName) {
|
||||
if (newName.trim().isEmpty())
|
||||
return true;
|
||||
for (Faction faction : factions.values())
|
||||
if (faction.name.equals(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Faction getFactionFromName(String factioname) {
|
||||
for (Map.Entry<Integer, Faction> entryfaction : FactionController.getInstance().factions.entrySet()) {
|
||||
if (entryfaction.getValue().name.equalsIgnoreCase(factioname)) {
|
||||
return entryfaction.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
String[] names = new String[factions.size()];
|
||||
int i = 0;
|
||||
for (Faction faction : factions.values()) {
|
||||
names[i] = faction.name.toLowerCase();
|
||||
i++;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import static noppes.npcs.util.CustomNPCsThreader.customNPCThread;
|
||||
|
||||
public class GlobalDataController {
|
||||
public static GlobalDataController Instance;
|
||||
private int itemGiverId = 0;
|
||||
|
||||
public GlobalDataController() {
|
||||
Instance = this;
|
||||
load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
try {
|
||||
File file = new File(saveDir, "global.dat");
|
||||
if (file.exists()) {
|
||||
loadData(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "global.dat_old");
|
||||
if (file.exists()) {
|
||||
loadData(file);
|
||||
}
|
||||
|
||||
} catch (Exception ee) {
|
||||
ee.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadData(File file) throws Exception {
|
||||
// OLD: NBTTagCompound nbttagcompound1;
|
||||
// OLD: try (FileInputStream fis = new FileInputStream(file)) {
|
||||
// OLD: nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
// OLD: }
|
||||
INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
itemGiverId = nbttagcompound1.getInteger("itemGiverId");
|
||||
}
|
||||
|
||||
public void saveData() {
|
||||
customNPCThread.execute(() -> {
|
||||
try {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
|
||||
// OLD: NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("itemGiverId", itemGiverId);
|
||||
|
||||
File file = new File(saveDir, "global.dat_new");
|
||||
File file1 = new File(saveDir, "global.dat_old");
|
||||
File file2 = new File(saveDir, "global.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(nbttagcompound, new FileOutputStream(file));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(nbttagcompound, file);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int incrementItemGiverId() {
|
||||
itemGiverId++;
|
||||
saveData();
|
||||
return itemGiverId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,384 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.constants.EnumDiagramLayout;
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.controllers.data.Magic;
|
||||
import noppes.npcs.controllers.data.MagicAssociation;
|
||||
import noppes.npcs.controllers.data.MagicCycle;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MagicController {
|
||||
public HashMap<Integer, Magic> magics = new HashMap<>();
|
||||
public HashMap<Integer, Magic> magicSync = new HashMap<>();
|
||||
|
||||
public HashMap<Integer, MagicCycle> cycles = new HashMap<>();
|
||||
public HashMap<Integer, MagicCycle> cyclesSync = new HashMap<>();
|
||||
|
||||
public int lastUsedCycleID = 0;
|
||||
private int lastUsedMagicID = 0;
|
||||
|
||||
private static MagicController instance;
|
||||
|
||||
// TODO: mc1710 version implements IMagicHandler and adds:
|
||||
// OLD: public Magic getMagic(int magicId) — @Override from IMagicHandler
|
||||
// OLD: public MagicCycle getCycle(int cycleID) — @Override from IMagicHandler
|
||||
// OLD: public void addMagicToCycle(int magicId, int cycleId, int index, int priority) — @Override
|
||||
// OLD: public void removeMagicFromCycle(int magicId, int cycleId) — @Override
|
||||
|
||||
public MagicController() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
public static MagicController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Magic getMagic(int magicId) {
|
||||
return magics.get(magicId);
|
||||
}
|
||||
|
||||
public MagicCycle getCycle(int cycleID) {
|
||||
return cycles.get(cycleID);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
magics.clear();
|
||||
cycles.clear();
|
||||
|
||||
lastUsedCycleID = 0;
|
||||
lastUsedMagicID = 0;
|
||||
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
if (saveDir == null) return;
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat");
|
||||
if (file.exists()) {
|
||||
loadMagicFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "magic.dat_old");
|
||||
if (file.exists()) {
|
||||
loadMagicFile(file);
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
|
||||
if (magics.isEmpty() && cycles.isEmpty()) {
|
||||
createDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates default magic entries. Override in mc1710 to set ItemStack items.
|
||||
*/
|
||||
protected void createDefaults() {
|
||||
// TODO: mc1710 version sets ItemStack items on each magic:
|
||||
// OLD: earth.setItem(new ItemStack(CustomItems.earthElement));
|
||||
// OLD: water.setItem(new ItemStack(CustomItems.waterElement));
|
||||
// OLD: fire.setItem(new ItemStack(CustomItems.spellFire));
|
||||
// OLD: air.setItem(new ItemStack(CustomItems.airElement));
|
||||
// OLD: dark.setItem(new ItemStack(CustomItems.spellDark));
|
||||
// OLD: holy.setItem(new ItemStack(CustomItems.spellHoly));
|
||||
// OLD: nature.setItem(new ItemStack(CustomItems.spellNature));
|
||||
// OLD: arcane.setItem(new ItemStack(CustomItems.spellArcane));
|
||||
|
||||
Magic earth = new Magic(getUnusedId(), "Earth", 0x00DD00);
|
||||
Magic water = new Magic(getUnusedId(), "Water", 0xF2DD00);
|
||||
Magic fire = new Magic(getUnusedId(), "Fire", 0xDD0000);
|
||||
Magic air = new Magic(getUnusedId(), "Air", 0xDD0000);
|
||||
Magic dark = new Magic(getUnusedId(), "Dark", 0xDD0000);
|
||||
Magic holy = new Magic(getUnusedId(), "Holy", 0xDD0000);
|
||||
Magic nature = new Magic(getUnusedId(), "Nature", 0xDD0000);
|
||||
Magic arcane = new Magic(getUnusedId(), "Arcane", 0xDD0000);
|
||||
|
||||
// Insiders
|
||||
earth.interactions.put(air.id, -0.50f);
|
||||
air.interactions.put(earth.id, 0.50f);
|
||||
|
||||
water.interactions.put(earth.id, -0.50f);
|
||||
earth.interactions.put(water.id, 0.50f);
|
||||
|
||||
fire.interactions.put(water.id, -0.50f);
|
||||
water.interactions.put(fire.id, 0.50f);
|
||||
|
||||
air.interactions.put(fire.id, -0.50f);
|
||||
fire.interactions.put(air.id, 0.50f);
|
||||
|
||||
// Outsiders
|
||||
dark.interactions.put(nature.id, -0.50f);
|
||||
nature.interactions.put(dark.id, 0.50f);
|
||||
|
||||
nature.interactions.put(holy.id, -0.50f);
|
||||
holy.interactions.put(nature.id, 0.50f);
|
||||
|
||||
holy.interactions.put(arcane.id, -0.50f);
|
||||
arcane.interactions.put(holy.id, 0.50f);
|
||||
|
||||
arcane.interactions.put(dark.id, -0.50f);
|
||||
dark.interactions.put(arcane.id, 0.50f);
|
||||
|
||||
// Cross Interactions
|
||||
earth.interactions.put(nature.id, -0.25f);
|
||||
nature.interactions.put(earth.id, 0.25f);
|
||||
|
||||
water.interactions.put(holy.id, -0.25f);
|
||||
holy.interactions.put(water.id, 0.25f);
|
||||
|
||||
fire.interactions.put(arcane.id, -0.25f);
|
||||
arcane.interactions.put(fire.id, 0.25f);
|
||||
|
||||
air.interactions.put(dark.id, -0.25f);
|
||||
dark.interactions.put(air.id, 0.25f);
|
||||
|
||||
dark.interactions.put(fire.id, -0.25f);
|
||||
fire.interactions.put(dark.id, 0.25f);
|
||||
|
||||
nature.interactions.put(air.id, -0.25f);
|
||||
air.interactions.put(nature.id, 0.25f);
|
||||
|
||||
holy.interactions.put(earth.id, -0.25f);
|
||||
earth.interactions.put(holy.id, 0.25f);
|
||||
|
||||
arcane.interactions.put(water.id, -0.25f);
|
||||
water.interactions.put(arcane.id, 0.25f);
|
||||
|
||||
// Add them to the registry
|
||||
magics.put(earth.id, earth);
|
||||
magics.put(water.id, water);
|
||||
magics.put(fire.id, fire);
|
||||
magics.put(air.id, air);
|
||||
magics.put(dark.id, dark);
|
||||
magics.put(holy.id, holy);
|
||||
magics.put(nature.id, nature);
|
||||
magics.put(arcane.id, arcane);
|
||||
|
||||
MagicCycle defaultCycle = new MagicCycle();
|
||||
defaultCycle.id = getUnusedCycleId();
|
||||
defaultCycle.name = "Universal";
|
||||
defaultCycle.layout = EnumDiagramLayout.CIRCULAR_MANUAL;
|
||||
defaultCycle.displayName = "&6Elementa Cycle";
|
||||
cycles.put(defaultCycle.id, defaultCycle);
|
||||
|
||||
// Add magic associations
|
||||
addMagicToCycle(earth.id, defaultCycle.id, 1, 1);
|
||||
addMagicToCycle(water.id, defaultCycle.id, 1, 2);
|
||||
addMagicToCycle(fire.id, defaultCycle.id, 1, 3);
|
||||
addMagicToCycle(air.id, defaultCycle.id, 1, 0);
|
||||
addMagicToCycle(dark.id, defaultCycle.id, 0, 3);
|
||||
addMagicToCycle(holy.id, defaultCycle.id, 0, 1);
|
||||
addMagicToCycle(nature.id, defaultCycle.id, 0, 0);
|
||||
addMagicToCycle(arcane.id, defaultCycle.id, 0, 2);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
private void loadMagicFile(File file) throws Exception {
|
||||
// OLD: DataInputStream stream = new DataInputStream(
|
||||
// OLD: new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))
|
||||
// OLD: );
|
||||
// OLD: loadMagic(stream);
|
||||
// OLD: stream.close();
|
||||
INBTCompound compound = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
loadMagic(compound);
|
||||
}
|
||||
|
||||
public void loadMagic(INBTCompound compound) {
|
||||
lastUsedMagicID = compound.getInteger("lastID");
|
||||
lastUsedCycleID = compound.getInteger("lastCycleID");
|
||||
|
||||
magics.clear();
|
||||
INBTList magicList = compound.getList("Magics", 10);
|
||||
for (int i = 0; i < magicList.size(); i++) {
|
||||
INBTCompound magCompound = magicList.getCompound(i);
|
||||
Magic mag = new Magic();
|
||||
mag.readNBT(magCompound);
|
||||
magics.put(mag.id, mag);
|
||||
}
|
||||
|
||||
cycles.clear();
|
||||
INBTList cycleList = compound.getList("Cycles", 10);
|
||||
for (int i = 0; i < cycleList.size(); i++) {
|
||||
INBTCompound catCompound = cycleList.getCompound(i);
|
||||
MagicCycle cycle = new MagicCycle();
|
||||
// OLD: cycle.readNBT(new MC1710NBTCompound(catCompound));
|
||||
cycle.readNBT(catCompound);
|
||||
cycles.put(cycle.id, cycle);
|
||||
}
|
||||
}
|
||||
|
||||
public INBTCompound getNBT() {
|
||||
INBTList magicList = NBT.list();
|
||||
for (Magic mag : magics.values()) {
|
||||
INBTCompound magCompound = NBT.compound();
|
||||
mag.writeNBT(magCompound);
|
||||
magicList.addCompound(magCompound);
|
||||
}
|
||||
INBTList catList = NBT.list();
|
||||
for (MagicCycle cat : cycles.values()) {
|
||||
INBTCompound catCompound = NBT.compound();
|
||||
// OLD: cat.writeNBT(new MC1710NBTCompound(catCompound));
|
||||
cat.writeNBT(catCompound);
|
||||
catList.addCompound(catCompound);
|
||||
}
|
||||
INBTCompound compound = NBT.compound();
|
||||
compound.setInteger("lastID", lastUsedMagicID);
|
||||
compound.setInteger("lastCycleID", lastUsedCycleID);
|
||||
compound.setList("Magics", magicList);
|
||||
compound.setList("Cycles", catList);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void saveMagicData() {
|
||||
try {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
File fileNew = new File(saveDir, "magic.dat_new");
|
||||
File fileOld = new File(saveDir, "magic.dat_old");
|
||||
File fileCurrent = new File(saveDir, "magic.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(fileNew));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(getNBT(), fileNew);
|
||||
if (fileOld.exists())
|
||||
fileOld.delete();
|
||||
fileCurrent.renameTo(fileOld);
|
||||
|
||||
if (fileCurrent.exists())
|
||||
fileCurrent.delete();
|
||||
fileNew.renameTo(fileCurrent);
|
||||
if (fileNew.exists()) fileNew.delete();
|
||||
} catch (Exception e) {
|
||||
// OLD: LogWriter.except(e);
|
||||
PlatformServiceHolder.get().logError("Error saving magic data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void saveMagic(Magic mag) {
|
||||
if (mag.id < 0) {
|
||||
mag.id = getUnusedId();
|
||||
while (hasName(mag.name))
|
||||
mag.name += "_";
|
||||
} else {
|
||||
Magic existing = magics.get(mag.id);
|
||||
if (existing != null && !existing.name.equals(mag.name))
|
||||
while (hasName(mag.name))
|
||||
mag.name += "_";
|
||||
}
|
||||
magics.put(mag.id, mag);
|
||||
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: NBTTagCompound magicCompound = new NBTTagCompound();
|
||||
// OLD: mag.writeNBT(magicCompound);
|
||||
// OLD: SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeMagic(int magicID) {
|
||||
if (magics.containsKey(magicID)) {
|
||||
magics.remove(magicID);
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: SyncController.syncRemove(EnumSyncType.MAGIC, magicID);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
if (lastUsedMagicID == 0) {
|
||||
for (int id : magics.keySet())
|
||||
if (id > lastUsedMagicID)
|
||||
lastUsedMagicID = id;
|
||||
}
|
||||
lastUsedMagicID++;
|
||||
return lastUsedMagicID;
|
||||
}
|
||||
|
||||
public boolean hasName(String newName) {
|
||||
if (newName.trim().isEmpty()) return true;
|
||||
for (Magic mag : magics.values())
|
||||
if (mag.name.equalsIgnoreCase(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
// === Cycle Management Methods ===
|
||||
|
||||
public int getUnusedCycleId() {
|
||||
if (lastUsedCycleID == 0) {
|
||||
for (int id : cycles.keySet())
|
||||
if (id > lastUsedCycleID)
|
||||
lastUsedCycleID = id;
|
||||
}
|
||||
lastUsedCycleID++;
|
||||
return lastUsedCycleID;
|
||||
}
|
||||
|
||||
public boolean containsCategoryName(String title) {
|
||||
title = title.toLowerCase();
|
||||
for (MagicCycle cat : cycles.values()) {
|
||||
if (cat.name.toLowerCase().equals(title))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void saveCycle(MagicCycle cycle) {
|
||||
if (cycle.id < 0) {
|
||||
cycle.id = getUnusedCycleId();
|
||||
while (containsCategoryName(cycle.name))
|
||||
cycle.name += "_";
|
||||
} else {
|
||||
MagicCycle existing = cycles.get(cycle.id);
|
||||
if (existing != null && !existing.name.equals(cycle.name))
|
||||
while (containsCategoryName(cycle.name))
|
||||
cycle.name += "_";
|
||||
}
|
||||
cycles.put(cycle.id, cycle);
|
||||
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: NBTTagCompound cycleCompound = new NBTTagCompound();
|
||||
// OLD: cycle.writeNBT(new MC1710NBTCompound(cycleCompound));
|
||||
// OLD: SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound);
|
||||
|
||||
saveMagicData();
|
||||
}
|
||||
|
||||
public void removeCycle(int categoryId) {
|
||||
if (cycles.containsKey(categoryId)) {
|
||||
cycles.remove(categoryId);
|
||||
// TODO: mc1710 version also calls:
|
||||
// OLD: SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId);
|
||||
saveMagicData();
|
||||
}
|
||||
}
|
||||
|
||||
public void addMagicToCycle(int magicId, int cycleId, int index, int priority) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null)
|
||||
return;
|
||||
|
||||
Magic magic = magics.get(magicId);
|
||||
if (magic == null)
|
||||
return;
|
||||
|
||||
MagicAssociation assoc = new MagicAssociation();
|
||||
assoc.magicId = magicId;
|
||||
assoc.index = index;
|
||||
assoc.priority = priority;
|
||||
cat.associations.put(magicId, assoc);
|
||||
|
||||
saveCycle(cat);
|
||||
}
|
||||
|
||||
public void removeMagicFromCycle(int magicId, int cycleId) {
|
||||
MagicCycle cat = cycles.get(cycleId);
|
||||
if (cat == null) return;
|
||||
cat.associations.remove(magicId);
|
||||
|
||||
saveCycle(cat);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.controllers.data.TagMap;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ServerTagMapController {
|
||||
public static ServerTagMapController Instance;
|
||||
public TagMap tagMap;
|
||||
|
||||
public ServerTagMapController() {
|
||||
}
|
||||
|
||||
public File getDir() {
|
||||
File dir = new File(PlatformServiceHolder.get().getWorldSaveDirectory(), "clones");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
|
||||
public File getCloneTabDir(int tab) {
|
||||
File dir = new File(getDir(), tab + "");
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
|
||||
public File getCloneFolderDir(String folderName) {
|
||||
File dir = new File(getDir(), folderName);
|
||||
if (!dir.exists())
|
||||
dir.mkdir();
|
||||
return dir;
|
||||
}
|
||||
|
||||
public TagMap getTagMap(int tab) {
|
||||
this.tagMap = new TagMap(tab);
|
||||
try {
|
||||
File file = new File(getCloneTabDir(tab), "___tagmap.dat");
|
||||
if (file.exists()) {
|
||||
loadTagMapFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(getCloneTabDir(tab), "___tagmap.dat_old");
|
||||
if (file.exists()) {
|
||||
loadTagMapFile(file);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return this.tagMap;
|
||||
}
|
||||
|
||||
private void loadTagMapFile(File file) throws Exception {
|
||||
// OLD: DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
|
||||
// OLD: NBTTagCompound nbtCompound = CompressedStreamTools.read(var1);
|
||||
// OLD: this.tagMap.readNBT(new MC1710NBTCompound(nbtCompound));
|
||||
// OLD: var1.close();
|
||||
INBTCompound nbtCompound = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
this.tagMap.readNBT(nbtCompound);
|
||||
}
|
||||
|
||||
public TagMap getTagMap(String folderName) {
|
||||
this.tagMap = new TagMap(folderName);
|
||||
try {
|
||||
File file = new File(getCloneFolderDir(folderName), "___tagmap.dat");
|
||||
if (file.exists()) {
|
||||
loadTagMapFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(getCloneFolderDir(folderName), "___tagmap.dat_old");
|
||||
if (file.exists()) {
|
||||
loadTagMapFile(file);
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
return this.tagMap;
|
||||
}
|
||||
|
||||
public void saveTagMap(TagMap tagMap) {
|
||||
try {
|
||||
File saveDir;
|
||||
if (tagMap.cloneFolder != null) {
|
||||
saveDir = getCloneFolderDir(tagMap.cloneFolder);
|
||||
} else {
|
||||
saveDir = getCloneTabDir(tagMap.cloneTab);
|
||||
}
|
||||
File file = new File(saveDir, "___tagmap.dat_new");
|
||||
File file1 = new File(saveDir, "___tagmap.dat_old");
|
||||
File file2 = new File(saveDir, "___tagmap.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(((MC1710NBTCompound) tagMap.writeNBT()).getMCTag(), new FileOutputStream(file));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(tagMap.writeNBT(), file);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// OLD: LogWriter.except(e);
|
||||
PlatformServiceHolder.get().logError("Error saving tag map", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.controllers.data.Tag;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TagController {
|
||||
public HashMap<Integer, Tag> tags;
|
||||
private static TagController instance;
|
||||
|
||||
private int lastUsedID = 0;
|
||||
|
||||
// TODO: mc1710 version implements ITagHandler and adds:
|
||||
// OLD: public List<ITag> list()
|
||||
// OLD: public ITag delete(int id)
|
||||
// OLD: public static void sendCategoryTagMap(EntityPlayerMP player, HashMap<String, HashSet<UUID>> itemTags) — uses GuiDataPacket
|
||||
|
||||
public TagController() {
|
||||
instance = this;
|
||||
tags = new HashMap<Integer, Tag>();
|
||||
loadTags();
|
||||
}
|
||||
|
||||
public static TagController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void loadTags() {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
if (saveDir == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
File file = new File(saveDir, "tags.dat");
|
||||
if (file.exists()) {
|
||||
loadTagsFile(file);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "tags.dat_old");
|
||||
if (file.exists()) {
|
||||
loadTagsFile(file);
|
||||
}
|
||||
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTagsFile(File file) throws Exception {
|
||||
// OLD: DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file))));
|
||||
// OLD: loadTags(var1);
|
||||
// OLD: var1.close();
|
||||
INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
loadTags(nbttagcompound1);
|
||||
}
|
||||
|
||||
public void loadTags(INBTCompound nbttagcompound1) {
|
||||
HashMap<Integer, Tag> tags = new HashMap<Integer, Tag>();
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
INBTList list = nbttagcompound1.getList("NPCTags", 10);
|
||||
|
||||
if (list != null) {
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
INBTCompound nbttagcompound = list.getCompound(i);
|
||||
Tag tag = new Tag();
|
||||
// OLD: tag.readNBT(new MC1710NBTCompound(nbttagcompound));
|
||||
tag.readNBT(nbttagcompound);
|
||||
tags.put(tag.id, tag);
|
||||
}
|
||||
}
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public INBTCompound getNBT() {
|
||||
INBTList list = NBT.list();
|
||||
for (int slot : tags.keySet()) {
|
||||
Tag tag = tags.get(slot);
|
||||
INBTCompound nbtfactions = NBT.compound();
|
||||
// OLD: tag.writeNBT(new MC1710NBTCompound(nbtfactions));
|
||||
tag.writeNBT(nbtfactions);
|
||||
list.addCompound(nbtfactions);
|
||||
}
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("lastID", lastUsedID);
|
||||
nbttagcompound.setList("NPCTags", list);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void saveTags() {
|
||||
try {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
File file = new File(saveDir, "tags.dat_new");
|
||||
File file1 = new File(saveDir, "tags.dat_old");
|
||||
File file2 = new File(saveDir, "tags.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(getNBT(), file);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// OLD: LogWriter.except(e);
|
||||
PlatformServiceHolder.get().logError("Error saving tag data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Tag get(int tagSlot) {
|
||||
return tags.get(tagSlot);
|
||||
}
|
||||
|
||||
public void saveTag(Tag tag) {
|
||||
|
||||
if (tag.id < 0) {
|
||||
tag.id = getUnusedId();
|
||||
while (hasName(tag.name))
|
||||
tag.name += "_";
|
||||
} else {
|
||||
Tag existing = tags.get(tag.id);
|
||||
if (existing != null && !existing.name.equals(tag.name))
|
||||
while (hasName(tag.name))
|
||||
tag.name += "_";
|
||||
}
|
||||
tags.remove(tag.id);
|
||||
tags.put(tag.id, tag);
|
||||
saveTags();
|
||||
}
|
||||
|
||||
public Tag create(Tag tag) {
|
||||
this.saveTag(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public Tag create(String name, int color) {
|
||||
Tag tag = new Tag();
|
||||
tag.name = name;
|
||||
tag.color = color;
|
||||
this.saveTag(tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
public int getUnusedId() {
|
||||
if (lastUsedID == 0) {
|
||||
for (int catid : tags.keySet())
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
public void delete(int id) {
|
||||
if (id >= 0 && this.tags.size() > 1) {
|
||||
Tag tag = this.tags.remove(id);
|
||||
if (tag != null) {
|
||||
this.saveTags();
|
||||
tag.id = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasName(String newName) {
|
||||
if (newName.trim().isEmpty())
|
||||
return true;
|
||||
for (Tag tag : tags.values())
|
||||
if (tag.name.equals(newName))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public Tag getTagFromName(String tagname) {
|
||||
for (Map.Entry<Integer, Tag> entryTag : TagController.getInstance().tags.entrySet()) {
|
||||
if (entryTag.getValue().name.equalsIgnoreCase(tagname)) {
|
||||
return entryTag.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tag getTagFromUUID(UUID uuid) {
|
||||
for (Map.Entry<Integer, Tag> entryTag : TagController.getInstance().tags.entrySet()) {
|
||||
if (entryTag.getValue().uuid.equals(uuid)) {
|
||||
return entryTag.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String[] getNames() {
|
||||
String[] names = new String[tags.size()];
|
||||
int i = 0;
|
||||
for (Tag tag : tags.values()) {
|
||||
names[i] = tag.name.toLowerCase();
|
||||
i++;
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
public HashSet<Tag> getAllTags() {
|
||||
return new HashSet<Tag>(this.tags.values());
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a set of tag UUIDs to an NBT compound under the given key.
|
||||
*/
|
||||
public static void writeTagUUIDs(INBTCompound compound, String key, HashSet<UUID> tagUUIDs) {
|
||||
if (tagUUIDs != null && !tagUUIDs.isEmpty()) {
|
||||
INBTList list = NBT.list();
|
||||
for (UUID uuid : tagUUIDs) {
|
||||
list.addString(uuid.toString());
|
||||
}
|
||||
compound.setList(key, list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a set of tag UUIDs from an NBT compound under the given key.
|
||||
*/
|
||||
public static HashSet<UUID> readTagUUIDs(INBTCompound compound, String key) {
|
||||
HashSet<UUID> uuids = new HashSet<>();
|
||||
if (compound.hasKey(key)) {
|
||||
INBTList list = compound.getList(key, 8);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
try {
|
||||
uuids.add(UUID.fromString(list.getString(i)));
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
}
|
||||
}
|
||||
return uuids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove invalid tag UUIDs (those not in the tag registry).
|
||||
*/
|
||||
public static void validateTagUUIDs(HashSet<UUID> tagUUIDs) {
|
||||
TagController tc = getInstance();
|
||||
if (tc == null) return;
|
||||
tagUUIDs.removeIf(uuid -> tc.getTagFromUUID(uuid) == null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,257 @@
|
||||
package noppes.npcs.controllers;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.controllers.data.TransportCategory;
|
||||
import noppes.npcs.controllers.data.TransportLocation;
|
||||
import noppes.npcs.platform.PlatformServiceHolder;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TransportController {
|
||||
private HashMap<Integer, TransportLocation> locations = new HashMap<Integer, TransportLocation>();
|
||||
public HashMap<Integer, TransportCategory> categories = new HashMap<Integer, TransportCategory>();
|
||||
|
||||
private int lastUsedID = 0;
|
||||
|
||||
// TODO: mc1710 version implements ITransportHandler and adds:
|
||||
// OLD: public TransportLocation saveLocation(int categoryId, NBTTagCompound compound, EntityNPCInterface npc)
|
||||
// - This overload uses EntityNPCInterface, RoleTransporter, EnumRoleType
|
||||
// OLD: public ITransportCategory[] categories()
|
||||
// OLD: public void createCategory(String title)
|
||||
// OLD: public ITransportCategory getCategory(String title)
|
||||
// OLD: public void removeCategory(String title)
|
||||
|
||||
private static TransportController instance;
|
||||
|
||||
public TransportController() {
|
||||
instance = this;
|
||||
loadCategories();
|
||||
if (categories.isEmpty()) {
|
||||
TransportCategory cat = new TransportCategory();
|
||||
cat.id = 1;
|
||||
cat.title = "Default";
|
||||
categories.put(cat.id, cat);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCategories() {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
if (saveDir == null)
|
||||
return;
|
||||
try {
|
||||
File file = new File(saveDir, "transport.dat");
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
loadCategories(file);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
File file = new File(saveDir, "transport.dat_old");
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
loadCategories(file);
|
||||
|
||||
} catch (Exception ee) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCategories(File file) throws Exception {
|
||||
HashMap<Integer, TransportLocation> locations = new HashMap<Integer, TransportLocation>();
|
||||
HashMap<Integer, TransportCategory> categories = new HashMap<Integer, TransportCategory>();
|
||||
// OLD: NBTTagCompound nbttagcompound1;
|
||||
// OLD: try (FileInputStream fis = new FileInputStream(file)) {
|
||||
// OLD: nbttagcompound1 = CompressedStreamTools.readCompressed(fis);
|
||||
// OLD: }
|
||||
INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file);
|
||||
lastUsedID = nbttagcompound1.getInteger("lastID");
|
||||
INBTList list = nbttagcompound1.getList("NPCTransportCategories", 10);
|
||||
if (list == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
TransportCategory category = new TransportCategory();
|
||||
INBTCompound compound = list.getCompound(i);
|
||||
// OLD: category.readNBT(new MC1710NBTCompound(compound));
|
||||
category.readNBT(compound);
|
||||
|
||||
for (TransportLocation location : category.locations.values())
|
||||
locations.put(location.id, location);
|
||||
|
||||
categories.put(category.id, category);
|
||||
}
|
||||
this.locations = locations;
|
||||
this.categories = categories;
|
||||
}
|
||||
|
||||
public INBTCompound getNBT() {
|
||||
INBTList list = NBT.list();
|
||||
for (TransportCategory category : categories.values()) {
|
||||
INBTCompound compound = NBT.compound();
|
||||
category.writeNBT(compound);
|
||||
list.addCompound(compound);
|
||||
}
|
||||
INBTCompound nbttagcompound = NBT.compound();
|
||||
nbttagcompound.setInteger("lastID", lastUsedID);
|
||||
nbttagcompound.setList("NPCTransportCategories", list);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void saveCategories() {
|
||||
try {
|
||||
File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory();
|
||||
File file = new File(saveDir, "transport.dat_new");
|
||||
File file1 = new File(saveDir, "transport.dat_old");
|
||||
File file2 = new File(saveDir, "transport.dat");
|
||||
// OLD: CompressedStreamTools.writeCompressed(getNBT(), new FileOutputStream(file));
|
||||
PlatformServiceHolder.get().writeCompressedNBT(getNBT(), file);
|
||||
if (file1.exists()) {
|
||||
file1.delete();
|
||||
}
|
||||
file2.renameTo(file1);
|
||||
if (file2.exists()) {
|
||||
file2.delete();
|
||||
}
|
||||
file.renameTo(file2);
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// OLD: LogWriter.except(e);
|
||||
PlatformServiceHolder.get().logError("Error saving transport data", e);
|
||||
}
|
||||
}
|
||||
|
||||
public TransportLocation getTransport(int transportId) {
|
||||
return locations.get(transportId);
|
||||
}
|
||||
|
||||
public TransportLocation getTransport(String name) {
|
||||
for (TransportLocation loc : locations.values()) {
|
||||
if (loc.name.equals(name))
|
||||
return loc;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getUniqueIdLocation() {
|
||||
if (lastUsedID == 0) {
|
||||
for (int catid : locations.keySet())
|
||||
if (catid > lastUsedID)
|
||||
lastUsedID = catid;
|
||||
}
|
||||
lastUsedID++;
|
||||
return lastUsedID;
|
||||
}
|
||||
|
||||
private int getUniqueIdCategory() {
|
||||
int id = 0;
|
||||
for (int catid : categories.keySet())
|
||||
if (catid > id)
|
||||
id = catid;
|
||||
id++;
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setLocation(TransportLocation location) {
|
||||
if (locations.containsKey(location.id)) {
|
||||
for (TransportCategory cat : categories.values())
|
||||
cat.locations.remove(location.id);
|
||||
}
|
||||
locations.put(location.id, location);
|
||||
location.category.locations.put(location.id, location);
|
||||
}
|
||||
|
||||
public TransportLocation removeLocation(int location) {
|
||||
TransportLocation loc = locations.get(location);
|
||||
if (loc == null)
|
||||
return null;
|
||||
loc.category.locations.remove(location);
|
||||
locations.remove(location);
|
||||
|
||||
saveCategories();
|
||||
return loc;
|
||||
}
|
||||
|
||||
private boolean containsCategoryName(String name) {
|
||||
name = name.toLowerCase();
|
||||
for (TransportCategory cat : categories.values()) {
|
||||
if (cat.title.toLowerCase().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void saveCategory(String name, int id) {
|
||||
if (id < 0) {
|
||||
id = getUniqueIdCategory();
|
||||
}
|
||||
if (categories.containsKey(id)) {
|
||||
TransportCategory category = categories.get(id);
|
||||
if (!category.title.equals(name)) {
|
||||
while (containsCategoryName(name))
|
||||
name += "_";
|
||||
categories.get(id).title = name;
|
||||
}
|
||||
} else {
|
||||
while (containsCategoryName(name))
|
||||
name += "_";
|
||||
TransportCategory category = new TransportCategory();
|
||||
category.id = id;
|
||||
category.title = name;
|
||||
categories.put(id, category);
|
||||
}
|
||||
saveCategories();
|
||||
}
|
||||
|
||||
public void removeCategory(int id) {
|
||||
if (categories.size() == 1)
|
||||
return;
|
||||
TransportCategory cat = categories.get(id);
|
||||
if (cat == null)
|
||||
return;
|
||||
for (int i : cat.locations.keySet())
|
||||
locations.remove(i);
|
||||
categories.remove(id);
|
||||
|
||||
saveCategories();
|
||||
}
|
||||
|
||||
public boolean containsLocationName(String name) {
|
||||
name = name.toLowerCase();
|
||||
for (TransportLocation loc : locations.values()) {
|
||||
if (loc.name.toLowerCase().equals(name))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static TransportController getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
public TransportLocation saveLocation(int categoryId, TransportLocation location) {
|
||||
TransportCategory category = categories.get(categoryId);
|
||||
if (category == null)
|
||||
return null;
|
||||
location.category = category;
|
||||
if (location.id < 0 || !locations.get(location.id).name.equals(location.name)) {
|
||||
while (containsLocationName(location.name))
|
||||
location.name += "_";
|
||||
}
|
||||
if (location.id < 0)
|
||||
location.id = getUniqueIdLocation();
|
||||
|
||||
category.locations.put(location.id, location);
|
||||
locations.put(location.id, location);
|
||||
saveCategories();
|
||||
|
||||
return location;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import noppes.npcs.NBTTags;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class Faction {
|
||||
public String name = "";
|
||||
public int color = Integer.parseInt("FF00", 16);
|
||||
|
||||
public HashSet<Integer> attackFactions;
|
||||
public int id = -1;
|
||||
|
||||
public int neutralPoints = 500;
|
||||
public int friendlyPoints = 1500;
|
||||
|
||||
public int defaultPoints = 1000;
|
||||
|
||||
public boolean hideFaction = false;
|
||||
public boolean getsAttacked = false;
|
||||
public boolean isPassive = false;
|
||||
|
||||
public Faction() {
|
||||
attackFactions = new HashSet<Integer>();
|
||||
}
|
||||
|
||||
public Faction(int id, String name, int color, int defaultPoints) {
|
||||
this.name = name;
|
||||
this.color = color;
|
||||
this.defaultPoints = defaultPoints;
|
||||
this.id = id;
|
||||
attackFactions = new HashSet<Integer>();
|
||||
}
|
||||
|
||||
public static String formatName(String name) {
|
||||
name = name.toLowerCase().trim();
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound compound) {
|
||||
name = compound.getString("Name");
|
||||
color = compound.getInteger("Color");
|
||||
id = compound.getInteger("Slot");
|
||||
|
||||
neutralPoints = compound.getInteger("NeutralPoints");
|
||||
friendlyPoints = compound.getInteger("FriendlyPoints");
|
||||
defaultPoints = compound.getInteger("DefaultPoints");
|
||||
|
||||
hideFaction = compound.getBoolean("HideFaction");
|
||||
getsAttacked = compound.getBoolean("GetsAttacked");
|
||||
isPassive = compound.getBoolean("IsPassive");
|
||||
|
||||
attackFactions = NBTTags.getIntegerSet(compound.getList("AttackFactions", 10));
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound compound) {
|
||||
compound.setInteger("Slot", id);
|
||||
compound.setString("Name", name);
|
||||
compound.setInteger("Color", color);
|
||||
|
||||
compound.setInteger("NeutralPoints", neutralPoints);
|
||||
compound.setInteger("FriendlyPoints", friendlyPoints);
|
||||
compound.setInteger("DefaultPoints", defaultPoints);
|
||||
|
||||
compound.setBoolean("HideFaction", hideFaction);
|
||||
compound.setBoolean("GetsAttacked", getsAttacked);
|
||||
compound.setBoolean("IsPassive", isPassive);
|
||||
|
||||
compound.setList("AttackFactions", NBTTags.nbtIntegerSet(attackFactions));
|
||||
}
|
||||
|
||||
// TODO: mc1710 version implements IFaction and adds:
|
||||
// OLD: public boolean isFriendlyToPlayer(EntityPlayer player) — uses PlayerData.get(player).factionData
|
||||
// OLD: public boolean isAggressiveToPlayer(EntityPlayer player) — uses PlayerData.get(player).factionData
|
||||
// OLD: public boolean isNeutralToPlayer(EntityPlayer player) — uses PlayerData.get(player).factionData
|
||||
// OLD: public boolean isAggressiveToNpc(EntityNPCInterface entity) — uses entity.faction.id
|
||||
// OLD: public int playerStatus(IPlayer player) — uses IPlayerFactionData
|
||||
// OLD: public boolean isAggressiveToNpc(ICustomNpc npc) — uses npc.getFaction().getId()
|
||||
// OLD: public boolean isFriendlyToPlayer(IPlayer player) — delegates to EntityPlayer overload
|
||||
// OLD: public boolean isNeutralToPlayer(IPlayer player) — delegates to EntityPlayer overload
|
||||
// OLD: public boolean isAggressiveToPlayer(IPlayer player) — delegates to EntityPlayer overload
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDefaultPoints(int points) {
|
||||
this.defaultPoints = points;
|
||||
}
|
||||
|
||||
public int getDefaultPoints() {
|
||||
return this.defaultPoints;
|
||||
}
|
||||
|
||||
public void setFriendlyPoints(int points) {
|
||||
this.friendlyPoints = points;
|
||||
}
|
||||
|
||||
public int getFriendlyPoints() {
|
||||
return this.friendlyPoints;
|
||||
}
|
||||
|
||||
public void setNeutralPoints(int points) {
|
||||
this.neutralPoints = points;
|
||||
}
|
||||
|
||||
public int getNeutralPoints() {
|
||||
return this.neutralPoints;
|
||||
}
|
||||
|
||||
public void setColor(int color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public boolean isEnemyFaction(int factionId) {
|
||||
return this.attackFactions.contains(factionId);
|
||||
}
|
||||
|
||||
public void addEnemyFaction(int factionId) {
|
||||
this.attackFactions.add(factionId);
|
||||
}
|
||||
|
||||
public void removeEnemyFaction(int factionId) {
|
||||
this.attackFactions.remove(factionId);
|
||||
}
|
||||
|
||||
public boolean getIsHidden() {
|
||||
return this.hideFaction;
|
||||
}
|
||||
|
||||
public void setIsHidden(boolean bo) {
|
||||
this.hideFaction = bo;
|
||||
}
|
||||
|
||||
public boolean isPassive() {
|
||||
return isPassive;
|
||||
}
|
||||
|
||||
public void setIsPassive(boolean passive) {
|
||||
this.isPassive = passive;
|
||||
}
|
||||
|
||||
public boolean attackedByMobs() {
|
||||
return this.getsAttacked;
|
||||
}
|
||||
|
||||
public void setAttackedByMobs(boolean bo) {
|
||||
this.getsAttacked = bo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import noppes.npcs.core.NBT;
|
||||
import noppes.npcs.constants.EnumTextureType;
|
||||
import noppes.npcs.controllers.MagicController;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Magic {
|
||||
public String name = "";
|
||||
public String displayName = "";
|
||||
public int color = Integer.parseInt("FF00", 16);
|
||||
public int id = -1;
|
||||
|
||||
// TODO: mc1710 version has: public ItemStack item = null;
|
||||
// OLD: import net.minecraft.item.ItemStack;
|
||||
|
||||
public EnumTextureType type = EnumTextureType.BASE;
|
||||
public String iconTexture = "";
|
||||
public Map<Integer, Float> interactions = new HashMap<>();
|
||||
|
||||
public Magic() {
|
||||
}
|
||||
|
||||
public Magic(int id, String name, int color) {
|
||||
this.name = name;
|
||||
this.displayName = name;
|
||||
this.color = color;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static String formatName(String name) {
|
||||
name = name.toLowerCase().trim();
|
||||
return name.substring(0, 1).toUpperCase() + name.substring(1);
|
||||
}
|
||||
|
||||
public void readNBT(INBTCompound compound) {
|
||||
name = compound.getString("Name");
|
||||
displayName = compound.getString("DisplayName");
|
||||
color = compound.getInteger("Color");
|
||||
id = compound.getInteger("Slot");
|
||||
|
||||
type = EnumTextureType.values()[compound.getInteger("Type")];
|
||||
iconTexture = compound.getString("IconTexture");
|
||||
// TODO: mc1710 version resolves ItemStack from GameRegistry here:
|
||||
// OLD: if (type == EnumTextureType.ITEM && !iconTexture.isEmpty()) {
|
||||
// OLD: String[] parts = iconTexture.split(":");
|
||||
// OLD: Item item = GameRegistry.findItem(parts[0], parts[1]);
|
||||
// OLD: this.item = (item != null) ? new ItemStack(item) : null;
|
||||
// OLD: }
|
||||
|
||||
interactions.clear();
|
||||
if (compound.hasKey("Interactions")) {
|
||||
INBTList interactionsList = compound.getList("Interactions", 10);
|
||||
for (int i = 0; i < interactionsList.size(); i++) {
|
||||
INBTCompound interactionTag = interactionsList.getCompound(i);
|
||||
int magicId = interactionTag.getInteger("MagicID");
|
||||
float percentage = interactionTag.getFloat("Percentage");
|
||||
interactions.put(magicId, percentage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNBT(INBTCompound compound) {
|
||||
compound.setInteger("Slot", id);
|
||||
compound.setString("Name", name);
|
||||
compound.setString("DisplayName", displayName);
|
||||
compound.setInteger("Color", color);
|
||||
compound.setString("IconTexture", iconTexture);
|
||||
compound.setInteger("Type", type.ordinal());
|
||||
INBTList interactionsList = NBT.list();
|
||||
for (Map.Entry<Integer, Float> entry : interactions.entrySet()) {
|
||||
INBTCompound interactionTag = NBT.compound();
|
||||
interactionTag.setInteger("MagicID", entry.getKey());
|
||||
interactionTag.setFloat("Percentage", entry.getValue());
|
||||
interactionsList.addCompound(interactionTag);
|
||||
}
|
||||
compound.setList("Interactions", interactionsList);
|
||||
|
||||
// TODO: mc1710 version resolves ItemStack from GameRegistry here:
|
||||
// OLD: if (type == EnumTextureType.ITEM && !iconTexture.isEmpty()) {
|
||||
// OLD: Item item = GameRegistry.findItem(parts[0], parts[1]);
|
||||
// OLD: this.item = (item != null) ? new ItemStack(item) : null;
|
||||
// OLD: }
|
||||
}
|
||||
|
||||
// TODO: mc1710 version implements IMagic and adds:
|
||||
// OLD: public void setItem(ItemStack item) — uses GameRegistry.findUniqueIdentifierFor
|
||||
// OLD: public ItemStack getItem()
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setColor(int c) {
|
||||
this.color = c;
|
||||
}
|
||||
|
||||
public int getColor() {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(String displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
MagicController.getInstance().saveMagic(this);
|
||||
}
|
||||
|
||||
public void setIconTexture(String texture) {
|
||||
this.iconTexture = texture;
|
||||
}
|
||||
|
||||
public String getIconTexture() {
|
||||
return this.iconTexture;
|
||||
}
|
||||
|
||||
public void setInteractions(Map<Integer, Float> interactions) {
|
||||
this.interactions = interactions;
|
||||
}
|
||||
|
||||
public Map<Integer, Float> getInteractions() {
|
||||
return this.interactions;
|
||||
}
|
||||
|
||||
public boolean hasInteraction(int magicID) {
|
||||
return interactions.containsKey(magicID);
|
||||
}
|
||||
|
||||
public void setInteraction(int magicID, float value) {
|
||||
interactions.put(magicID, value);
|
||||
}
|
||||
|
||||
public float getInteraction(int magicID, float value) {
|
||||
if (hasInteraction(magicID))
|
||||
return interactions.get(magicID);
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import noppes.npcs.api.handler.data.IPlayerEffect;
|
||||
|
||||
public class PlayerEffect implements IPlayerEffect {
|
||||
public int id;
|
||||
public int duration;
|
||||
public byte level;
|
||||
public int index;
|
||||
|
||||
public PlayerEffect(int id, int duration, byte level, int index) {
|
||||
this.id = id;
|
||||
this.duration = duration;
|
||||
this.level = level;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void kill() {
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLevel(byte level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO: Requires CustomEffectController - implement via callback or platform service
|
||||
// OLD CODE:
|
||||
// CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
|
||||
// if (effect != null)
|
||||
// return effect.getName();
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies this effect's tick logic to the given player.
|
||||
* This method is not part of the core IPlayerEffect interface because
|
||||
* it depends on IPlayer which has MC entity dependencies.
|
||||
* Override in mc1710 to restore original behavior.
|
||||
*/
|
||||
public void performEffect(Object player) {
|
||||
// TODO: Requires CustomEffectController + IPlayer - implement in mc1710 override
|
||||
// OLD CODE:
|
||||
// if (player != null && player.getMCEntity() != null && player.getMCEntity() instanceof EntityPlayer) {
|
||||
// CustomEffect effect = CustomEffectController.getInstance().get(this.id, this.index);
|
||||
// if (effect != null)
|
||||
// effect.onTick((EntityPlayer) player.getMCEntity(), this);
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import noppes.npcs.constants.NBTTypes;
|
||||
import noppes.npcs.platform.nbt.INBTCompound;
|
||||
import noppes.npcs.platform.nbt.INBTList;
|
||||
import noppes.npcs.core.NBT;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PlayerEffectData {
|
||||
private ConcurrentHashMap<EffectKey, PlayerEffect> effects = new ConcurrentHashMap<>();
|
||||
|
||||
public PlayerEffectData() {
|
||||
}
|
||||
|
||||
public INBTCompound writeToNBT(INBTCompound compound) {
|
||||
INBTList list = NBT.list();
|
||||
for (Map.Entry<EffectKey, PlayerEffect> entry : effects.entrySet()) {
|
||||
INBTCompound effectCompound = NBT.compound();
|
||||
effectCompound.setInteger("id", entry.getKey().getId());
|
||||
effectCompound.setInteger("index", entry.getKey().getIndex());
|
||||
effectCompound.setInteger("duration", entry.getValue().duration);
|
||||
effectCompound.setByte("level", entry.getValue().level);
|
||||
list.addCompound(effectCompound);
|
||||
}
|
||||
compound.setList("Effects", list);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readFromNBT(INBTCompound compound) {
|
||||
HashSet<EffectKey> newKeys = new HashSet<>();
|
||||
if (compound.hasKey("Effects")) {
|
||||
INBTList list = compound.getList("Effects", NBTTypes.TAG_COMPOUND);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
INBTCompound effectCompound = list.getCompound(i);
|
||||
int id = effectCompound.getInteger("id");
|
||||
int index = effectCompound.getInteger("index");
|
||||
int duration = effectCompound.getInteger("duration");
|
||||
byte level = effectCompound.getByte("level");
|
||||
EffectKey key = new EffectKey(id, index);
|
||||
newKeys.add(key);
|
||||
PlayerEffect effect = effects.get(key);
|
||||
if (effect != null) {
|
||||
effect.duration = duration;
|
||||
effect.level = level;
|
||||
} else {
|
||||
effect = new PlayerEffect(id, duration, level, index);
|
||||
effects.put(key, effect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Iterator<EffectKey> it = effects.keySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
EffectKey key = it.next();
|
||||
if (!newKeys.contains(key)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConcurrentHashMap<EffectKey, PlayerEffect> getEffects() {
|
||||
return effects;
|
||||
}
|
||||
|
||||
public void setEffects(ConcurrentHashMap<EffectKey, PlayerEffect> effects) {
|
||||
this.effects = effects;
|
||||
}
|
||||
|
||||
public PlayerEffect getPlayerEffect(int id, int index) {
|
||||
return effects.get(new EffectKey(id, index));
|
||||
}
|
||||
|
||||
public PlayerEffect getPlayerEffect(int id) {
|
||||
return getPlayerEffect(id, 0);
|
||||
}
|
||||
|
||||
public boolean hasPlayerEffect(int id, int index) {
|
||||
return effects.containsKey(new EffectKey(id, index));
|
||||
}
|
||||
|
||||
public boolean hasPlayerEffect(int id) {
|
||||
return hasPlayerEffect(id, 0);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package noppes.npcs.scripted.constants;
|
||||
|
||||
public class AnimationType {
|
||||
public static final int NORMAL = 0;
|
||||
public static final int SITTING = 1;
|
||||
public static final int LYING = 2;
|
||||
public static final int HUGGING = 3;
|
||||
public static final int SNEAKING = 4;
|
||||
public static final int DANCING = 5;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package noppes.npcs.scripted.constants;
|
||||
|
||||
public class EntityType {
|
||||
public static final int UNKNOWN = 0;
|
||||
public static final int PLAYER = 1;
|
||||
public static final int NPC = 2;
|
||||
public static final int MONSTER = 3;
|
||||
public static final int ANIMAL = 4;
|
||||
public static final int LIVING = 5;
|
||||
public static final int ITEM = 6;
|
||||
public static final int PROJECTILE = 7;
|
||||
public static final int PIXELMON = 8;
|
||||
public static final int VILLAGER = 9;
|
||||
public static final int ARROW = 10;
|
||||
public static final int THROWABLE = 11;
|
||||
public static final int FISH_HOOK = 12;
|
||||
public static final int ENERGY_PROJECTILE = 13;
|
||||
public static final int ENERGY_ORB = 14;
|
||||
public static final int ENERGY_BEAM = 15;
|
||||
public static final int ENERGY_DISC = 16;
|
||||
public static final int ENERGY_LASER = 17;
|
||||
public static final int ENERGY_SLICER = 18;
|
||||
public static final int ENERGY_BARRIER = 19;
|
||||
public static final int ENERGY_DOME = 20;
|
||||
public static final int ENERGY_PANEL = 21;
|
||||
public static final int ENERGY_EXPLOSION = 22;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package noppes.npcs.scripted.constants;
|
||||
|
||||
public class JobType {
|
||||
public static final int UNKNOWN = 0;
|
||||
public static final int BARD = 1;
|
||||
public static final int HEALER = 2;
|
||||
public static final int GUARD = 3;
|
||||
public static final int FOLLOWER = 4;
|
||||
public static final int ITEMGIVER = 5;
|
||||
public static final int SPAWNER = 6;
|
||||
public static final int CONVERSATION = 7;
|
||||
public static final int PUPPET = 8;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package noppes.npcs.scripted.constants;
|
||||
|
||||
public class RoleType {
|
||||
public static final int UNKNOWN = 0;
|
||||
public static final int TRADER = 1;
|
||||
public static final int FOLLOWER = 2;
|
||||
public static final int BANK = 3;
|
||||
public static final int TRANSPORTER = 4;
|
||||
public static final int POSTMAN = 5;
|
||||
public static final int COMPANION = 6;
|
||||
}
|
||||
Reference in new issue
Block a user