diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/ProjectileData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/ProjectileData.java index b942af00d..5129032c3 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/ProjectileData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/ProjectileData.java @@ -3,7 +3,7 @@ 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; +import noppes.npcs.api.INbt; /** * Per-projectile data: anchor point + optional color override. @@ -35,7 +35,7 @@ public class ProjectileData { return resolved; } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { // OLD: anchor.writeNBT(new NBTWrapper(nbt)); anchor.writeNBT(nbt); nbt.setBoolean("colorOverride", colorOverride); @@ -45,7 +45,7 @@ public class ProjectileData { } } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt nbt) { // OLD: anchor.readNBT(new NBTWrapper(nbt)); anchor.readNBT(nbt); colorOverride = nbt.getBoolean("colorOverride"); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyAnchorData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyAnchorData.java index f354b6666..71e6f89aa 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyAnchorData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyAnchorData.java @@ -2,7 +2,7 @@ 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; +import noppes.npcs.api.INbt; public class EnergyAnchorData implements IEnergyAnchorData { public AnchorPoint anchorPoint = AnchorPoint.FRONT; @@ -94,7 +94,7 @@ public class EnergyAnchorData implements IEnergyAnchorData { this.launchFromAnchor = launchFromAnchor; } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setInteger("anchorPoint", anchorPoint.ordinal()); nbt.setFloat("anchorOffsetX", anchorOffsetX); nbt.setFloat("anchorOffsetY", anchorOffsetY); @@ -102,7 +102,7 @@ public class EnergyAnchorData implements IEnergyAnchorData { nbt.setBoolean("launchFromAnchor", launchFromAnchor); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt nbt) { this.anchorPoint = AnchorPoint.fromOrdinal(nbt.getInteger("anchorPoint")); this.anchorOffsetX = nbt.getFloat("anchorOffsetX"); this.anchorOffsetY = nbt.getFloat("anchorOffsetY"); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyBarrierData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyBarrierData.java index 323134481..b269cd11f 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyBarrierData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyBarrierData.java @@ -1,7 +1,7 @@ package kamkeel.npcs.controllers.data.ability.data.energy; import noppes.npcs.core.NBT; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import java.util.HashMap; import java.util.Map; @@ -165,7 +165,7 @@ public class EnergyBarrierData { // ==================== NBT ==================== - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setFloat("barrierMaxHealth", maxHealth); nbt.setBoolean("barrierUseHealth", useHealth); nbt.setInteger("barrierDuration", durationTicks); @@ -182,14 +182,14 @@ public class EnergyBarrierData { nbt.setFloat("barrierReflectStrPct", reflectStrengthPct); nbt.setBoolean("barrierTargetOwner", targetOwner); - INBTCompound multNbt = NBT.compound(); + INbt multNbt = NBT.compound(); for (Map.Entry entry : damageMultipliers.entrySet()) { multNbt.setFloat(entry.getKey(), entry.getValue()); } nbt.setCompound("barrierMultipliers", multNbt); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; @@ -208,7 +208,7 @@ public class EnergyBarrierData { damageMultipliers.clear(); if (nbt.hasKey("barrierMultipliers")) { - INBTCompound multNbt = nbt.getCompound("barrierMultipliers"); + INbt multNbt = nbt.getCompound("barrierMultipliers"); Set keys = multNbt.getKeySet(); for (String key : keys) { damageMultipliers.put(key, multNbt.getFloat(key)); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyChargingData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyChargingData.java index 6c9093919..3b88b1098 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyChargingData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyChargingData.java @@ -1,6 +1,6 @@ package kamkeel.npcs.controllers.data.ability.data.energy; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; public class EnergyChargingData { @@ -61,7 +61,7 @@ public class EnergyChargingData { this.maxCharge = Math.max(0, maxCharge); } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setInteger("chargeDuration", chargeDuration); nbt.setInteger("chargeDelay", chargeDelay); nbt.setInteger("maxCharge", maxCharge); @@ -69,7 +69,7 @@ public class EnergyChargingData { nbt.setBoolean("chargeWindUpSync", chargeWindUpSync); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyCombatData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyCombatData.java index 3b5908e15..7e5a50f76 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyCombatData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyCombatData.java @@ -2,7 +2,7 @@ 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; +import noppes.npcs.api.INbt; /** * Groups combat properties shared by energy projectile abilities. @@ -124,7 +124,7 @@ public class EnergyCombatData implements IEnergyCombatData { this.maxHits = clampMaxHits(maxHits); } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setFloat("damage", damage); nbt.setFloat("knockback", knockback); nbt.setFloat("knockbackUp", knockbackUp); @@ -136,7 +136,7 @@ public class EnergyCombatData implements IEnergyCombatData { nbt.setInteger("maxHits", maxHits); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyDisplayData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyDisplayData.java index ccc334b5a..0a2cad5a2 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyDisplayData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyDisplayData.java @@ -1,7 +1,7 @@ package kamkeel.npcs.controllers.data.ability.data.energy; import noppes.npcs.api.ability.data.IEnergyDisplayData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; /** * Groups visual color properties shared by all energy abilities. @@ -110,7 +110,7 @@ public class EnergyDisplayData implements IEnergyDisplayData { this.rotationSpeed = rotationSpeed; } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setInteger("innerColor", innerColor); nbt.setInteger("outerColor", outerColor); nbt.setBoolean("outerColorEnabled", outerColorEnabled); @@ -120,7 +120,7 @@ public class EnergyDisplayData implements IEnergyDisplayData { nbt.setFloat("rotationSpeed", rotationSpeed); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt nbt) { innerColor = nbt.hasKey("innerColor") ? nbt.getInteger("innerColor") : 0xFFFFFF; outerColor = nbt.hasKey("outerColor") ? nbt.getInteger("outerColor") : 0x8888FF; outerColorEnabled = !nbt.hasKey("outerColorEnabled") || nbt.getBoolean("outerColorEnabled"); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyHomingData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyHomingData.java index e3d7f49e0..41cdfaebd 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyHomingData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyHomingData.java @@ -1,7 +1,7 @@ package kamkeel.npcs.controllers.data.ability.data.energy; import noppes.npcs.api.ability.data.IEnergyHomingData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; /** * Groups homing/movement properties for energy projectile abilities. @@ -63,14 +63,14 @@ public class EnergyHomingData implements IEnergyHomingData { this.homingRange = homingRange; } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setFloat("speed", speed); nbt.setBoolean("homing", homing); nbt.setFloat("homingStrength", homingStrength); nbt.setFloat("homingRange", homingRange); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLifespanData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLifespanData.java index ca1b449ba..96f4fc396 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLifespanData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLifespanData.java @@ -1,7 +1,7 @@ package kamkeel.npcs.controllers.data.ability.data.energy; import noppes.npcs.api.ability.data.IEnergyLifespanData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; /** * Groups lifespan/range properties for energy projectile abilities. @@ -39,12 +39,12 @@ public class EnergyLifespanData implements IEnergyLifespanData { this.maxLifetime = maxLifetime <= 0 ? 200 : maxLifetime; } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setFloat("maxDistance", maxDistance); nbt.setInteger("maxLifetime", maxLifetime); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt nbt) { maxDistance = nbt.getFloat("maxDistance"); maxLifetime = nbt.getInteger("maxLifetime"); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLightningData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLightningData.java index 89fdb766b..76e8cfb22 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLightningData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyLightningData.java @@ -1,7 +1,7 @@ package kamkeel.npcs.controllers.data.ability.data.energy; import noppes.npcs.api.ability.data.IEnergyLightningData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; /** * Groups lightning visual effect properties for energy abilities. @@ -64,14 +64,14 @@ public class EnergyLightningData implements IEnergyLightningData { this.lightningFadeTime = Math.max(1, lightningFadeTime); } - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setBoolean("lightningEffect", lightningEffect); nbt.setFloat("lightningDensity", lightningDensity); nbt.setFloat("lightningRadius", lightningRadius); nbt.setInteger("lightningFadeTime", lightningFadeTime); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyPanelData.java b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyPanelData.java index 609f66efc..47597cbf1 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyPanelData.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/ability/data/energy/EnergyPanelData.java @@ -1,6 +1,6 @@ package kamkeel.npcs.controllers.data.ability.data.energy; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; /** * Groups panel-specific properties for energy wall/shield abilities. @@ -88,7 +88,7 @@ public class EnergyPanelData { // ==================== NBT ==================== - public void writeNBT(INBTCompound nbt) { + public void writeNBT(INbt nbt) { nbt.setFloat("panelWidth", panelWidth); nbt.setFloat("panelHeight", panelHeight); nbt.setFloat("panelHeightOffset", heightOffset); @@ -100,7 +100,7 @@ public class EnergyPanelData { nbt.setFloat("panelLaunchKnockback", launchKnockback); } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt 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; diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/profile/ProfileInfoEntry.java b/core/src/main/java/kamkeel/npcs/controllers/data/profile/ProfileInfoEntry.java index 7652c67b3..2af0c4346 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/profile/ProfileInfoEntry.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/profile/ProfileInfoEntry.java @@ -1,6 +1,6 @@ package kamkeel.npcs.controllers.data.profile; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class ProfileInfoEntry { @@ -27,8 +27,8 @@ public class ProfileInfoEntry { this(label, 0xFFFFFF, result, 0xFFFFFF); } - public INBTCompound writeToNBT() { - INBTCompound tag = NBT.compound(); + public INbt writeToNBT() { + INbt tag = NBT.compound(); tag.setString("Label", label); tag.setInteger("LabelColor", labelColor); tag.setString("Result", result); @@ -36,7 +36,7 @@ public class ProfileInfoEntry { return tag; } - public static ProfileInfoEntry readFromNBT(INBTCompound tag) { + public static ProfileInfoEntry readFromNBT(INbt tag) { return new ProfileInfoEntry( tag.getString("Label"), tag.getInteger("LabelColor"), diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/profile/Slot.java b/core/src/main/java/kamkeel/npcs/controllers/data/profile/Slot.java index 69ddf0c89..3c2d091ab 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/profile/Slot.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/profile/Slot.java @@ -2,7 +2,7 @@ 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 noppes.npcs.api.INbt; import java.util.HashMap; import java.util.Map; @@ -13,14 +13,14 @@ public class Slot implements ISlot { private String name; private long lastLoaded; private boolean temporary; - private Map components = new HashMap<>(); + private Map 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 components) { + public Slot(int id, String name, long lastLoaded, boolean temporary, Map components) { this.id = id; this.name = name; this.lastLoaded = lastLoaded; @@ -68,35 +68,35 @@ public class Slot implements ISlot { } @Override - public Map getComponents() { + public Map getComponents() { return components; } @Override - public void setComponentData(String key, INBTCompound data) { + public void setComponentData(String key, INbt data) { components.put(key, data); } @Override - public INBTCompound getComponentData(String key) { + public INbt getComponentData(String key) { return components.get(key); } @Override - public INBTCompound toNBT() { - INBTCompound slotNBT = NBT.compound(); + public INbt toNBT() { + INbt slotNBT = NBT.compound(); slotNBT.setString("Name", name); slotNBT.setLong("LastLoaded", lastLoaded); slotNBT.setBoolean("Temporary", temporary); - INBTCompound compCompound = NBT.compound(); - for (Map.Entry entry : components.entrySet()) { + INbt compCompound = NBT.compound(); + for (Map.Entry entry : components.entrySet()) { compCompound.setCompound(entry.getKey(), entry.getValue()); } slotNBT.setCompound("Components", compCompound); return slotNBT; } - public static Slot fromNBT(int id, INBTCompound slotNBT) { + public static Slot fromNBT(int id, INbt slotNBT) { String name = slotNBT.getString("Name"); long lastLoaded = slotNBT.getLong("LastLoaded"); boolean temporary = slotNBT.getBoolean("Temporary"); @@ -104,7 +104,7 @@ public class Slot implements ISlot { slot.setLastLoaded(lastLoaded); slot.setTemporary(temporary); if (slotNBT.hasKey("Components")) { - INBTCompound compCompound = slotNBT.getCompound("Components"); + INbt compCompound = slotNBT.getCompound("Components"); Set keys = compCompound.getKeySet(); for (String key : keys) { slot.setComponentData(key, compCompound.getCompound(key)); diff --git a/core/src/main/java/kamkeel/npcs/controllers/data/telegraph/Telegraph.java b/core/src/main/java/kamkeel/npcs/controllers/data/telegraph/Telegraph.java index ebb6d89a9..f3d7d98b4 100644 --- a/core/src/main/java/kamkeel/npcs/controllers/data/telegraph/Telegraph.java +++ b/core/src/main/java/kamkeel/npcs/controllers/data/telegraph/Telegraph.java @@ -1,6 +1,6 @@ package kamkeel.npcs.controllers.data.telegraph; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; /** @@ -70,8 +70,8 @@ public class Telegraph { // NBT SERIALIZATION // ═══════════════════════════════════════════════════════════════════ - public INBTCompound writeNBT() { - INBTCompound nbt = NBT.compound(); + public INbt writeNBT() { + INbt nbt = NBT.compound(); nbt.setString("id", id); nbt.setString("type", type.name()); nbt.setFloat("radius", radius); @@ -93,7 +93,7 @@ public class Telegraph { return nbt; } - public void readNBT(INBTCompound nbt) { + public void readNBT(INbt nbt) { this.id = nbt.getString("id"); if (nbt.hasKey("type")) { try { diff --git a/core/src/main/java/noppes/npcs/NBTTags.java b/core/src/main/java/noppes/npcs/NBTTags.java index d0694ea3b..d0d7bf164 100644 --- a/core/src/main/java/noppes/npcs/NBTTags.java +++ b/core/src/main/java/noppes/npcs/NBTTags.java @@ -1,8 +1,8 @@ package noppes.npcs; import noppes.npcs.core.NBT; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.util.ArrayList; import java.util.HashMap; @@ -15,7 +15,7 @@ import java.util.Vector; /** * Core NBT serialization utilities for Map/Set/List collections. - * Uses INBTCompound/INBTList abstractions. + * Uses INbt/INbtList abstractions. * * NOTE: ItemStack-related methods, IScriptUnit methods, and raw NBT type methods * (nbtDoubleList, getIntAt) remain in the mc1710 version only since they require @@ -42,84 +42,84 @@ public class NBTTags { // OLD: nbtItemStackList(HashMap) - uses NoppesUtilServer.writeItem() // OLD: nbtItemStackArray(ItemStack[]) - uses NoppesUtilServer.writeItem() - public static ArrayList getIntegerArraySet(INBTList tagList) { + public static ArrayList getIntegerArraySet(INbtList tagList) { ArrayList set = new ArrayList(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound compound = tagList.getCompound(i); + INbt compound = tagList.getCompound(i); set.add(compound.getIntArray("Array")); } return set; } - public static HashMap getBooleanList(INBTList tagList) { + public static HashMap getBooleanList(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getBoolean("Boolean")); } return list; } - public static HashMap getIntegerIntegerMap(INBTList tagList) { + public static HashMap getIntegerIntegerMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getInteger("Integer")); } return list; } - public static HashMap getIntegerFloatMap(INBTList tagList) { + public static HashMap getIntegerFloatMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getFloat("Float")); } return list; } - public static HashMap getIntegerDoubleMap(INBTList tagList) { + public static HashMap getIntegerDoubleMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getDouble("Double")); } return list; } - public static HashMap getIntegerLongMap(INBTList tagList) { + public static HashMap getIntegerLongMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getLong("Long")); } return list; } - public static HashSet getStringSet(INBTList tagList) { + public static HashSet getStringSet(INbtList tagList) { HashSet list = new HashSet<>(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.add(nbttagcompound.getString("String")); } return list; } - public static HashMap getIntegerByteMap(INBTList tagList) { + public static HashMap getIntegerByteMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getByte("Byte")); } return list; } - public static INBTList nbtIntegerByteMap(Map lines) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerByteMap(Map lines) { + INbtList nbttaglist = NBT.list(); if (lines == null) return nbttaglist; for (int slot : lines.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setByte("Byte", lines.get(slot)); nbttaglist.addCompound(nbttagcompound); @@ -127,79 +127,79 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtStringSet(HashSet collection) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtStringSet(HashSet collection) { + INbtList nbttaglist = NBT.list(); if (collection == null) return nbttaglist; for (String slot : collection) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("String", slot); nbttaglist.addCompound(nbttagcompound); } return nbttaglist; } - public static HashSet getIntegerSet(INBTList tagList) { + public static HashSet getIntegerSet(INbtList tagList) { HashSet list = new HashSet(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.add(nbttagcompound.getInteger("Integer")); } return list; } - public static INBTList nbtIntegerSet(HashSet set) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerSet(HashSet set) { + INbtList nbttaglist = NBT.list(); if (set == null) return nbttaglist; for (int slot : set) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Integer", slot); nbttaglist.addCompound(nbttagcompound); } return nbttaglist; } - public static HashMap getStringStringMap(INBTList tagList) { + public static HashMap getStringStringMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getString("Slot"), nbttagcompound.getString("Value")); } return list; } - public static HashMap getIntegerStringMap(INBTList tagList) { + public static HashMap getIntegerStringMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getString("Value")); } return list; } - public static HashMap getStringIntegerMap(INBTList tagList) { + public static HashMap getStringIntegerMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getString("Slot"), nbttagcompound.getInteger("Value")); } return list; } - public static HashMap getStringIntegerArrayMap(INBTList tagList) { + public static HashMap getStringIntegerArrayMap(INbtList tagList) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getString("Slot"), nbttagcompound.getIntArray("Value")); } return list; } - public static HashMap getStringIntegerArrayMap(INBTList tagList, int arrayLength) { + public static HashMap getStringIntegerArrayMap(INbtList tagList, int arrayLength) { HashMap list = new HashMap(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); int[] a = nbttagcompound.getIntArray("Value"); if (a.length != arrayLength) a = new int[arrayLength]; list.put(nbttagcompound.getString("Slot"), a); @@ -207,14 +207,14 @@ public class NBTTags { return list; } - public static HashMap> getVectorMap(INBTList tagList) { + public static HashMap> getVectorMap(INbtList tagList) { HashMap> map = new HashMap>(); for (int i = 0; i < tagList.size(); i++) { Vector values = new Vector(); - INBTCompound nbttagcompound = tagList.getCompound(i); - INBTList list = nbttagcompound.getList("Values", 10); + INbt nbttagcompound = tagList.getCompound(i); + INbtList list = nbttagcompound.getTagList("Values", 10); for (int j = 0; j < list.size(); j++) { - INBTCompound value = list.getCompound(j); + INbt value = list.getCompound(j); values.add(value.getString("Value")); } @@ -224,20 +224,20 @@ public class NBTTags { } - public static List getStringList(INBTList tagList) { + public static List getStringList(INbtList tagList) { List list = new ArrayList(); for (int i = 0; i < tagList.size(); i++) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); String line = nbttagcompound.getString("Line"); list.add(line); } return list; } - public static String[] getStringArray(INBTList tagList, int size) { + 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); + INbt nbttagcompound = tagList.getCompound(i); String line = nbttagcompound.getString("Value"); int slot = nbttagcompound.getInteger("Slot"); arr[slot] = line; @@ -245,25 +245,25 @@ public class NBTTags { return arr; } - public static INBTList nbtIntegerArraySet(List set) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerArraySet(List set) { + INbtList nbttaglist = NBT.list(); if (set == null) return nbttaglist; for (int[] arr : set) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setIntArray("Array", arr); nbttaglist.addCompound(nbttagcompound); } return nbttaglist; } - public static INBTList nbtBooleanList(HashMap updatedSlots) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtBooleanList(HashMap updatedSlots) { + INbtList nbttaglist = NBT.list(); if (updatedSlots == null) return nbttaglist; HashMap inventory2 = updatedSlots; for (Integer slot : inventory2.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setBoolean("Boolean", inventory2.get(slot)); @@ -272,12 +272,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtIntegerIntegerMap(Map lines) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerIntegerMap(Map lines) { + INbtList nbttaglist = NBT.list(); if (lines == null) return nbttaglist; for (int slot : lines.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setInteger("Integer", lines.get(slot)); nbttaglist.addCompound(nbttagcompound); @@ -285,12 +285,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtIntegerFloatMap(Map lines) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerFloatMap(Map lines) { + INbtList nbttaglist = NBT.list(); if (lines == null) return nbttaglist; for (int slot : lines.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setDouble("Float", lines.get(slot)); nbttaglist.addCompound(nbttagcompound); @@ -298,12 +298,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtIntegerDoubleMap(Map lines) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerDoubleMap(Map lines) { + INbtList nbttaglist = NBT.list(); if (lines == null) return nbttaglist; for (int slot : lines.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setDouble("Double", lines.get(slot)); nbttaglist.addCompound(nbttagcompound); @@ -311,12 +311,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtIntegerLongMap(Map lines) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerLongMap(Map lines) { + INbtList nbttaglist = NBT.list(); if (lines == null) return nbttaglist; for (int slot : lines.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setLong("Long", lines.get(slot)); nbttaglist.addCompound(nbttagcompound); @@ -324,31 +324,31 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtVectorMap(Map> map) { - INBTList list = NBT.list(); + public static INbtList nbtVectorMap(Map> map) { + INbtList list = NBT.list(); if (map == null) return list; for (String key : map.keySet()) { - INBTCompound compound = NBT.compound(); + INbt compound = NBT.compound(); compound.setString("Key", key); - INBTList values = NBT.list(); + INbtList values = NBT.list(); for (String value : map.get(key)) { - INBTCompound comp = NBT.compound(); + INbt comp = NBT.compound(); comp.setString("Value", value); values.addCompound(comp); } - compound.setList("Values", values); + compound.setTagList("Values", values); list.addCompound(compound); } return list; } - public static INBTList nbtStringStringMap(Map map) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtStringStringMap(Map map) { + INbtList nbttaglist = NBT.list(); if (map == null) return nbttaglist; for (String slot : map.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("Slot", slot); nbttagcompound.setString("Value", map.get(slot)); @@ -357,12 +357,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtStringIntegerMap(Map map) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtStringIntegerMap(Map map) { + INbtList nbttaglist = NBT.list(); if (map == null) return nbttaglist; for (String slot : map.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("Slot", slot); nbttagcompound.setInteger("Value", map.get(slot)); @@ -371,12 +371,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtStringIntegerArrayMap(Map map) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtStringIntegerArrayMap(Map map) { + INbtList nbttaglist = NBT.list(); if (map == null) return nbttaglist; for (String slot : map.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("Slot", slot); nbttagcompound.setIntArray("Value", map.get(slot)); @@ -385,12 +385,12 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtIntegerStringMap(HashMap map) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtIntegerStringMap(HashMap map) { + INbtList nbttaglist = NBT.list(); if (map == null) return nbttaglist; for (int slot : map.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setString("Value", map.get(slot)); @@ -399,14 +399,14 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtStringArray(String[] list) { - INBTList nbttaglist = NBT.list(); + 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(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("Value", list[i]); nbttagcompound.setInteger("Slot", i); nbttaglist.addCompound(nbttagcompound); @@ -414,10 +414,10 @@ public class NBTTags { return nbttaglist; } - public static INBTList nbtStringList(List list) { - INBTList nbttaglist = NBT.list(); + public static INbtList nbtStringList(List list) { + INbtList nbttaglist = NBT.list(); for (String s : list) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setString("Line", s); nbttaglist.addCompound(nbttagcompound); } @@ -427,8 +427,8 @@ public class NBTTags { // 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(); + public static INbt NBTMerge(INbt data, INbt merge) { + INbt compound = data.copy(); Set names = merge.getKeySet(); for (String name : names) { int type = merge.getTagType(name); @@ -436,7 +436,7 @@ public class NBTTags { 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. + // We need to handle by type since INbt doesn't have a raw getTag/setTag. copyTag(compound, merge, name, type); } } @@ -447,7 +447,7 @@ public class NBTTags { * 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) { + private static void copyTag(INbt dest, INbt source, String key, int type) { switch (type) { case 1: // Byte dest.setByte(key, source.getByte(key)); @@ -474,7 +474,7 @@ public class NBTTags { dest.setString(key, source.getString(key)); break; case 9: // List - dest.setList(key, source.getList(key, 0)); + dest.setTagList(key, source.getTagList(key, 0)); break; case 10: // Compound (handled above in NBTMerge) dest.setCompound(key, source.getCompound(key)); @@ -485,24 +485,24 @@ public class NBTTags { } } - public static TreeMap GetLongStringMap(INBTList tagList) { + public static TreeMap GetLongStringMap(INbtList tagList) { TreeMap list = new TreeMap<>(); for (int i = 0; i < tagList.size(); ++i) { - INBTCompound nbttagcompound = tagList.getCompound(i); + INbt nbttagcompound = tagList.getCompound(i); list.put(nbttagcompound.getLong("Long"), nbttagcompound.getString("String")); } return list; } - public static INBTList NBTLongStringMap(Map map) { - INBTList nbttaglist = NBT.list(); + public static INbtList NBTLongStringMap(Map map) { + INbtList nbttaglist = NBT.list(); if (map == null) { return nbttaglist; } else { for (long slot : map.keySet()) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setLong("Long", slot); nbttagcompound.setString("String", map.get(slot)); nbttaglist.addCompound(nbttagcompound); diff --git a/core/src/main/java/noppes/npcs/constants/NBTTypes.java b/core/src/main/java/noppes/npcs/constants/NBTTypes.java index 2385b5dcb..61b220729 100644 --- a/core/src/main/java/noppes/npcs/constants/NBTTypes.java +++ b/core/src/main/java/noppes/npcs/constants/NBTTypes.java @@ -4,8 +4,8 @@ package noppes.npcs.constants; * NBT type ID constants, matching Minecraft's internal NBT type numbering. * These are stable across all MC versions. * - * Use these instead of magic numbers when calling INBTCompound.hasKey(key, type) - * or INBTCompound.getList(key, type). + * Use these instead of magic numbers when calling INbt.hasKey(key, type) + * or INbt.getTagList(key, type). */ public final class NBTTypes { diff --git a/core/src/main/java/noppes/npcs/controllers/FactionController.java b/core/src/main/java/noppes/npcs/controllers/FactionController.java index fa02ee05a..b7e6a945d 100644 --- a/core/src/main/java/noppes/npcs/controllers/FactionController.java +++ b/core/src/main/java/noppes/npcs/controllers/FactionController.java @@ -2,9 +2,9 @@ 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 kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.io.File; import java.util.HashMap; @@ -70,18 +70,18 @@ public class FactionController { // OLD: DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))); // OLD: loadFactions(var1); // OLD: var1.close(); - INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); + INbt nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); loadFactions(nbttagcompound1); } - public void loadFactions(INBTCompound nbttagcompound1) { + public void loadFactions(INbt nbttagcompound1) { HashMap factions = new HashMap(); lastUsedID = nbttagcompound1.getInteger("lastID"); - INBTList list = nbttagcompound1.getList("NPCFactions", 10); + INbtList list = nbttagcompound1.getTagList("NPCFactions", 10); if (list != null) { for (int i = 0; i < list.size(); i++) { - INBTCompound nbttagcompound = list.getCompound(i); + INbt nbttagcompound = list.getCompound(i); Faction faction = new Faction(); faction.readNBT(nbttagcompound); factions.put(faction.id, faction); @@ -90,17 +90,17 @@ public class FactionController { this.factions = factions; } - public INBTCompound getNBT() { - INBTList list = NBT.list(); + public INbt getNBT() { + INbtList list = NBT.list(); for (int slot : factions.keySet()) { Faction faction = factions.get(slot); - INBTCompound nbtfactions = NBT.compound(); + INbt nbtfactions = NBT.compound(); faction.writeNBT(nbtfactions); list.addCompound(nbtfactions); } - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("lastID", lastUsedID); - nbttagcompound.setList("NPCFactions", list); + nbttagcompound.setTagList("NPCFactions", list); return nbttagcompound; } diff --git a/core/src/main/java/noppes/npcs/controllers/GlobalDataController.java b/core/src/main/java/noppes/npcs/controllers/GlobalDataController.java index 18029f60b..5c70e4e44 100644 --- a/core/src/main/java/noppes/npcs/controllers/GlobalDataController.java +++ b/core/src/main/java/noppes/npcs/controllers/GlobalDataController.java @@ -1,8 +1,8 @@ package noppes.npcs.controllers; import noppes.npcs.core.NBT; -import noppes.npcs.platform.PlatformServiceHolder; -import noppes.npcs.platform.nbt.INBTCompound; +import kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; import java.io.File; @@ -42,7 +42,7 @@ public class GlobalDataController { // OLD: try (FileInputStream fis = new FileInputStream(file)) { // OLD: nbttagcompound1 = CompressedStreamTools.readCompressed(fis); // OLD: } - INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); + INbt nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); itemGiverId = nbttagcompound1.getInteger("itemGiverId"); } @@ -52,7 +52,7 @@ public class GlobalDataController { File saveDir = PlatformServiceHolder.get().getWorldSaveDirectory(); // OLD: NBTTagCompound nbttagcompound = new NBTTagCompound(); - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("itemGiverId", itemGiverId); File file = new File(saveDir, "global.dat_new"); diff --git a/core/src/main/java/noppes/npcs/controllers/MagicController.java b/core/src/main/java/noppes/npcs/controllers/MagicController.java index 355a3f88e..684c61118 100644 --- a/core/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/core/src/main/java/noppes/npcs/controllers/MagicController.java @@ -5,9 +5,9 @@ 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 kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.io.File; import java.util.HashMap; @@ -185,27 +185,27 @@ public class MagicController { // OLD: ); // OLD: loadMagic(stream); // OLD: stream.close(); - INBTCompound compound = PlatformServiceHolder.get().readCompressedNBT(file); + INbt compound = PlatformServiceHolder.get().readCompressedNBT(file); loadMagic(compound); } - public void loadMagic(INBTCompound compound) { + public void loadMagic(INbt compound) { lastUsedMagicID = compound.getInteger("lastID"); lastUsedCycleID = compound.getInteger("lastCycleID"); magics.clear(); - INBTList magicList = compound.getList("Magics", 10); + INbtList magicList = compound.getTagList("Magics", 10); for (int i = 0; i < magicList.size(); i++) { - INBTCompound magCompound = magicList.getCompound(i); + INbt magCompound = magicList.getCompound(i); Magic mag = new Magic(); mag.readNBT(magCompound); magics.put(mag.id, mag); } cycles.clear(); - INBTList cycleList = compound.getList("Cycles", 10); + INbtList cycleList = compound.getTagList("Cycles", 10); for (int i = 0; i < cycleList.size(); i++) { - INBTCompound catCompound = cycleList.getCompound(i); + INbt catCompound = cycleList.getCompound(i); MagicCycle cycle = new MagicCycle(); // OLD: cycle.readNBT(new NBTWrapper(catCompound)); cycle.readNBT(catCompound); @@ -213,25 +213,25 @@ public class MagicController { } } - public INBTCompound getNBT() { - INBTList magicList = NBT.list(); + public INbt getNBT() { + INbtList magicList = NBT.list(); for (Magic mag : magics.values()) { - INBTCompound magCompound = NBT.compound(); + INbt magCompound = NBT.compound(); mag.writeNBT(magCompound); magicList.addCompound(magCompound); } - INBTList catList = NBT.list(); + INbtList catList = NBT.list(); for (MagicCycle cat : cycles.values()) { - INBTCompound catCompound = NBT.compound(); + INbt catCompound = NBT.compound(); // OLD: cat.writeNBT(new NBTWrapper(catCompound)); cat.writeNBT(catCompound); catList.addCompound(catCompound); } - INBTCompound compound = NBT.compound(); + INbt compound = NBT.compound(); compound.setInteger("lastID", lastUsedMagicID); compound.setInteger("lastCycleID", lastUsedCycleID); - compound.setList("Magics", magicList); - compound.setList("Cycles", catList); + compound.setTagList("Magics", magicList); + compound.setTagList("Cycles", catList); return compound; } diff --git a/core/src/main/java/noppes/npcs/controllers/ServerTagMapController.java b/core/src/main/java/noppes/npcs/controllers/ServerTagMapController.java index fc5d92441..d25bb5f86 100644 --- a/core/src/main/java/noppes/npcs/controllers/ServerTagMapController.java +++ b/core/src/main/java/noppes/npcs/controllers/ServerTagMapController.java @@ -1,8 +1,8 @@ package noppes.npcs.controllers; import noppes.npcs.controllers.data.TagMap; -import noppes.npcs.platform.PlatformServiceHolder; -import noppes.npcs.platform.nbt.INBTCompound; +import kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; import java.io.File; @@ -58,7 +58,7 @@ public class ServerTagMapController { // OLD: NBTTagCompound nbtCompound = CompressedStreamTools.read(var1); // OLD: this.tagMap.readNBT(new NBTWrapper(nbtCompound)); // OLD: var1.close(); - INBTCompound nbtCompound = PlatformServiceHolder.get().readCompressedNBT(file); + INbt nbtCompound = PlatformServiceHolder.get().readCompressedNBT(file); this.tagMap.readNBT(nbtCompound); } diff --git a/core/src/main/java/noppes/npcs/controllers/TagController.java b/core/src/main/java/noppes/npcs/controllers/TagController.java index 079b56799..3c8297264 100644 --- a/core/src/main/java/noppes/npcs/controllers/TagController.java +++ b/core/src/main/java/noppes/npcs/controllers/TagController.java @@ -2,9 +2,9 @@ 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 kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.io.File; import java.util.HashMap; @@ -59,18 +59,18 @@ public class TagController { // OLD: DataInputStream var1 = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(file)))); // OLD: loadTags(var1); // OLD: var1.close(); - INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); + INbt nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); loadTags(nbttagcompound1); } - public void loadTags(INBTCompound nbttagcompound1) { + public void loadTags(INbt nbttagcompound1) { HashMap tags = new HashMap(); lastUsedID = nbttagcompound1.getInteger("lastID"); - INBTList list = nbttagcompound1.getList("NPCTags", 10); + INbtList list = nbttagcompound1.getTagList("NPCTags", 10); if (list != null) { for (int i = 0; i < list.size(); i++) { - INBTCompound nbttagcompound = list.getCompound(i); + INbt nbttagcompound = list.getCompound(i); Tag tag = new Tag(); // OLD: tag.readNBT(new NBTWrapper(nbttagcompound)); tag.readNBT(nbttagcompound); @@ -80,18 +80,18 @@ public class TagController { this.tags = tags; } - public INBTCompound getNBT() { - INBTList list = NBT.list(); + public INbt getNBT() { + INbtList list = NBT.list(); for (int slot : tags.keySet()) { Tag tag = tags.get(slot); - INBTCompound nbtfactions = NBT.compound(); + INbt nbtfactions = NBT.compound(); // OLD: tag.writeNBT(new NBTWrapper(nbtfactions)); tag.writeNBT(nbtfactions); list.addCompound(nbtfactions); } - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("lastID", lastUsedID); - nbttagcompound.setList("NPCTags", list); + nbttagcompound.setTagList("NPCTags", list); return nbttagcompound; } @@ -218,23 +218,23 @@ public class TagController { /** * Write a set of tag UUIDs to an NBT compound under the given key. */ - public static void writeTagUUIDs(INBTCompound compound, String key, HashSet tagUUIDs) { + public static void writeTagUUIDs(INbt compound, String key, HashSet tagUUIDs) { if (tagUUIDs != null && !tagUUIDs.isEmpty()) { - INBTList list = NBT.list(); + INbtList list = NBT.list(); for (UUID uuid : tagUUIDs) { list.addString(uuid.toString()); } - compound.setList(key, list); + compound.setTagList(key, list); } } /** * Read a set of tag UUIDs from an NBT compound under the given key. */ - public static HashSet readTagUUIDs(INBTCompound compound, String key) { + public static HashSet readTagUUIDs(INbt compound, String key) { HashSet uuids = new HashSet<>(); if (compound.hasKey(key)) { - INBTList list = compound.getList(key, 8); + INbtList list = compound.getTagList(key, 8); for (int i = 0; i < list.size(); i++) { try { uuids.add(UUID.fromString(list.getString(i))); diff --git a/core/src/main/java/noppes/npcs/controllers/TransportController.java b/core/src/main/java/noppes/npcs/controllers/TransportController.java index e2fd48ad6..60ea82ec7 100644 --- a/core/src/main/java/noppes/npcs/controllers/TransportController.java +++ b/core/src/main/java/noppes/npcs/controllers/TransportController.java @@ -3,13 +3,12 @@ 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 kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.io.File; import java.util.HashMap; -import java.util.Map; public class TransportController { private HashMap locations = new HashMap(); @@ -68,15 +67,15 @@ public class TransportController { // OLD: try (FileInputStream fis = new FileInputStream(file)) { // OLD: nbttagcompound1 = CompressedStreamTools.readCompressed(fis); // OLD: } - INBTCompound nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); + INbt nbttagcompound1 = PlatformServiceHolder.get().readCompressedNBT(file); lastUsedID = nbttagcompound1.getInteger("lastID"); - INBTList list = nbttagcompound1.getList("NPCTransportCategories", 10); + INbtList list = nbttagcompound1.getTagList("NPCTransportCategories", 10); if (list == null) { return; } for (int i = 0; i < list.size(); i++) { TransportCategory category = new TransportCategory(); - INBTCompound compound = list.getCompound(i); + INbt compound = list.getCompound(i); // OLD: category.readNBT(new NBTWrapper(compound)); category.readNBT(compound); @@ -89,16 +88,16 @@ public class TransportController { this.categories = categories; } - public INBTCompound getNBT() { - INBTList list = NBT.list(); + public INbt getNBT() { + INbtList list = NBT.list(); for (TransportCategory category : categories.values()) { - INBTCompound compound = NBT.compound(); + INbt compound = NBT.compound(); category.writeNBT(compound); list.addCompound(compound); } - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("lastID", lastUsedID); - nbttagcompound.setList("NPCTransportCategories", list); + nbttagcompound.setTagList("NPCTransportCategories", list); return nbttagcompound; } diff --git a/core/src/main/java/noppes/npcs/controllers/data/AbilityHotbarData.java b/core/src/main/java/noppes/npcs/controllers/data/AbilityHotbarData.java index 9f466a94f..636f13dae 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/AbilityHotbarData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/AbilityHotbarData.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class AbilityHotbarData { @@ -26,15 +26,15 @@ public class AbilityHotbarData { return abilityKey; } - public INBTCompound writeToNBT(INBTCompound compound) { - INBTCompound tag = NBT.compound(); + public INbt writeToNBT(INbt compound) { + INbt tag = NBT.compound(); tag.setInteger("slot", slot); tag.setString("abilityKey", abilityKey != null ? abilityKey : ""); compound.setCompound("AbilityHotbar" + slot, tag); return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { abilityKey = compound.getString("abilityKey"); } diff --git a/core/src/main/java/noppes/npcs/controllers/data/AuctionFilter.java b/core/src/main/java/noppes/npcs/controllers/data/AuctionFilter.java index dba39f7c7..04e324d9d 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/AuctionFilter.java +++ b/core/src/main/java/noppes/npcs/controllers/data/AuctionFilter.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.constants.EnumAuctionSort; import java.util.regex.Pattern; @@ -87,13 +87,13 @@ public class AuctionFilter { normalizedSearch = ""; } - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { compound.setString("SearchText", searchText != null ? searchText : ""); compound.setInteger("SortBy", sortBy.ordinal()); return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { searchText = compound.getString("SearchText"); normalizedSearch = normalizeForSearch(searchText); sortBy = EnumAuctionSort.fromOrdinal(compound.getInteger("SortBy")); diff --git a/core/src/main/java/noppes/npcs/controllers/data/Category.java b/core/src/main/java/noppes/npcs/controllers/data/Category.java index 34cfd192e..8be8ca387 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Category.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Category.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; /** @@ -19,12 +19,12 @@ public class Category { this.title = title; } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { id = compound.getInteger("CatID"); title = compound.getString("CatTitle"); } - public INBTCompound writeNBT(INBTCompound compound) { + public INbt writeNBT(INbt compound) { compound.setInteger("CatID", id); compound.setString("CatTitle", title); return compound; diff --git a/core/src/main/java/noppes/npcs/controllers/data/CloneFolder.java b/core/src/main/java/noppes/npcs/controllers/data/CloneFolder.java index a83aec391..68c690332 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/CloneFolder.java +++ b/core/src/main/java/noppes/npcs/controllers/data/CloneFolder.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class CloneFolder { @@ -17,12 +17,12 @@ public class CloneFolder { this.createdDate = System.currentTimeMillis(); } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { name = compound.getString("Name"); createdDate = compound.getLong("Created"); } - public INBTCompound writeNBT(INBTCompound compound) { + public INbt writeNBT(INbt compound) { compound.setString("Name", name); compound.setLong("Created", createdDate); return compound; diff --git a/core/src/main/java/noppes/npcs/controllers/data/DialogColorData.java b/core/src/main/java/noppes/npcs/controllers/data/DialogColorData.java index e0693a907..e9e2da1c2 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/DialogColorData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/DialogColorData.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class DialogColorData { @@ -12,7 +12,7 @@ public class DialogColorData { private int buttonAcceptColor = 0xfff96605; private int buttonRejectColor = 0xfff96605; - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { compound.setBoolean("ColorSettings", enableColorSettings); if (enableColorSettings) { compound.setInteger("LineColor1", lineColor1); @@ -25,7 +25,7 @@ public class DialogColorData { return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { this.enableColorSettings = compound.getBoolean("ColorSettings"); if (enableColorSettings) { lineColor1 = compound.getInteger("LineColor1"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/DialogImage.java b/core/src/main/java/noppes/npcs/controllers/data/DialogImage.java index 7a57ded46..3d1e29e4d 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/DialogImage.java +++ b/core/src/main/java/noppes/npcs/controllers/data/DialogImage.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IDialogImage; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; public class DialogImage implements IDialogImage { public int id; @@ -29,7 +29,7 @@ public class DialogImage implements IDialogImage { this.id = id; } - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { compound.setInteger("ID", id); compound.setString("Texture", texture); compound.setInteger("PosX", x); @@ -49,7 +49,7 @@ public class DialogImage implements IDialogImage { return compound; } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { id = compound.getInteger("ID"); texture = compound.getString("Texture"); x = compound.getInteger("PosX"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/Faction.java b/core/src/main/java/noppes/npcs/controllers/data/Faction.java index aa6ef1d9b..5bab37810 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Faction.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Faction.java @@ -1,8 +1,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.NBTTags; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.util.HashSet; @@ -39,7 +39,7 @@ public class Faction { return name.substring(0, 1).toUpperCase() + name.substring(1); } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { name = compound.getString("Name"); color = compound.getInteger("Color"); id = compound.getInteger("Slot"); @@ -52,10 +52,10 @@ public class Faction { getsAttacked = compound.getBoolean("GetsAttacked"); isPassive = compound.getBoolean("IsPassive"); - attackFactions = NBTTags.getIntegerSet(compound.getList("AttackFactions", 10)); + attackFactions = NBTTags.getIntegerSet(compound.getTagList("AttackFactions", 10)); } - public void writeNBT(INBTCompound compound) { + public void writeNBT(INbt compound) { compound.setInteger("Slot", id); compound.setString("Name", name); compound.setInteger("Color", color); @@ -68,7 +68,7 @@ public class Faction { compound.setBoolean("GetsAttacked", getsAttacked); compound.setBoolean("IsPassive", isPassive); - compound.setList("AttackFactions", NBTTags.nbtIntegerSet(attackFactions)); + compound.setTagList("AttackFactions", NBTTags.nbtIntegerSet(attackFactions)); } // TODO: mc1710 version implements IFaction and adds: diff --git a/core/src/main/java/noppes/npcs/controllers/data/Frame.java b/core/src/main/java/noppes/npcs/controllers/data/Frame.java index d63db42f7..2ff18ed07 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Frame.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Frame.java @@ -3,8 +3,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IFrame; import noppes.npcs.api.handler.data.IFramePart; import noppes.npcs.constants.EnumAnimationPart; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.HashMap; @@ -124,7 +124,7 @@ public class Frame implements IFrame { this.comment = comment; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { duration = compound.getInteger("Duration"); if (compound.hasKey("ColorMarker")) { this.setColorMarker(compound.getInteger("ColorMarker")); @@ -149,9 +149,9 @@ public class Frame implements IFrame { } HashMap frameParts = new HashMap<>(); - INBTList list = compound.getList("FrameParts", 10); + INbtList list = compound.getTagList("FrameParts", 10); for (int i = 0; i < list.size(); i++) { - INBTCompound item = list.getCompound(i); + INbt item = list.getCompound(i); FramePart framePart = new FramePart(); framePart.readFromNBT(item); if (!framePart.customized) { @@ -163,8 +163,8 @@ public class Frame implements IFrame { this.frameParts = frameParts; } - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); compound.setInteger("Duration", duration); compound.setInteger("ColorMarker", this.colorMarker); compound.setString("Comment", this.comment); @@ -174,12 +174,12 @@ public class Frame implements IFrame { compound.setByte("Smooth", smooth); } - INBTList list = NBT.list(); + INbtList list = NBT.list(); for (FramePart framePart : frameParts.values()) { - INBTCompound item = framePart.writeToNBT(); + INbt item = framePart.writeToNBT(); list.addCompound(item); } - compound.setList("FrameParts", list); + compound.setTagList("FrameParts", list); return compound; } diff --git a/core/src/main/java/noppes/npcs/controllers/data/FramePart.java b/core/src/main/java/noppes/npcs/controllers/data/FramePart.java index a3081ea31..ffb1e3384 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/FramePart.java +++ b/core/src/main/java/noppes/npcs/controllers/data/FramePart.java @@ -2,7 +2,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IFramePart; import noppes.npcs.constants.EnumAnimationPart; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class FramePart implements IFramePart { @@ -111,7 +111,7 @@ public class FramePart implements IFramePart { return this; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { part = EnumAnimationPart.valueOf(compound.getString("Part")); for (int i = 0; i < 3; i++) { rotation[i] = compound.getFloat("Rotation" + i); @@ -131,8 +131,8 @@ public class FramePart implements IFramePart { } } - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); compound.setString("Part", part.toString()); for (int i = 0; i < 3; i++) { compound.setFloat("Rotation" + i, rotation[i]); diff --git a/core/src/main/java/noppes/npcs/controllers/data/HitboxData.java b/core/src/main/java/noppes/npcs/controllers/data/HitboxData.java index 224807c0c..72c6224cb 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/HitboxData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/HitboxData.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.entity.data.IHitboxData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.CoreConfig; public class HitboxData implements IHitboxData { @@ -10,7 +10,7 @@ public class HitboxData implements IHitboxData { private float heightScale = 1f; private boolean hitboxEnabled = false; - public INBTCompound writeToNBT(INBTCompound nbttagcompound) { + public INbt writeToNBT(INbt nbttagcompound) { nbttagcompound.setBoolean("HitboxEnabled", hitboxEnabled); if (hitboxEnabled) { if (widthScale > CoreConfig.HitBoxScaleMax) @@ -24,7 +24,7 @@ public class HitboxData implements IHitboxData { return nbttagcompound; } - public void readFromNBT(INBTCompound nbttagcompound) { + public void readFromNBT(INbt nbttagcompound) { hitboxEnabled = nbttagcompound.getBoolean("HitboxEnabled"); if (hitboxEnabled) { widthScale = nbttagcompound.getFloat("HitboxWidthScale"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/ItemDisplayData.java b/core/src/main/java/noppes/npcs/controllers/data/ItemDisplayData.java index a57a70aa0..e3cedffd8 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/ItemDisplayData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/ItemDisplayData.java @@ -1,6 +1,6 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class ItemDisplayData { @@ -18,13 +18,13 @@ public class ItemDisplayData { public Integer frameCount = 1; public Integer frametime = 2; - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); this.writeToNBT(compound); return compound; } - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { this.setBoolean(compound, "DurabilityShow", this.durabilityShow); this.setInteger(compound, "DurabilityColor", this.durabilityColor); this.setInteger(compound, "ItemColor", this.itemColor); @@ -55,7 +55,7 @@ public class ItemDisplayData { return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { if (compound.hasKey("DurabilityShow")) { this.durabilityShow = compound.getBoolean("DurabilityShow"); } @@ -119,19 +119,19 @@ public class ItemDisplayData { } } - private void setBoolean(INBTCompound compound, String key, Boolean value) { + private void setBoolean(INbt compound, String key, Boolean value) { if (value != null) { compound.setBoolean(key, value); } } - private void setInteger(INBTCompound compound, String key, Integer value) { + private void setInteger(INbt compound, String key, Integer value) { if (value != null) { compound.setInteger(key, value); } } - private void setFloat(INBTCompound compound, String key, Float value) { + private void setFloat(INbt compound, String key, Float value) { if (value != null) { compound.setFloat(key, value); } diff --git a/core/src/main/java/noppes/npcs/controllers/data/Lines.java b/core/src/main/java/noppes/npcs/controllers/data/Lines.java index 4d6d602b2..289f16ccb 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Lines.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Lines.java @@ -2,8 +2,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.ILine; import noppes.npcs.api.handler.data.ILines; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.ArrayList; @@ -17,13 +17,13 @@ public class Lines implements ILines { public HashMap lines = new HashMap(); - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); - INBTList nbttaglist = NBT.list(); + INbtList nbttaglist = NBT.list(); for (int slot : lines.keySet()) { Line line = lines.get(slot); - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Slot", slot); nbttagcompound.setString("Line", line.text); nbttagcompound.setString("Song", line.sound); @@ -31,16 +31,16 @@ public class Lines implements ILines { nbttaglist.addCompound(nbttagcompound); } - compound.setList("Lines", nbttaglist); + compound.setTagList("Lines", nbttaglist); return compound; } - public void readNBT(INBTCompound compound) { - INBTList nbttaglist = compound.getList("Lines", 10); + public void readNBT(INbt compound) { + INbtList nbttaglist = compound.getTagList("Lines", 10); HashMap map = new HashMap(); for (int i = 0; i < nbttaglist.size(); i++) { - INBTCompound nbttagcompound = nbttaglist.getCompound(i); + INbt nbttagcompound = nbttaglist.getCompound(i); Line line = new Line(); line.text = nbttagcompound.getString("Line"); line.sound = nbttagcompound.getString("Song"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/Magic.java b/core/src/main/java/noppes/npcs/controllers/data/Magic.java index 3a5f055ca..50df15589 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Magic.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Magic.java @@ -3,8 +3,8 @@ 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 noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import java.util.HashMap; import java.util.Map; @@ -37,7 +37,7 @@ public class Magic { return name.substring(0, 1).toUpperCase() + name.substring(1); } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { name = compound.getString("Name"); displayName = compound.getString("DisplayName"); color = compound.getInteger("Color"); @@ -54,9 +54,9 @@ public class Magic { interactions.clear(); if (compound.hasKey("Interactions")) { - INBTList interactionsList = compound.getList("Interactions", 10); + INbtList interactionsList = compound.getTagList("Interactions", 10); for (int i = 0; i < interactionsList.size(); i++) { - INBTCompound interactionTag = interactionsList.getCompound(i); + INbt interactionTag = interactionsList.getCompound(i); int magicId = interactionTag.getInteger("MagicID"); float percentage = interactionTag.getFloat("Percentage"); interactions.put(magicId, percentage); @@ -64,21 +64,21 @@ public class Magic { } } - public void writeNBT(INBTCompound compound) { + public void writeNBT(INbt 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(); + INbtList interactionsList = NBT.list(); for (Map.Entry entry : interactions.entrySet()) { - INBTCompound interactionTag = NBT.compound(); + INbt interactionTag = NBT.compound(); interactionTag.setInteger("MagicID", entry.getKey()); interactionTag.setFloat("Percentage", entry.getValue()); interactionsList.addCompound(interactionTag); } - compound.setList("Interactions", interactionsList); + compound.setTagList("Interactions", interactionsList); // TODO: mc1710 version resolves ItemStack from GameRegistry here: // OLD: if (type == EnumTextureType.ITEM && !iconTexture.isEmpty()) { diff --git a/core/src/main/java/noppes/npcs/controllers/data/MagicCycle.java b/core/src/main/java/noppes/npcs/controllers/data/MagicCycle.java index 12557124e..a5f9cb73d 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/MagicCycle.java +++ b/core/src/main/java/noppes/npcs/controllers/data/MagicCycle.java @@ -1,8 +1,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IMagicCycle; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import noppes.npcs.constants.EnumDiagramLayout; @@ -22,15 +22,15 @@ public class MagicCycle implements IMagicCycle { public MagicCycle() { } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { id = compound.getInteger("ID"); name = compound.getString("Name"); displayName = compound.getString("DisplayName"); layout = EnumDiagramLayout.values()[compound.getInteger("Layout")]; associations.clear(); - INBTList list = compound.getList("Associations", 10); // compound tags + INbtList list = compound.getTagList("Associations", 10); // compound tags for (int i = 0; i < list.size(); i++) { - INBTCompound assocTag = list.getCompound(i); + INbt assocTag = list.getCompound(i); MagicAssociation assoc = new MagicAssociation(); assoc.magicId = assocTag.getInteger("MagicID"); assoc.index = assocTag.getInteger("Index"); @@ -39,20 +39,20 @@ public class MagicCycle implements IMagicCycle { } } - public void writeNBT(INBTCompound compound) { + public void writeNBT(INbt compound) { compound.setInteger("ID", id); compound.setString("Name", name); compound.setString("DisplayName", displayName); compound.setInteger("Layout", layout.ordinal()); - INBTList list = NBT.list(); + INbtList list = NBT.list(); for (MagicAssociation assoc : associations.values()) { - INBTCompound assocTag = NBT.compound(); + INbt assocTag = NBT.compound(); assocTag.setInteger("MagicID", assoc.magicId); assocTag.setInteger("Index", assoc.index); assocTag.setInteger("Priority", assoc.priority); list.addCompound(assocTag); } - compound.setList("Associations", list); + compound.setTagList("Associations", list); } public int getId() { diff --git a/core/src/main/java/noppes/npcs/controllers/data/MagicData.java b/core/src/main/java/noppes/npcs/controllers/data/MagicData.java index de23ba81f..6038306df 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/MagicData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/MagicData.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IMagicData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; import java.util.HashMap; @@ -9,16 +9,16 @@ import java.util.HashMap; public class MagicData implements IMagicData { private final HashMap magics = new HashMap<>(); - public void writeToNBT(INBTCompound compound) { - INBTCompound magicData = NBT.compound(); + public void writeToNBT(INbt compound) { + INbt magicData = NBT.compound(); for (int key : magics.keySet()) { magicData.setCompound(String.valueOf(key), magics.get(key).writeToNBT()); } compound.setCompound("MagicData", magicData); } - public void readToNBT(INBTCompound compound) { - INBTCompound magicData = compound.getCompound("MagicData"); + public void readToNBT(INbt compound) { + INbt magicData = compound.getCompound("MagicData"); magics.clear(); if (magicData == null) return; diff --git a/core/src/main/java/noppes/npcs/controllers/data/MagicEntry.java b/core/src/main/java/noppes/npcs/controllers/data/MagicEntry.java index 1fc661d71..76df5996a 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/MagicEntry.java +++ b/core/src/main/java/noppes/npcs/controllers/data/MagicEntry.java @@ -1,20 +1,20 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class MagicEntry { public float damage; public float split; - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); compound.setFloat("Dmg", damage); compound.setFloat("Split", split); return compound; } - public void readToNBT(INBTCompound compound) { + public void readToNBT(INbt compound) { damage = compound.getFloat("Dmg"); split = compound.getFloat("Split"); } diff --git a/core/src/main/java/noppes/npcs/controllers/data/PartyOptions.java b/core/src/main/java/noppes/npcs/controllers/data/PartyOptions.java index 156825b6b..3c771654b 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/PartyOptions.java +++ b/core/src/main/java/noppes/npcs/controllers/data/PartyOptions.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IPartyOptions; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; import noppes.npcs.core.CoreConfig; import noppes.npcs.constants.EnumPartyExchange; @@ -25,7 +25,7 @@ public class PartyOptions implements IPartyOptions { public int minPartySize = CoreConfig.DefaultMinPartySize; public int maxPartySize = CoreConfig.DefaultMaxPartySize; - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { // Party Management allowParty = compound.getBoolean("AllowParty"); if (allowParty) { @@ -74,8 +74,8 @@ public class PartyOptions implements IPartyOptions { } } - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); compound.setBoolean("AllowParty", allowParty); if (allowParty) { compound.setBoolean("OnlyParty", onlyParty); diff --git a/core/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java b/core/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java index 0b1294b66..46fd5720f 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/PlayerDialogData.java @@ -1,8 +1,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.IPlayerDialogData; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.HashSet; @@ -13,31 +13,31 @@ public class PlayerDialogData implements IPlayerDialogData { public PlayerDialogData() { } - public void loadNBTData(INBTCompound compound) { + public void loadNBTData(INbt compound) { HashSet dialogsRead = new HashSet(); if (compound == null) return; - INBTList list = compound.getList("DialogData", 10); + INbtList list = compound.getTagList("DialogData", 10); if (list == null) { return; } for (int i = 0; i < list.size(); i++) { - INBTCompound nbttagcompound = list.getCompound(i); + INbt nbttagcompound = list.getCompound(i); dialogsRead.add(nbttagcompound.getInteger("Dialog")); } this.dialogsRead = dialogsRead; } - public void saveNBTData(INBTCompound compound) { - INBTList list = NBT.list(); + public void saveNBTData(INbt compound) { + INbtList list = NBT.list(); for (int dia : dialogsRead) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Dialog", dia); list.addCompound(nbttagcompound); } - compound.setList("DialogData", list); + compound.setTagList("DialogData", list); } public boolean hasReadDialog(int id) { diff --git a/core/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java b/core/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java index 9578169a6..4985a7913 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/PlayerEffectData.java @@ -1,8 +1,8 @@ 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.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.HashSet; @@ -16,26 +16,26 @@ public class PlayerEffectData { public PlayerEffectData() { } - public INBTCompound writeToNBT(INBTCompound compound) { - INBTList list = NBT.list(); + public INbt writeToNBT(INbt compound) { + INbtList list = NBT.list(); for (Map.Entry entry : effects.entrySet()) { - INBTCompound effectCompound = NBT.compound(); + INbt 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); + compound.setTagList("Effects", list); return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { HashSet newKeys = new HashSet<>(); if (compound.hasKey("Effects")) { - INBTList list = compound.getList("Effects", NBTTypes.TAG_COMPOUND); + INbtList list = compound.getTagList("Effects", NBTTypes.TAG_COMPOUND); for (int i = 0; i < list.size(); i++) { - INBTCompound effectCompound = list.getCompound(i); + INbt effectCompound = list.getCompound(i); int id = effectCompound.getInteger("id"); int index = effectCompound.getInteger("index"); int duration = effectCompound.getInteger("duration"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java b/core/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java index d7fec48be..b0011cb6b 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/PlayerTransportData.java @@ -2,8 +2,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.IPlayerTransportData; import noppes.npcs.api.handler.data.ITransportLocation; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.HashSet; @@ -14,31 +14,31 @@ public class PlayerTransportData implements IPlayerTransportData { public PlayerTransportData() { } - public void loadNBTData(INBTCompound compound) { + public void loadNBTData(INbt compound) { HashSet dialogsRead = new HashSet(); if (compound == null) return; - INBTList list = compound.getList("TransportData", 10); + INbtList list = compound.getTagList("TransportData", 10); if (list == null) { return; } for (int i = 0; i < list.size(); i++) { - INBTCompound nbttagcompound = list.getCompound(i); + INbt nbttagcompound = list.getCompound(i); dialogsRead.add(nbttagcompound.getInteger("Transport")); } this.transports = dialogsRead; } - public void saveNBTData(INBTCompound compound) { - INBTList list = NBT.list(); + public void saveNBTData(INbt compound) { + INbtList list = NBT.list(); for (int dia : transports) { - INBTCompound nbttagcompound = NBT.compound(); + INbt nbttagcompound = NBT.compound(); nbttagcompound.setInteger("Transport", dia); list.addCompound(nbttagcompound); } - compound.setList("TransportData", list); + compound.setTagList("TransportData", list); } public boolean hasTransport(int id) { diff --git a/core/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java b/core/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java index 34ea95f8b..639144345 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java +++ b/core/src/main/java/noppes/npcs/controllers/data/ProfileOptions.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.IProfileOptions; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; import noppes.npcs.constants.EnumProfileSync; @@ -11,7 +11,7 @@ public class ProfileOptions implements IProfileOptions { public EnumProfileSync cooldownControl = EnumProfileSync.Individual; public EnumProfileSync completeControl = EnumProfileSync.Individual; - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { // Party Management enableOptions = compound.getBoolean("EnableProfiles"); if (enableOptions) { @@ -30,8 +30,8 @@ public class ProfileOptions implements IProfileOptions { } } - public INBTCompound writeToNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeToNBT() { + INbt compound = NBT.compound(); compound.setBoolean("EnableProfiles", enableOptions); if (enableOptions) { compound.setInteger("CooldownControl", cooldownControl.ordinal()); diff --git a/core/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java b/core/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java index ab99060a1..5e293e559 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java +++ b/core/src/main/java/noppes/npcs/controllers/data/SkinOverlay.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.ISkinOverlay; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; public class SkinOverlay implements ISkinOverlay { private Runnable onChanged; @@ -139,7 +139,7 @@ public class SkinOverlay implements ISkinOverlay { return offsetZ; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { this.texture = compound.getString("SkinOverlayTexture"); this.glow = compound.getBoolean("SkinOverlayGlow"); this.blend = compound.getBoolean("SkinOverlayBlend"); @@ -159,7 +159,7 @@ public class SkinOverlay implements ISkinOverlay { this.offsetZ = compound.getFloat("SkinOverlayOffsetZ"); } - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { compound.setString("SkinOverlayTexture", this.getTexture()); compound.setBoolean("SkinOverlayGlow", this.getGlow()); compound.setBoolean("SkinOverlayBlend", this.getBlend()); diff --git a/core/src/main/java/noppes/npcs/controllers/data/Tag.java b/core/src/main/java/noppes/npcs/controllers/data/Tag.java index b862f7494..1c0da132c 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/Tag.java +++ b/core/src/main/java/noppes/npcs/controllers/data/Tag.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.ITag; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import java.util.UUID; @@ -34,7 +34,7 @@ public class Tag implements ITag { return name.substring(0, 1).toUpperCase() + name.substring(1); } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { name = compound.getString("Name"); color = compound.getInteger("Color"); id = compound.getInteger("Slot"); @@ -42,7 +42,7 @@ public class Tag implements ITag { uuid = UUID.fromString(compound.getString("Uuid")); } - public void writeNBT(INBTCompound compound) { + public void writeNBT(INbt compound) { compound.setInteger("Slot", id); compound.setString("Name", name); compound.setInteger("Color", color); @@ -50,12 +50,12 @@ public class Tag implements ITag { compound.setBoolean("HideTag", hideTag); } - public void readShortNBT(INBTCompound compound) { + public void readShortNBT(INbt compound) { name = compound.getString("Name"); uuid = UUID.fromString(compound.getString("Uuid")); } - public void writeShortNBT(INBTCompound compound) { + public void writeShortNBT(INbt compound) { compound.setString("Name", name); compound.setString("Uuid", uuid.toString()); } diff --git a/core/src/main/java/noppes/npcs/controllers/data/TagMap.java b/core/src/main/java/noppes/npcs/controllers/data/TagMap.java index 70249a24e..c915eec99 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/TagMap.java +++ b/core/src/main/java/noppes/npcs/controllers/data/TagMap.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.ArrayList; @@ -28,16 +28,16 @@ public class TagMap { this.tagMap = new HashMap>(); } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { this.tagMap = new HashMap>(); - INBTList list = compound.getList("TagMap", 10); + INbtList list = compound.getTagList("TagMap", 10); if (list != null) { for (int i = 0; i < list.size(); i++) { - INBTCompound nbttagcompound = list.getCompound(i); + INbt nbttagcompound = list.getCompound(i); String cloneName = nbttagcompound.getString("Clone"); HashSet uuids = new HashSet(); - INBTList nbtTagList = nbttagcompound.getList("TagUUIDs", 8); + INbtList nbtTagList = nbttagcompound.getTagList("TagUUIDs", 8); for (int j = 0; j < nbtTagList.size(); j++) { String uuid = nbtTagList.getString(j); if (!uuid.isEmpty()) { @@ -49,23 +49,23 @@ public class TagMap { } } - public INBTCompound writeNBT() { - INBTCompound nbt = NBT.compound(); - INBTList cloneList = NBT.list(); + public INbt writeNBT() { + INbt nbt = NBT.compound(); + INbtList cloneList = NBT.list(); for (String key : tagMap.keySet()) { HashSet uuidSet = tagMap.get(key); if (uuidSet.size() > 0) { - INBTCompound cloneCompound = NBT.compound(); + INbt cloneCompound = NBT.compound(); cloneCompound.setString("Clone", key); - INBTList nbtTagList = NBT.list(); + INbtList nbtTagList = NBT.list(); for (UUID uuid : uuidSet) { nbtTagList.addString(uuid.toString()); } - cloneCompound.setList("TagUUIDs", nbtTagList); + cloneCompound.setTagList("TagUUIDs", nbtTagList); cloneList.addCompound(cloneCompound); } } - nbt.setList("TagMap", cloneList); + nbt.setTagList("TagMap", cloneList); return nbt; } diff --git a/core/src/main/java/noppes/npcs/controllers/data/TintData.java b/core/src/main/java/noppes/npcs/controllers/data/TintData.java index 5534bf7c8..c72dd164d 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/TintData.java +++ b/core/src/main/java/noppes/npcs/controllers/data/TintData.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.entity.data.ITintData; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; public class TintData implements ITintData { private boolean tintEnabled = false; @@ -11,7 +11,7 @@ public class TintData implements ITintData { private int generalTint = 0x000000; private int generalAlpha = 40; - public INBTCompound writeToNBT(INBTCompound nbttagcompound) { + public INbt writeToNBT(INbt nbttagcompound) { nbttagcompound.setBoolean("TintEnabled", tintEnabled); if (tintEnabled) { nbttagcompound.setBoolean("HurtTintEnabled", hurtTintEnabled); @@ -23,7 +23,7 @@ public class TintData implements ITintData { return nbttagcompound; } - public void readFromNBT(INBTCompound nbttagcompound) { + public void readFromNBT(INbt nbttagcompound) { tintEnabled = nbttagcompound.getBoolean("TintEnabled"); if (tintEnabled) { hurtTintEnabled = nbttagcompound.getBoolean("HurtTintEnabled"); diff --git a/core/src/main/java/noppes/npcs/controllers/data/TraderStock.java b/core/src/main/java/noppes/npcs/controllers/data/TraderStock.java index 730a5533f..922de856d 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/TraderStock.java +++ b/core/src/main/java/noppes/npcs/controllers/data/TraderStock.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers.data; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import noppes.npcs.constants.EnumStockReset; @@ -266,7 +266,7 @@ public class TraderStock { // ==================== NBT Serialization ==================== - public INBTCompound writeToNBT(INBTCompound compound) { + public INbt writeToNBT(INbt compound) { compound.setBoolean("EnableStock", enableStock); compound.setBoolean("PerPlayer", perPlayer); compound.setInteger("ResetType", resetType.ordinal()); @@ -276,19 +276,19 @@ public class TraderStock { compound.setLong("LastResetTime", lastResetTime); // Save per-player stock - INBTList playerList = NBT.list(); + INbtList playerList = NBT.list(); for (Map.Entry entry : playerStock.entrySet()) { - INBTCompound playerTag = NBT.compound(); + INbt playerTag = NBT.compound(); playerTag.setString("Player", entry.getKey()); entry.getValue().writeToNBT(playerTag); playerList.addCompound(playerTag); } - compound.setList("PlayerStock", playerList); + compound.setTagList("PlayerStock", playerList); return compound; } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { enableStock = compound.getBoolean("EnableStock"); perPlayer = compound.getBoolean("PerPlayer"); @@ -313,9 +313,9 @@ public class TraderStock { // Load per-player stock playerStock.clear(); - INBTList playerList = compound.getList("PlayerStock", 10); + INbtList playerList = compound.getTagList("PlayerStock", 10); for (int i = 0; i < playerList.size(); i++) { - INBTCompound playerTag = playerList.getCompound(i); + INbt playerTag = playerList.getCompound(i); String playerName = playerTag.getString("Player"); PlayerTraderStock pStock = new PlayerTraderStock(); pStock.readFromNBT(playerTag); @@ -348,11 +348,11 @@ public class TraderStock { return false; } - public void writeToNBT(INBTCompound compound) { + public void writeToNBT(INbt compound) { compound.setIntArray("Purchased", purchasedAmounts); } - public void readFromNBT(INBTCompound compound) { + public void readFromNBT(INbt compound) { int[] loaded = compound.getIntArray("Purchased"); if (loaded != null && loaded.length == 18) { purchasedAmounts = loaded; diff --git a/core/src/main/java/noppes/npcs/controllers/data/TransportCategory.java b/core/src/main/java/noppes/npcs/controllers/data/TransportCategory.java index 19b9705d4..28919524c 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/TransportCategory.java +++ b/core/src/main/java/noppes/npcs/controllers/data/TransportCategory.java @@ -2,8 +2,8 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.handler.data.ITransportCategory; import noppes.npcs.api.handler.data.ITransportLocation; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.core.NBT; import java.util.HashMap; @@ -27,11 +27,11 @@ public class TransportCategory implements ITransportCategory { return list; } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { id = compound.getInteger("CategoryId"); title = compound.getString("CategoryTitle"); - INBTList locs = compound.getList("CategoryLocations", 10); + INbtList locs = compound.getTagList("CategoryLocations", 10); if (locs == null || locs.size() == 0) return; @@ -43,14 +43,14 @@ public class TransportCategory implements ITransportCategory { } } - public void writeNBT(INBTCompound compound) { + public void writeNBT(INbt compound) { compound.setInteger("CategoryId", id); compound.setString("CategoryTitle", title); - INBTList locs = NBT.list(); + INbtList locs = NBT.list(); for (TransportLocation location : locations.values()) { locs.addCompound(location.writeNBT()); } - compound.setList("CategoryLocations", locs); + compound.setTagList("CategoryLocations", locs); } public int getId() { diff --git a/core/src/main/java/noppes/npcs/controllers/data/TransportLocation.java b/core/src/main/java/noppes/npcs/controllers/data/TransportLocation.java index 7cec188a0..00d5f4693 100644 --- a/core/src/main/java/noppes/npcs/controllers/data/TransportLocation.java +++ b/core/src/main/java/noppes/npcs/controllers/data/TransportLocation.java @@ -2,7 +2,7 @@ package noppes.npcs.controllers.data; import noppes.npcs.api.IPos; import noppes.npcs.api.handler.data.ITransportLocation; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.core.NBT; public class TransportLocation implements ITransportLocation { @@ -23,7 +23,7 @@ public class TransportLocation implements ITransportLocation { this.saveHandler = saveHandler; } - public void readNBT(INBTCompound compound) { + public void readNBT(INbt compound) { if (compound == null) return; id = compound.getInteger("Id"); @@ -35,8 +35,8 @@ public class TransportLocation implements ITransportLocation { name = compound.getString("Name"); } - public INBTCompound writeNBT() { - INBTCompound compound = NBT.compound(); + public INbt writeNBT() { + INbt compound = NBT.compound(); compound.setInteger("Id", id); compound.setDouble("PosX", posX); compound.setDouble("PosY", posY); diff --git a/core/src/main/java/noppes/npcs/core/NBT.java b/core/src/main/java/noppes/npcs/core/NBT.java index 15c3b5f01..445346660 100644 --- a/core/src/main/java/noppes/npcs/core/NBT.java +++ b/core/src/main/java/noppes/npcs/core/NBT.java @@ -1,8 +1,8 @@ package noppes.npcs.core; -import noppes.npcs.platform.PlatformServiceHolder; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import kamkeel.npcs.platform.PlatformServiceHolder; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; /** * Convenience factory for creating NBT objects in CORE code. @@ -15,14 +15,14 @@ public final class NBT { /** * Creates a new, empty NBT compound. */ - public static INBTCompound compound() { + public static INbt compound() { return PlatformServiceHolder.get().nbt().createCompound(); } /** * Creates a new, empty NBT list. */ - public static INBTList list() { + public static INbtList list() { return PlatformServiceHolder.get().nbt().createList(); } } diff --git a/core/src/main/java/noppes/npcs/core/package-info.java b/core/src/main/java/noppes/npcs/core/package-info.java index e75ebad6a..8c62ddb9f 100644 --- a/core/src/main/java/noppes/npcs/core/package-info.java +++ b/core/src/main/java/noppes/npcs/core/package-info.java @@ -7,6 +7,6 @@ * Rules: * - NO imports from net.minecraft.*, cpw.mods.*, net.minecraftforge.*, org.spongepowered.* * - Only java.*, javax.*, noppes.npcs.core.*, noppes.npcs.platform.*, kamkeel.npcs.core.* - * - All MC-specific behavior is accessed through noppes.npcs.platform.PlatformServiceHolder + * - All MC-specific behavior is accessed through kamkeel.npcs.platform.PlatformServiceHolder */ package noppes.npcs.core; diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/PlatformService.java b/platform-api/src/main/java/kamkeel/npcs/platform/PlatformService.java new file mode 100644 index 000000000..8b6097aee --- /dev/null +++ b/platform-api/src/main/java/kamkeel/npcs/platform/PlatformService.java @@ -0,0 +1,96 @@ +package kamkeel.npcs.platform; + +import noppes.npcs.api.IDamageSource; +import noppes.npcs.api.INbt; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntity; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.item.IItemStack; +import noppes.npcs.platform.nbt.NBTFactory; + +import java.io.File; +import java.io.IOException; + +/** + * Central platform abstraction that bridges CORE logic with MC-version-specific code. + * + * Each mc* module (mc1710, mc1122, mc1165, mc1201) provides an implementation + * that is registered during mod initialization via {@link PlatformServiceHolder#set(PlatformService)}. + * + * CORE code accesses this via {@link PlatformServiceHolder#get()}. + */ +public interface PlatformService { + + // --- NBT --- + + NBTFactory nbt(); + + // --- NBT I/O --- + + INbt readCompressedNBT(File file) throws IOException; + + void writeCompressedNBT(INbt compound, File file) throws IOException; + + // --- Paths --- + + File getWorldSaveDirectory(); + + File getWorldSaveDirectory(String subdir); + + File getConfigDirectory(); + + // --- Environment --- + + boolean isPhysicalClient(); + + String getModVersion(); + + // --- Logging --- + + void logInfo(String message); + + void logWarn(String message); + + void logError(String message); + + void logError(String message, Throwable t); + + void logDebug(String message); + + // --- Entity Wrapping --- + + /** + * Wraps a raw MC player entity. + */ + IPlayer wrapPlayer(Object mcPlayer); + + /** + * Wraps a raw MC entity. + */ + IEntity wrapEntity(Object mcEntity); + + /** + * Wraps a raw MC living entity. + */ + IEntityLivingBase wrapLiving(Object mcLiving); + + /** + * Wraps a raw MC item stack. + */ + IItemStack wrapStack(Object mcStack); + + /** + * Wraps a raw MC world. + */ + IWorld wrapWorld(Object mcWorld); + + /** + * Wraps a raw MC damage source. + */ + IDamageSource wrapDamageSource(Object mcSource); + + // --- Scheduling --- + + void runOnMainThread(Runnable task); +} diff --git a/platform-api/src/main/java/noppes/npcs/platform/PlatformServiceHolder.java b/platform-api/src/main/java/kamkeel/npcs/platform/PlatformServiceHolder.java similarity index 97% rename from platform-api/src/main/java/noppes/npcs/platform/PlatformServiceHolder.java rename to platform-api/src/main/java/kamkeel/npcs/platform/PlatformServiceHolder.java index c1a5a5c8c..a40a96c10 100644 --- a/platform-api/src/main/java/noppes/npcs/platform/PlatformServiceHolder.java +++ b/platform-api/src/main/java/kamkeel/npcs/platform/PlatformServiceHolder.java @@ -1,4 +1,4 @@ -package noppes.npcs.platform; +package kamkeel.npcs.platform; /** * Static accessor for the active {@link PlatformService} implementation. diff --git a/platform-api/src/main/java/noppes/npcs/platform/config/IConfigProvider.java b/platform-api/src/main/java/kamkeel/npcs/platform/config/IConfigProvider.java similarity index 96% rename from platform-api/src/main/java/noppes/npcs/platform/config/IConfigProvider.java rename to platform-api/src/main/java/kamkeel/npcs/platform/config/IConfigProvider.java index 305b987b8..ddfaa0b0a 100644 --- a/platform-api/src/main/java/noppes/npcs/platform/config/IConfigProvider.java +++ b/platform-api/src/main/java/kamkeel/npcs/platform/config/IConfigProvider.java @@ -1,4 +1,4 @@ -package noppes.npcs.platform.config; +package kamkeel.npcs.platform.config; /** * Version-independent abstraction over Minecraft Forge's Configuration system. diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IDamage.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/IDamage.java deleted file mode 100644 index a2a463598..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IDamage.java +++ /dev/null @@ -1,25 +0,0 @@ -package kamkeel.npcs.platform.entity; - -/** - * Platform-independent damage source abstraction. - */ -public interface IDamage { - - /** - * @return the damage type identifier (e.g., "player", "mob", "generic") - */ - String getType(); - - /** - * @return the entity that caused this damage, or null if none (e.g., fall damage) - */ - IMob getSourceEntity(); - - /** - * Returns the underlying MC DamageSource object. - * Core code should NEVER call this. - * - * @return the raw MC DamageSource - */ - Object getHandle(); -} diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IGameWorld.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/IGameWorld.java deleted file mode 100644 index bcd0f63e5..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IGameWorld.java +++ /dev/null @@ -1,33 +0,0 @@ -package kamkeel.npcs.platform.entity; - -/** - * Platform-independent world abstraction. - */ -public interface IGameWorld { - - /** - * @return the dimension ID (e.g., 0 for overworld, -1 for nether) - */ - int getDimensionId(); - - /** - * @return true if this is a client-side world - */ - boolean isClient(); - - /** - * Look up an entity by its numeric ID. - * - * @param id the entity ID - * @return the entity, or null if not found - */ - IMob getEntityById(int id); - - /** - * Returns the underlying MC World object. - * Core code should NEVER call this. - * - * @return the raw MC World - */ - Object getHandle(); -} diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/ILiving.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/ILiving.java deleted file mode 100644 index df41e0266..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/ILiving.java +++ /dev/null @@ -1,22 +0,0 @@ -package kamkeel.npcs.platform.entity; - -/** - * Platform-independent living entity abstraction. - * Extends {@link IMob} with health and damage operations. - */ -public interface ILiving extends IMob { - - float getHealth(); - - void setHealth(float hp); - - float getMaxHealth(); - - /** - * Deal damage to this entity. - * - * @param amount the damage amount - * @param source the damage source, or null for generic damage - */ - void damage(float amount, IDamage source); -} diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IMob.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/IMob.java deleted file mode 100644 index 07e4d3fab..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IMob.java +++ /dev/null @@ -1,58 +0,0 @@ -package kamkeel.npcs.platform.entity; - -/** - * Platform-independent entity abstraction for core logic. - * Thin interface — only exposes what core actually needs. - * - * Each MC version provides an implementation wrapping the native Entity class. - * Use {@link #getHandle()} to retrieve the underlying MC object in platform code. - */ -public interface IMob { - - /** - * @return the entity's numeric ID in the world - */ - int getEntityId(); - - /** - * @return the entity's UUID as a string - */ - String getUniqueID(); - - // --- Position --- - - double getX(); - - double getY(); - - double getZ(); - - float getYaw(); - - float getPitch(); - - void setPosition(double x, double y, double z); - - // --- State --- - - /** - * @return true if the entity exists and is not dead - */ - boolean isAlive(); - - /** - * @return the dimension/world the entity is in - */ - IGameWorld getWorld(); - - // --- Escape hatch --- - - /** - * Returns the underlying MC entity object. - * Platform code can cast this to the version-specific Entity class. - * Core code should NEVER call this. - * - * @return the raw MC entity (e.g., net.minecraft.entity.Entity on 1.7.10) - */ - Object getHandle(); -} diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IStack.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/IStack.java deleted file mode 100644 index a12b9adde..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IStack.java +++ /dev/null @@ -1,50 +0,0 @@ -package kamkeel.npcs.platform.entity; - -import noppes.npcs.platform.nbt.INBTCompound; - -/** - * Platform-independent item stack abstraction. - */ -public interface IStack { - - /** - * @return the item's registry ID (e.g., "minecraft:stone") - */ - String getItemId(); - - int getCount(); - - void setCount(int count); - - /** - * @return the item's damage/metadata value - */ - int getDamage(); - - void setDamage(int dmg); - - /** - * @return the stack's NBT tag compound, or null if none - */ - INBTCompound getTag(); - - void setTag(INBTCompound tag); - - /** - * @return true if this stack is empty (null item or count <= 0) - */ - boolean isEmpty(); - - /** - * @return a deep copy of this stack - */ - IStack copy(); - - /** - * Returns the underlying MC ItemStack object. - * Core code should NEVER call this. - * - * @return the raw MC ItemStack - */ - Object getHandle(); -} diff --git a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IUser.java b/platform-api/src/main/java/kamkeel/npcs/platform/entity/IUser.java deleted file mode 100644 index 74cb60251..000000000 --- a/platform-api/src/main/java/kamkeel/npcs/platform/entity/IUser.java +++ /dev/null @@ -1,36 +0,0 @@ -package kamkeel.npcs.platform.entity; - -/** - * Platform-independent player abstraction. - * Extends {@link ILiving} with player-specific operations. - */ -public interface IUser extends ILiving { - - /** - * @return the player's username - */ - String getName(); - - /** - * @return the player's UUID as a string - */ - @Override - String getUniqueID(); - - /** - * @return true if the player is a server operator - */ - boolean isOp(); - - /** - * Send a chat message to this player. - * - * @param text plain text message - */ - void sendMessage(String text); - - /** - * @return the item currently held in the player's main hand, or null if empty - */ - IStack getHeldItem(); -} diff --git a/platform-api/src/main/java/noppes/npcs/api/IDamageSource.java b/platform-api/src/main/java/noppes/npcs/api/IDamageSource.java new file mode 100644 index 000000000..cf955c285 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/IDamageSource.java @@ -0,0 +1,25 @@ +package noppes.npcs.api; + +import noppes.npcs.api.entity.IEntity; + +/** + * Platform-api version (MC-free). The src/api shadow adds typed getMCDamageSource(). + */ +public interface IDamageSource { + + String getType(); + + boolean isUnblockable(); + + boolean isProjectile(); + + IEntity getTrueSource(); + + IEntity getImmediateSource(); + + /** + * Returns the underlying MC DamageSource object. + * Expert use only. Returns Object in platform-api; shadow narrows to DamageSource. + */ + Object getMCDamageSource(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/INbt.java b/platform-api/src/main/java/noppes/npcs/api/INbt.java new file mode 100644 index 000000000..a87fdf703 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/INbt.java @@ -0,0 +1,218 @@ +package noppes.npcs.api; + +import java.util.Set; + +/** + * Unified NBT compound interface — used by both CORE logic and scripting. + * + * Platform-api version (MC-free). The src/api shadow adds typed MC methods + * (e.g., {@code NBTTagCompound getMCNBT()}). + * + *

Compound tags contain uniquely-keyed tags of various types: + *

+ * 1: Byte    2: Short   3: Int      4: Long
+ * 5: Float   6: Double  7: Byte[]   8: String
+ * 9: List   10: Compound 11: Int[]
+ * 
+ */ +public interface INbt { + + // ======================== Setters ======================== + + void setString(String key, String value); + + void setInteger(String key, int value); + + void setBoolean(String key, boolean value); + + void setDouble(String key, double value); + + void setFloat(String key, float value); + + void setLong(String key, long value); + + void setShort(String key, short value); + + void setByte(String key, byte value); + + void setByteArray(String key, byte[] value); + + void setIntArray(String key, int[] value); + + /** + * Alias for {@link #setIntArray(String, int[])}. + */ + default void setIntegerArray(String key, int[] value) { + setIntArray(key, value); + } + + void setCompound(String key, INbt compound); + + /** + * Alias for {@link #setCompound(String, INbt)}. + */ + default void setTag(String key, INbt compound) { + setCompound(key, compound); + } + + /** + * Sets a list from an Object array. Elements can be: INbt, String, Double, Float, Integer, int[]. + */ + void setList(String key, Object[] value); + + /** + * Sets a typed tag list on this compound. + */ + void setTagList(String key, INbtList list); + + // ======================== Getters ======================== + + String getString(String key); + + int getInteger(String key); + + boolean getBoolean(String key); + + double getDouble(String key); + + float getFloat(String key); + + long getLong(String key); + + short getShort(String key); + + byte getByte(String key); + + byte[] getByteArray(String key); + + int[] getIntArray(String key); + + /** + * Alias for {@link #getIntArray(String)}. + */ + default int[] getIntegerArray(String key) { + return getIntArray(key); + } + + INbt getCompound(String key); + + /** + * Returns a tag list as an Object array. Elements are typed based on list type: + * INbt (compounds), String, Double, Float, Integer, int[]. + */ + Object[] getList(String key, int type); + + /** + * Gets a typed tag list from this compound. + * + * @param key the key + * @param type the element type ID (e.g. 10 for compounds, 8 for strings) + * @return the list, or an empty list if the key doesn't exist + */ + INbtList getTagList(String key, int type); + + /** + * Returns the type of the list tag with the given key. + * + * @return the element type ID, or 0 if not a list tag + */ + int getListType(String key); + + // ======================== Query ======================== + + /** + * @return true if this compound has a tag with the given key + */ + boolean hasKey(String key); + + /** + * Alias for {@link #hasKey(String)}. + */ + default boolean has(String key) { + return hasKey(key); + } + + /** + * Checks if this compound has a key of a specific NBT type. + */ + boolean hasKey(String key, int type); + + /** + * @return a set of all keys in this compound + */ + Set getKeySet(); + + /** + * @return all keys as a String array + */ + default String[] getKeys() { + return getKeySet().toArray(new String[0]); + } + + /** + * Removes the tag with the given key. + */ + void removeTag(String key); + + /** + * Alias for {@link #removeTag(String)}. + */ + default void remove(String key) { + removeTag(key); + } + + /** + * Returns the NBT type ID for the tag with the given key. + * + * @return the type ID, or 0 if not present + */ + int getTagType(String key); + + /** + * Alias for {@link #getTagType(String)}. + */ + default int getType(String key) { + return getTagType(key); + } + + /** + * @return true if this compound has no keys + */ + boolean isEmpty(); + + // ======================== Interop ======================== + + /** + * Merges all tags from the given compound into this one. + */ + void merge(INbt other); + + /** + * Creates a deep copy of this compound. + */ + INbt copy(); + + /** + * Returns the underlying MC NBT object. + * Returns Object in platform-api; the src/api shadow narrows to the MC type. + * CORE code should NEVER call this — only mc* modules should. + */ + Object getMCNBT(); + + // ======================== Convenience ======================== + + /** + * @return a JSON string representation of this compound + */ + String toJsonString(); + + /** + * @return true if this compound has the same data as the given compound + */ + boolean isEqual(INbt nbt); + + /** + * Removes all tags from this compound. + */ + void clear(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/INbtList.java b/platform-api/src/main/java/noppes/npcs/api/INbtList.java new file mode 100644 index 000000000..38e8e28d2 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/INbtList.java @@ -0,0 +1,46 @@ +package noppes.npcs.api; + +/** + * Version-independent abstraction over Minecraft's NBT list tag. + * + * Platform-api version (MC-free). The src/api shadow may add MC-typed methods. + */ +public interface INbtList { + + int size(); + + INbt getCompound(int index); + + String getString(int index); + + int getInt(int index); + + double getDouble(int index); + + float getFloat(int index); + + int[] getIntArray(int index); + + /** + * @return the NBT type ID of elements in this list, or 0 if empty + */ + int getElementType(); + + // --- Mutators --- + + void addCompound(INbt compound); + + void addString(String value); + + void addInt(int value); + + void addDouble(double value); + + void remove(int index); + + /** + * Returns the underlying MC NBT list object. + * CORE code should NEVER call this — only mc* modules should. + */ + Object getMCTagList(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/IWorld.java b/platform-api/src/main/java/noppes/npcs/api/IWorld.java new file mode 100644 index 000000000..8b322e003 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/IWorld.java @@ -0,0 +1,338 @@ +package noppes.npcs.api; + +import noppes.npcs.api.entity.IEntity; +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.item.IItemStack; + +public interface IWorld { + /** + * @return The worlds time + */ + long getTime(); + + /** + * @return The total world time + */ + long getTotalTime(); + + boolean areAllPlayersAsleep(); + + boolean isBlockFreezable(IPos pos); + + boolean isBlockFreezable(int x, int y, int z); + + boolean isBlockFreezableNaturally(IPos pos); + + boolean isBlockFreezableNaturally(int x, int y, int z); + + boolean canBlockFreeze(IPos pos, boolean adjacentToWater); + + boolean canBlockFreeze(int x, int y, int z, boolean adjacentToWater); + + boolean canBlockFreezeBody(IPos pos, boolean adjacentToWater); + + boolean canBlockFreezeBody(int x, int y, int z, boolean adjacentToWater); + + boolean canSnowAt(IPos pos, boolean checkLight); + + boolean canSnowAt(int x, int y, int z, boolean checkLight); + + boolean canSnowAtBody(IPos pos, boolean checkLight); + + boolean canSnowAtBody(int x, int y, int z, boolean checkLight); + + /** + * @param x X coordinate + * @param z Z coordinate + * @return The Y-value of the world at this x & z value based on the height map of the world. + */ + int getHeightValue(int x, int z); + + int getHeightValue(IPos pos); + + /** + * @param x X coordinate + * @param z Z coordinate + * @return The minimum Y-value of the world at this x & z value based on the height map of the world. + */ + int getChunkHeightMapMinimum(int x, int z); + + int getChunkHeightMapMinimum(IPos pos); + + /** + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return The metadata of the block at this position. + */ + int getBlockMetadata(int x, int y, int z); + + int getBlockMetadata(IPos pos); + + boolean setBlockMetadataWithNotify(int x, int y, int z, int metadata, int flag); + + boolean setBlockMetadataWithNotify(IPos pos, int metadata, int flag); + + /** + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return can the block at this position see the sky or are there no blocks above this one + */ + boolean canSeeSky(int x, int y, int z); + + /** + * @param pos the block position + * @return can the block at this position see the sky or are there no blocks above this one + */ + boolean canSeeSky(IPos pos); + + int getFullBlockLightValue(int x, int y, int z); + + int getFullBlockLightValue(IPos pos); + + int getBlockLightValue(int x, int y, int z); + + int getBlockLightValue(IPos pos); + + void playSoundAtEntity(IEntity entity, String sound, float volume, float pitch); + + void playSoundToNearExcept(IPlayer player, String sound, float volume, float pitch); + + IEntity getEntityByID(int id); + + boolean spawnEntityInWorld(IEntity entity); + + IPlayer getClosestPlayerToEntity(IEntity entity, double range); + + IPlayer getClosestPlayer(double x, double y, double z, double range); + + IPlayer getClosestPlayer(IPos pos, double range); + + IPlayer getClosestVulnerablePlayerToEntity(IEntity entity, double range); + + IPlayer getClosestVulnerablePlayer(double x, double y, double z, double range); + + IPlayer getClosestVulnerablePlayer(IPos pos, double range); + + /** + * + * @param entity The entity whose type will be used as a parameter + * @return The amount of entities of the given type in the world. + */ + int countEntities(IEntity entity); + + IEntity[] getLoadedEntities(); + + IEntity[] getEntitiesNear(IPos position, double range); + + IEntity[] getEntitiesNear(double x, double y, double z, double range); + + /** + * @param x X coordinate + * @param y Y coordinate + * @param z Z coordinate + * @return True if the block at this position is of cubic shape. (Not a stair, slab, etc.) + */ + boolean isBlockFullCube(int x, int y, int z); + + boolean isBlockFullCube(IPos pos); + + long getSeed(); + + void setSpawnLocation(int x, int y, int z); + + void setSpawnLocation(IPos pos); + + boolean canLightningStrikeAt(int x, int y, int z); + + boolean canLightningStrikeAt(IPos pos); + + boolean isBlockHighHumidity(int x, int y, int z); + + boolean isBlockHighHumidity(IPos pos); + + /** + * @param x World position x + * @param y World position y + * @param z World position z + * @return Text from signs + * @since 1.7.10d + */ + String getSignText(int x, int y, int z); + + String getSignText(IPos pos); + + boolean isPlaceCancelled(int posX, int posY, int posZ); + + boolean isPlaceCancelled(IPos pos); + + boolean isBreakCancelled(int posX, int posY, int posZ); + + boolean isBreakCancelled(IPos pos); + + IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IPos rayCastPos(double[] startPos, double[] lookVector, int maxDistance); + + IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IPos rayCastPos(IPos startPos, IPos lookVector, int maxDistance); + + /** + * @param startPos the start position as [x, y, z] + * @param maxHeight maximum search height + * @return the position of the closest block of air to startPos + */ + IPos getNearestAir(IPos startPos, int maxHeight); + + IEntity[] rayCastEntities(double[] startPos, double[] lookVector, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IEntity[] rayCastEntities(IEntity[] ignoreEntities, double[] startPos, double[] lookVector, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IEntity[] rayCastEntities(double[] startPos, double[] lookVector, int maxDistance, double offset, double range); + + IEntity[] rayCastEntities(IPos startPos, IPos lookVector, int maxDistance, double offset, double range); + + /** + * @param name The name of the player to be returned + * @return The Player with name. Null is returned when the player isnt found + */ + IPlayer getPlayer(String name); + + IPlayer getPlayerByUUID(String uuid); + + /** + * @param time The world time to be set + */ + void setTime(long time); + + /** + * @return Whether or not its daytime + */ + boolean isDay(); + + /** + * @return Whether or not its currently raining + */ + boolean isRaining(); + + /** + * @param bo Set if it's raining + */ + void setRaining(boolean bo); + + /** + * @param x The x position + * @param y The y position + * @param z The z position + */ + void thunderStrike(double x, double y, double z); + + void thunderStrike(IPos pos); + + /** + * @param id The items name + * @param damage The damage value + * @param size The number of items in the item + * @return Returns the item + */ + IItemStack createItem(String id, int damage, int size); + + @Deprecated + Object getTempData(String key); + + @Deprecated + void setTempData(String key, Object value); + + @Deprecated + boolean hasTempData(String key); + + @Deprecated + void removeTempData(String key); + + @Deprecated + void clearTempData(); + + @Deprecated + String[] getTempDataKeys(); + + @Deprecated + Object getStoredData(String key); + + @Deprecated + void setStoredData(String key, Object value); + + @Deprecated + boolean hasStoredData(String key); + + @Deprecated + void removeStoredData(String key); + + @Deprecated + void clearStoredData(); + + String[] getStoredDataKeys(); + + /** + * @param x Position x + * @param y Position y + * @param z Position z + * @param range Range of the explosion + * @param fire Whether or not the explosion does fire damage + * @param grief Whether or not the explosion does damage to blocks + */ + void explode(double x, double y, double z, float range, boolean fire, boolean grief); + + void explode(IPos pos, float range, boolean fire, boolean grief); + + IPlayer[] getAllServerPlayers(); + + String[] getPlayerNames(); + + /** + * @param x Position x + * @param z Position z + * @return Returns the name of the biome + * @since 1.7.10c + */ + String getBiomeName(int x, int z); + + String getBiomeName(IPos pos); + + /** + * Lets you spawn a server side cloned entity + * + * @param x The x position the clone will be spawned at + * @param y The y position the clone will be spawned at + * @param z The z position the clone will be spawned at + * @param tab The tab in which the clone is + * @param name Name of the cloned entity + * @param ignoreProtection Whether the spawning of this clone skips protection checks. + * @return Returns the entity which was spawned + */ + IEntity spawnClone(int x, int y, int z, int tab, String name, boolean ignoreProtection); + + IEntity spawnClone(IPos pos, int tab, String name, boolean ignoreProtection); + + IEntity spawnClone(int x, int y, int z, int tab, String name); + + IEntity spawnClone(IPos pos, int tab, String name); + + /** + * @return Returns minecraft world object + * @since 1.7.10c + * Expert use only + */ + Object getMCWorld(); + + /** + * + * @return The ID of this world's dimension. 0 for overworld, 1 for End, -1 for Nether, etc. + */ + int getDimensionID(); + + void broadcast(String message); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/IAnimatable.java b/platform-api/src/main/java/noppes/npcs/api/entity/IAnimatable.java new file mode 100644 index 000000000..9d7fbc912 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/IAnimatable.java @@ -0,0 +1,8 @@ +package noppes.npcs.api.entity; + +import noppes.npcs.api.handler.data.IAnimationData; + +public interface IAnimatable { + + IAnimationData getAnimationData(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/ICustomNpc.java b/platform-api/src/main/java/noppes/npcs/api/entity/ICustomNpc.java new file mode 100644 index 000000000..5ebd4ea6e --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/ICustomNpc.java @@ -0,0 +1,1968 @@ +package noppes.npcs.api.entity; + +import noppes.npcs.api.INbt; +import noppes.npcs.api.IPos; +import noppes.npcs.api.entity.data.IHitboxData; +import noppes.npcs.api.entity.data.ITintData; +import noppes.npcs.api.handler.data.IAnimationData; +import noppes.npcs.api.handler.data.ILines; +import noppes.npcs.api.handler.data.IMagicData; +import noppes.npcs.api.item.IItemStack; + +/** + * Represents a customizable NPC with a wide variety of properties such as appearance, + * behavior, combat, loot, and more. This interface extends living entity and animation + * capabilities and defines methods for adjusting almost every aspect of an NPC. + */ +public interface ICustomNpc extends IEntityLiving, IAnimatable { + + /** + * Returns the underlying Minecraft entity object. + * + * @return the MC entity as a generic Object. + */ + Object getMCEntity(); + + /** + * Returns the current NPC's size (scale factor) within the range 1–30. + * + * @return the NPC's size. + */ + int getSize(); + + /** + * Sets the NPC's size (scale factor). + * + * @param size the size of the NPC (range 1–30, default is 5). + */ + void setSize(int size); + + /** + * Returns the NPC's model type. + * + * @return the model type. + */ + int getModelType(); + + /** + * Sets the NPC's model type. + * + * @param modelType the model type (0: Steve, 1: Steve64, 2: Alex). + */ + void setModelType(int modelType); + + /** + * Returns the NPC's name. + * + * @return the NPC's name. + */ + String getName(); + + /** + * Sets the NPC's rotation (yaw). + * + * @param rotation the new rotation angle in degrees. + */ + void setRotation(float rotation); + + /** + * Sets the NPC's rotation type. + * + * @param rotationType the rotation type (implementation-specific). + */ + void setRotationType(int rotationType); + + /** + * Returns the NPC's rotation type. + * + * @return the rotation type. + */ + int getRotationType(); + + /** + * Sets the moving type of the NPC. + * + * @param movingType the moving type (0: standing, 1: wandering, 2: moving path). + */ + void setMovingType(int movingType); + + /** + * Returns the moving type of the NPC. + * + * @return the moving type (0: standing, 1: wandering, 2: moving path). + */ + int getMovingType(); + + /** + * Sets the NPC's name. + * + * @param name the new name. + */ + void setName(String name); + + /** + * Returns the NPC's title. + * + * @return the NPC's title. + */ + String getTitle(); + + /** + * Sets the NPC's title. + * + * @param title the new title. + */ + void setTitle(String title); + + /** + * Returns the NPC's texture path. + * + * @return the texture path. + */ + String getTexture(); + + /** + * Sets the NPC's texture. + * + * @param texture the new texture path. + */ + void setTexture(String texture); + + /** + * Returns the NPC's home position. + * + * @return the home position as an IPos. + */ + IPos getHome(); + + /** + * Returns the home position X coordinate. + * + * @return the home X coordinate. + */ + int getHomeX(); + + /** + * Sets the home position X coordinate. + * + * @param x the new home X coordinate. + */ + void setHomeX(int x); + + /** + * Returns the home position Y coordinate. + * + * @return the home Y coordinate. + */ + int getHomeY(); + + /** + * Sets the home position Y coordinate. + * + * @param y the new home Y coordinate. + */ + void setHomeY(int y); + + /** + * Returns the home position Z coordinate. + * + * @return the home Z coordinate. + */ + int getHomeZ(); + + /** + * Sets the home position Z coordinate. + * + * @param z the new home Z coordinate. + */ + void setHomeZ(int z); + + /** + * Sets the home position using individual coordinates. + * + * @param x the home X coordinate. + * @param y the home Y coordinate. + * @param z the home Z coordinate. + */ + void setHome(int x, int y, int z); + + /** + * Sets the home position using an IPos instance. + * + * @param pos the new home position. + */ + void setHome(IPos pos); + + /** + * Sets the NPC's maximum health. + * + * @param health the new maximum health. + */ + void setMaxHealth(double health); + + /** + * Sets whether the NPC should return to its home position. + * + * @param bo true to enable returning home, false otherwise. + */ + void setReturnToHome(boolean bo); + + /** + * Returns whether the NPC is set to return home. + * + * @return true if the NPC returns home, false otherwise. + */ + boolean getReturnToHome(); + + /** + * Sets the NPC's faction by its ID. + * + * @param id the faction ID. + */ + void setFaction(int id); + + /** + * Sets whether the NPC will attack members of other factions. + * + * @param attackOtherFactions true to attack, false otherwise. + */ + void setAttackFactions(boolean attackOtherFactions); + + /** + * Returns whether the NPC attacks other factions. + * + * @return true if it attacks, false otherwise. + */ + boolean getAttackFactions(); + + /** + * Sets whether the NPC should defend members of its faction. + * + * @param defendFaction true to defend, false otherwise. + */ + void setDefendFaction(boolean defendFaction); + + /** + * Returns whether the NPC defends its faction. + * + * @return true if it defends, false otherwise. + */ + boolean getDefendFaction(); + + /** + * Returns the entity type of the NPC. + * + * @return the NPC's type. + */ + int getType(); + + /** + * Checks if the NPC is of the given type. + * + * @param type the type to check. + * @return true if the NPC matches the specified type; otherwise, defers to the parent. + */ + boolean typeOf(int type); + + /** + * Instructs the NPC to shoot an item at a target. + * + * @param target the target entity. + * @param item the item to shoot. + * @param accuracy the accuracy of the shot (0–100). + */ + void shootItem(IEntityLivingBase target, IItemStack item, int accuracy); + + /** + * Sets whether projectiles fired by the NPC should ignore terrain collisions. + * + * @param b true if projectiles keep terrain, false otherwise. + */ + void setProjectilesKeepTerrain(boolean b); + + /** + * Returns whether projectiles fired by the NPC ignore terrain collisions. + * + * @return true if they ignore terrain, false otherwise. + */ + boolean getProjectilesKeepTerrain(); + + /** + * Sets whether the NPC has projectile invincibility frames. + * + * @param invincible true to enable projectile invincibility, false to disable. + */ + void setProjectileInvincibility(boolean invincible); + + /** + * Returns whether the NPC has projectile invincibility frames. + * + * @return true if projectile invincibility is enabled, false otherwise. + */ + boolean getProjectileInvincibility(); + + /** + * Makes the NPC broadcast a message. + * + * @param message the message to say. + */ + void say(String message); + + /** + * Makes the NPC send a message to a specific player. + * + * @param player the target player. + * @param message the message to say. + */ + void say(IPlayer player, String message); + + /** + * Returns the dialog ID in the specified slot. + * + * @param slot the dialog slot. + * @return the dialog ID, or -1 if none exists. + */ + int getDialogId(int slot); + + /** + * Sets the dialog for the specified slot by its ID. + * + * @param slot the dialog slot. + * @param dialogId the dialog ID. + */ + void setDialog(int slot, int dialogId); + + /** + * Returns the lines used for NPC interaction. + * + * @return the interact lines. + */ + ILines getInteractLines(); + + /** + * Returns the lines displayed in the world. + * + * @return the world lines. + */ + ILines getWorldLines(); + + /** + * Returns the lines spoken when the NPC attacks. + * + * @return the attack lines. + */ + ILines getAttackLines(); + + /** + * Returns the lines spoken when the NPC is killed. + * + * @return the killed lines. + */ + ILines getKilledLines(); + + /** + * Returns the lines spoken when the NPC kills another entity. + * + * @return the kill lines. + */ + ILines getKillLines(); + + /** + * Returns whether NPC dialog lines are played in order. + * + * @return true if lines are ordered, false if random. + */ + boolean getOrderedLines(); + + /** + * Sets whether NPC dialog lines are played in order. + * + * @param ordered true for ordered, false for random. + */ + void setOrderedLines(boolean ordered); + + /** + * Returns the NPC's idle sound resource path. + * + * @return the idle sound path, or empty string if none. + */ + String getIdleSound(); + + /** + * Sets the NPC's idle sound resource path. + * + * @param sound the idle sound path. + */ + void setIdleSound(String sound); + + /** + * Returns the NPC's angry/aggro sound resource path. + * + * @return the angry sound path, or empty string if none. + */ + String getAngrySound(); + + /** + * Sets the NPC's angry/aggro sound resource path. + * + * @param sound the angry sound path. + */ + void setAngrySound(String sound); + + /** + * Returns the NPC's hurt sound resource path. + * + * @return the hurt sound path. + */ + String getHurtSound(); + + /** + * Sets the NPC's hurt sound resource path. + * + * @param sound the hurt sound path. + */ + void setHurtSound(String sound); + + /** + * Returns the NPC's death sound resource path. + * + * @return the death sound path. + */ + String getDeathSound(); + + /** + * Sets the NPC's death sound resource path. + * + * @param sound the death sound path. + */ + void setDeathSound(String sound); + + /** + * Returns the NPC's step/footstep sound resource path. + * + * @return the step sound path, or empty string if none. + */ + String getStepSound(); + + /** + * Sets the NPC's step/footstep sound resource path. + * + * @param sound the step sound path. + */ + void setStepSound(String sound); + + /** + * Returns whether pitch variation is disabled for NPC sounds. + * + * @return true if pitch is disabled (fixed pitch), false otherwise. + */ + boolean getDisablePitch(); + + /** + * Sets whether pitch variation is disabled for NPC sounds. + * + * @param disablePitch true to disable pitch variation, false to allow. + */ + void setDisablePitch(boolean disablePitch); + + /** + * Kills the NPC without despawning it. + */ + void kill(); + + /** + * Resets the NPC to its initial state and triggers the initialization script. + */ + void reset(); + + /** + * Returns the NPC's animation data. + * + * @return the animation data. + */ + IAnimationData getAnimationData(); + + /** + * Sets the NPC's role by its ID. + * + * @param role the role ID. + */ + void setRole(int role); + + /** + * Sets the NPC's job by its ID. + * + * @param job the job ID. + */ + void setJob(int job); + + /** + * Returns the item held in the NPC's right hand. + * + * @return the right-hand item. + */ + IItemStack getRightItem(); + + /** + * Sets the item held in the NPC's right hand. + * + * @param item the new item. + */ + void setRightItem(IItemStack item); + + /** + * (Deprecated) Returns the item held in the NPC's left hand. + * + * @return the left-hand item. + */ + @Deprecated + IItemStack getLefttItem(); + + /** + * Returns the item held in the NPC's left hand. + * + * @return the left-hand item. + */ + IItemStack getLeftItem(); + + /** + * Sets the item held in the NPC's left hand. + * + * @param item the new item. + */ + void setLeftItem(IItemStack item); + + /** + * Returns the projectile item used by the NPC. + * + * @return the projectile item. + */ + IItemStack getProjectileItem(); + + /** + * Sets the projectile item for the NPC. + * + * @param item the new projectile item. + */ + void setProjectileItem(IItemStack item); + + /** + * Checks if the NPC can aim while shooting. + * + * @return true if aiming while shooting is enabled, false otherwise. + */ + @Deprecated + boolean canAimWhileShooting(); + + /** + * Sets whether the NPC can aim while shooting. + * + * @param aimWhileShooting true to enable aiming, false to disable. + */ + @Deprecated + void aimWhileShooting(boolean aimWhileShooting); + + /** + * Sets the Aim Type for an NPC + * + * @param aimWhileShooting 0: No, 1: Yes, 2: On Shot + */ + void setAimType(byte aimWhileShooting); + + /** + * Gets the Aim Type for an NPC + * + * @return 0: No, 1: Yes, 2: On Shot + */ + byte getAimType(); + + /** + * Sets the minimum delay (in ticks) between projectiles. + * + * @param minDelay the minimum delay. + */ + void setMinProjectileDelay(int minDelay); + + /** + * Returns the minimum projectile delay. + * + * @return the minimum delay in ticks. + */ + int getMinProjectileDelay(); + + /** + * Sets the maximum delay (in ticks) between projectiles. + * + * @param maxDelay the maximum delay. + */ + void setMaxProjectileDelay(int maxDelay); + + /** + * Returns the maximum projectile delay. + * + * @return the maximum delay in ticks. + */ + int getMaxProjectileDelay(); + + /** + * Sets the range for ranged attacks. + * + * @param rangedRange the ranged attack range. + */ + void setRangedRange(int rangedRange); + + /** + * Returns the range for ranged attacks. + * + * @return the ranged attack range. + */ + int getRangedRange(); + + /** + * Sets the fire rate for ranged attacks. + * + * @param rate the fire rate in ticks. + */ + void setFireRate(int rate); + + /** + * Returns the fire rate for ranged attacks. + * + * @return the fire rate. + */ + int getFireRate(); + + /** + * Sets the number of shots in a burst. + * + * @param burstCount the burst count. + */ + void setBurstCount(int burstCount); + + /** + * Returns the number of shots in a burst. + * + * @return the burst count. + */ + int getBurstCount(); + + /** + * Sets the number of shots fired. + * + * @param shotCount the shot count. + */ + void setShotCount(int shotCount); + + /** + * Returns the number of shots fired. + * + * @return the shot count. + */ + int getShotCount(); + + /** + * Sets the shooting accuracy. + * + * @param accuracy the accuracy (0–100). + */ + void setAccuracy(int accuracy); + + /** + * Returns the shooting accuracy. + * + * @return the accuracy value. + */ + int getAccuracy(); + + /** + * Returns the sound directory played when a projectile is fired. + * + * @return the fire sound directory. + */ + String getFireSound(); + + /** + * Sets the sound directory for projectile firing. + * + * @param fireSound the new fire sound directory. + */ + void setFireSound(String fireSound); + + /** + * Returns the armor item in the specified slot. + * + * @param slot the armor slot (0: head, 1: body, 2: legs, 3: boots). + * @return the armor item. + */ + IItemStack getArmor(int slot); + + /** + * Sets the armor item in the specified slot. + * + * @param slot the armor slot (0: head, 1: body, 2: legs, 3: boots). + * @param item the armor item. + */ + void setArmor(int slot, IItemStack item); + + /** + * Returns the loot item from the NPC's drop list for the given slot. + * + * @param slot the loot slot (0–8). + * @return the loot item. + */ + IItemStack getLootItem(int slot); + + /** + * Sets the loot item in the NPC's drop list for the given slot. + * + * @param slot the loot slot (0–8). + * @param item the new loot item. + */ + void setLootItem(int slot, IItemStack item); + + /** + * Returns the chance for the loot item in the specified slot to drop. + * + * @param slot the loot slot (0–8). + * @return the drop chance (default 100 if not set). + */ + double getLootChance(int slot); + + /** + * Sets the drop chance for the loot item in the specified slot. + * + * @param slot the loot slot (0–8). + * @param chance the new drop chance. + */ + void setLootChance(int slot, double chance); + + /** + * Returns the NPC's loot mode. + * + * @return the loot mode (0: Normal, 1: Auto Pickup). + */ + int getLootMode(); + + /** + * Sets the NPC's loot mode. + * + * @param lootMode the loot mode (0: Normal, 1: Auto Pickup). + */ + void setLootMode(int lootMode); + + /** + * Sets the minimum XP dropped by the NPC. + * + * @param lootXP the minimum loot XP. + */ + void setMinLootXP(int lootXP); + + /** + * Sets the maximum XP dropped by the NPC. + * + * @param lootXP the maximum loot XP. + */ + void setMaxLootXP(int lootXP); + + /** + * Returns the minimum XP dropped by the NPC. + * + * @return the minimum loot XP. + */ + int getMinLootXP(); + + /** + * Returns the maximum XP dropped by the NPC. + * + * @return the maximum loot XP. + */ + int getMaxLootXP(); + + /** + * Returns whether the NPC can drown. + * + * @return true if the NPC can drown, false otherwise. + */ + boolean getCanDrown(); + + /** + * Sets whether the NPC can drown. + * Shorthand: sets drowning type to 1 (drowns in water) if true, 0 (never drowns) if false. + * + * @param canDrown true to allow drowning, false to prevent. + */ + void setCanDrown(boolean canDrown); + + /** + * Sets the drowning behavior of the NPC. + * + * @param type 0: Never drowns, 1: Drowns in water, 2: Drowns in air (without water). + */ + void setDrowningType(int type); + + /** + * Returns whether the NPC can breathe. + * + * @return true if the NPC can breathe, false otherwise. + */ + boolean canBreathe(); + + /** + * Sets the NPC's animation type. + * + * @param type the animation type. + */ + void setAnimation(int type); + + /** + * Sets the NPC's tactical variant. + * + * @param variant the tactical variant (0: Rush, 1: Dodge, 2: Surround, 3: Hit N Run, 4: Ambush, 5: Stalk, 6: None). + */ + void setTacticalVariant(int variant); + + /** + * Returns the NPC's tactical variant. + * + * @return the tactical variant as an integer. + */ + int getTacticalVariant(); + + /** + * Sets the NPC's tactical variant by its name. + * + * @param variant the name of the tactical variant. + */ + void setTacticalVariant(String variant); + + /** + * Returns the name of the NPC's tactical variant. + * + * @return the tactical variant name. + */ + String getTacticalVariantName(); + + /** + * Returns the name of the NPC's combat policy. + * + * @return the combat policy name. + */ + String getCombatPolicyName(); + + /** + * Sets the NPC's combat policy. + * + * @param policy the combat policy (0: Flip, 1: Brute, 2: Stubborn, 4: Tactical). + */ + void setCombatPolicy(int policy); + + /** + * Returns the NPC's combat policy. + * + * @return the combat policy as an integer. + */ + int getCombatPolicy(); + + /** + * Sets the NPC's combat policy by name. + * + * @param policy the combat policy name. + */ + void setCombatPolicy(String policy); + + /** + * Sets the tactical radius affecting NPC behavior. + * + * @param tacticalRadius the tactical radius. + */ + void setTacticalRadius(int tacticalRadius); + + /** + * Returns the tactical radius affecting NPC behavior. + * + * @return the tactical radius. + */ + int getTacticalRadius(); + + /** + * Returns the tactical behavior chance (1 in N). + * + * @return the tactical chance. + */ + int getTacticalChance(); + + /** + * Sets the tactical behavior chance (1 in N). + * + * @param chance the tactical chance. + */ + void setTacticalChance(int chance); + + /** + * Returns whether the NPC can swim. + * + * @return true if the NPC can swim, false otherwise. + */ + boolean getCanSwim(); + + /** + * Sets whether the NPC can swim. + * + * @param canSwim true to enable swimming, false to disable. + */ + void setCanSwim(boolean canSwim); + + /** + * Returns whether the NPC reacts to fire. + * + * @return true if the NPC reacts to fire, false otherwise. + */ + boolean getReactsToFire(); + + /** + * Sets whether the NPC reacts to fire. + * + * @param reactsToFire true to react, false otherwise. + */ + void setReactsToFire(boolean reactsToFire); + + /** + * Returns whether the NPC avoids water. + * + * @return true if the NPC avoids water, false otherwise. + */ + boolean getAvoidsWater(); + + /** + * Sets whether the NPC avoids water. + * + * @param avoidsWater true to avoid water, false otherwise. + */ + void setAvoidsWater(boolean avoidsWater); + + /** + * Returns whether the NPC avoids sunlight. + * + * @return true if the NPC avoids the sun, false otherwise. + */ + boolean getAvoidsSun(); + + /** + * Sets whether the NPC avoids sunlight. + * + * @param avoidsSun true to avoid sunlight, false otherwise. + */ + void setAvoidsSun(boolean avoidsSun); + + /** + * Returns whether the NPC requires direct line-of-sight to attack. + * + * @return true if direct LOS is required, false otherwise. + */ + boolean getDirectLOS(); + + /** + * Sets whether the NPC requires direct line-of-sight to attack. + * + * @param directLOS true to require LOS, false otherwise. + */ + void setDirectLOS(boolean directLOS); + + /** + * Returns the NPC's leap attack type. + * + * @return the leap type. + */ + int getLeapType(); + + /** + * Sets the NPC's leap attack type. + * + * @param leapType the leap type. + */ + void setLeapType(int leapType); + + /** + * Returns whether the NPC can sprint. + * + * @return true if sprinting is enabled, false otherwise. + */ + boolean getCanSprint(); + + /** + * Sets whether the NPC can sprint. + * + * @param canSprint true to enable sprinting, false to disable. + */ + void setCanSprint(boolean canSprint); + + /** + * Returns whether the NPC stops moving to interact with players. + * + * @return true if the NPC stops to interact, false otherwise. + */ + boolean getStopAndInteract(); + + /** + * Sets whether the NPC stops moving to interact with players. + * + * @param stopAndInteract true to stop and interact, false otherwise. + */ + void setStopAndInteract(boolean stopAndInteract); + + /** + * Returns the NPC's door interaction behavior. + * + * @return the door interaction mode (0: Break, 1: Open, 2: Disabled). + */ + int getDoorInteract(); + + /** + * Sets the NPC's door interaction behavior. + * + * @param doorInteract the door interaction mode (0: Break, 1: Open, 2: Disabled). + */ + void setDoorInteract(int doorInteract); + + /** + * Returns the NPC's walking range (wander radius). + * + * @return the walking range. + */ + int getWalkingRange(); + + /** + * Sets the NPC's walking range (wander radius). + * + * @param range the walking range. + */ + void setWalkingRange(int range); + + /** + * Returns whether the NPC interacts with other NPCs. + * + * @return true if NPC interaction is enabled, false otherwise. + */ + boolean getNpcInteracting(); + + /** + * Sets whether the NPC interacts with other NPCs. + * + * @param npcInteracting true to enable, false to disable. + */ + void setNpcInteracting(boolean npcInteracting); + + /** + * Returns whether the NPC pauses at path points. + * + * @return true if the NPC pauses at path points, false otherwise. + */ + boolean getMovingPause(); + + /** + * Sets whether the NPC pauses at path points. + * + * @param movingPause true to pause, false otherwise. + */ + void setMovingPause(boolean movingPause); + + /** + * Returns the NPC's path movement pattern. + * + * @return the moving pattern (0: Looping, 1: Backtracking). + */ + int getMovingPattern(); + + /** + * Sets the NPC's path movement pattern. + * + * @param pattern the moving pattern (0: Looping, 1: Backtracking). + */ + void setMovingPattern(int pattern); + + /** + * Returns whether the NPC fires indirect (arcing) projectiles. + * + * @return the indirect fire mode. + */ + int getCanFireIndirect(); + + /** + * Sets whether the NPC fires indirect (arcing) projectiles. + * + * @param canFireIndirect the indirect fire mode. + */ + void setCanFireIndirect(int canFireIndirect); + + /** + * Returns the NPC's use-range-melee mode. + * + * @return the use-range-melee mode. + */ + int getUseRangeMelee(); + + /** + * Sets the NPC's use-range-melee mode. + * + * @param useRangeMelee the use-range-melee mode. + */ + void setUseRangeMelee(int useRangeMelee); + + /** + * Returns the distance at which the NPC switches from ranged to melee. + * + * @return the distance to melee. + */ + int getDistanceToMelee(); + + /** + * Sets the distance at which the NPC switches from ranged to melee. + * + * @param distance the distance to melee. + */ + void setDistanceToMelee(int distance); + + /** + * Returns the NPC's body X offset. + * + * @return the body X offset. + */ + float getBodyOffsetX(); + + /** + * Sets the NPC's body X offset. + * + * @param offsetX the body X offset. + */ + void setBodyOffsetX(float offsetX); + + /** + * Returns the NPC's body Y offset. + * + * @return the body Y offset. + */ + float getBodyOffsetY(); + + /** + * Sets the NPC's body Y offset. + * + * @param offsetY the body Y offset. + */ + void setBodyOffsetY(float offsetY); + + /** + * Returns the NPC's body Z offset. + * + * @return the body Z offset. + */ + float getBodyOffsetZ(); + + /** + * Sets the NPC's body Z offset. + * + * @param offsetZ the body Z offset. + */ + void setBodyOffsetZ(float offsetZ); + + /** + * Sets whether the NPC ignores cobwebs. + * + * @param ignore true to ignore cobwebs, false otherwise. + */ + void setIgnoreCobweb(boolean ignore); + + /** + * Returns whether the NPC ignores cobwebs. + * + * @return true if cobwebs are ignored, false otherwise. + */ + boolean getIgnoreCobweb(); + + /** + * Sets the NPC's behavior when encountering an enemy. + * + * @param onAttack 0: Retaliate, 1: Panic, 2: Retreat, 3: Nothing. + */ + void setOnFoundEnemy(int onAttack); + + /** + * Returns the NPC's behavior when encountering an enemy. + * + * @return an integer representing the behavior (0: Retaliate, 1: Panic, 2: Retreat, 3: Nothing). + */ + int onFoundEnemy(); + + /** + * Sets the condition under which the NPC seeks shelter. + * + * @param shelterFrom 0: Darkness, 1: Sunlight, 2: Disabled. + */ + void setShelterFrom(int shelterFrom); + + /** + * Returns the condition under which the NPC seeks shelter. + * + * @return an integer representing the shelter condition (0: Darkness, 1: Sunlight, 2: Disabled). + */ + int getShelterFrom(); + + /** + * Returns whether the NPC has a living animation. + * + * @return true if living animation is enabled, false otherwise. + */ + boolean hasLivingAnimation(); + + /** + * Sets whether the NPC has a living animation. + * + * @param livingAnimation true to enable living animation, false to disable. + */ + void setLivingAnimation(boolean livingAnimation); + + /** + * Sets the visibility type of the NPC. + * + * @param type the visibility type (0: visible, 1: invisible, 2: semi-visible). + */ + void setVisibleType(int type); + + /** + * Returns the visibility type of the NPC. + * + * @return the visibility type. + */ + int getVisibleType(); + + /** + * Sets whether the NPC is visible to a specific player. + * + * @param player the player. + * @param visible true if the NPC should be visible, false if invisible. + */ + void setVisibleTo(IPlayer player, boolean visible); + + /** + * Checks if the NPC is visible to a specific player. + * + * @param player the player. + * @return true if the NPC is visible, false otherwise. + */ + boolean isVisibleTo(IPlayer player); + + /** + * Sets the visibility type of the NPC's name. + * + * @param type the visibility type (0: visible, 1: invisible, 2: when attacking). + */ + void setShowName(int type); + + /** + * Returns the visibility type of the NPC's name. + * + * @return the name visibility type. + */ + int getShowName(); + + /** + * Returns the visibility type of the NPC's boss bar. + * + * @return the boss bar visibility (0: invisible, 1: visible, 2: when attacking). + */ + int getShowBossBar(); + + /** + * Sets the visibility type of the NPC's boss bar. + * + * @param type the boss bar visibility (0: invisible, 1: visible, 2: when attacking). + */ + void setShowBossBar(int type); + + /** + * Returns the melee strength of the NPC. + * + * @return the melee strength. + */ + double getMeleeStrength(); + + /** + * Sets the melee strength of the NPC. + * + * @param strength the new melee strength. + */ + void setMeleeStrength(double strength); + + /** + * Returns the melee speed of the NPC. + * + * @return the melee speed. + */ + int getMeleeSpeed(); + + /** + * Sets the melee speed of the NPC. + * + * @param speed the new melee speed. + */ + void setMeleeSpeed(int speed); + + /** + * Returns the melee range of the NPC. + * + * @return the melee range. + */ + int getMeleeRange(); + + /** + * Sets the melee range of the NPC. + * + * @param range the new melee range. + */ + void setMeleeRange(int range); + + /** + * Returns the swing warmup time (in ticks) before melee damage is applied. + * + * @return the swing warmup time. + */ + int getSwingWarmup(); + + /** + * Sets the swing warmup time (in ticks) before melee damage is applied. + * + * @param ticks the warmup time. + */ + void setSwingWarmup(int ticks); + + /** + * Returns the knockback strength of the NPC. + * + * @return the knockback strength. + */ + int getKnockback(); + + /** + * Sets the knockback strength of the NPC. + * + * @param knockback the new knockback strength. + */ + void setKnockback(int knockback); + + /** + * Returns the aggro range of the NPC. + * + * @return the aggro range. + */ + int getAggroRange(); + + /** + * Sets the aggro range of the NPC. + * + * @param aggroRange the new aggro range. + */ + void setAggroRange(int aggroRange); + + /** + * Returns the ranged attack strength of the NPC. + * + * @return the ranged strength. + */ + float getRangedStrength(); + + /** + * Sets the ranged attack strength of the NPC. + * + * @param strength the new ranged strength. + */ + void setRangedStrength(float strength); + + /** + * Returns the ranged attack speed of the NPC. + * + * @return the ranged speed. + */ + int getRangedSpeed(); + + /** + * Sets the ranged attack speed of the NPC. + * + * @param speed the new ranged speed. + */ + void setRangedSpeed(int speed); + + /** + * Returns the number of projectiles in a ranged burst attack. + * + * @return the burst count. + */ + int getRangedBurst(); + + /** + * Sets the number of projectiles in a ranged burst attack. + * + * @param count the new burst count. + */ + void setRangedBurst(int count); + + /** + * Returns the number of ticks before the NPC respawns. + * + * @return the respawn time. + */ + int getRespawnTime(); + + /** + * Sets the number of ticks before the NPC respawns. + * + * @param time the respawn time. + */ + void setRespawnTime(int time); + + /** + * Returns the NPC's respawn cycle. + * + * @return the respawn cycle (0: Always, 1: Day, 2: Night, 3: No respawn). + */ + int getRespawnCycle(); + + /** + * Sets the NPC's respawn cycle. + * + * @param cycle the respawn cycle (0: Always, 1: Day, 2: Night, 3: No respawn). + */ + void setRespawnCycle(int cycle); + + /** + * Returns whether the NPC's body is hidden upon death. + * + * @return true if the body is hidden, false otherwise. + */ + boolean getHideKilledBody(); + + /** + * Sets whether the NPC's body should be hidden upon death. + * + * @param hide true to hide the body, false otherwise. + */ + void hideKilledBody(boolean hide); + + /** + * Returns whether the NPC naturally despawns. + * + * @return true if it naturally despawns, false otherwise. + */ + boolean naturallyDespawns(); + + /** + * Sets whether the NPC should naturally despawn. + * + * @param canDespawn true to allow natural despawning, false otherwise. + */ + void setNaturallyDespawns(boolean canDespawn); + + /** + * Returns whether the NPC was spawned using a soul stone. + * + * @return true if spawned from a soul stone, false otherwise. + */ + boolean spawnedFromSoulStone(); + + /** + * Returns the name of the player who spawned this NPC using a soul stone. + * + * @return the player's name, or null if not spawned by soul stone. + */ + String getSoulStonePlayerName(); + + /** + * Returns whether the NPC has been initialized after a soul stone spawn. + * + * @return true if initialized, false otherwise. + */ + boolean isSoulStoneInit(); + + /** + * Returns whether the NPC refuses to be captured by a soul stone. + * + * @return true if it refuses, false otherwise. + */ + boolean getRefuseSoulStone(); + + /** + * Sets whether the NPC refuses to be captured by a soul stone. + * + * @param refuse true to refuse, false to allow. + */ + void setRefuseSoulStone(boolean refuse); + + /** + * Returns the minimum faction points required to capture the NPC with a soul stone. + * + * @return the minimum points (default -1 means use the faction's friendly points). + */ + int getMinPointsToSoulStone(); + + /** + * Sets the minimum faction points required to capture the NPC with a soul stone. + * + * @param points the minimum faction points. + */ + void setMinPointsToSoulStone(int points); + + /** + * Gives an item to the specified player. + * + * @param player the recipient. + * @param item the item to give. + */ + void giveItem(IPlayer player, IItemStack item); + + /** + * Executes a command as the NPC. + *

+ * Note: On servers the enable-command-block option must be set to true. + *

+ * + * @param command the command to execute. + */ + void executeCommand(String command); + + /** + * Returns the hitbox data associated with the NPC. + * + * @return the hitbox data. + */ + IHitboxData getHitboxData(); + + /** + * Returns the tint data associated with the NPC. + * + * @return the tint data. + */ + ITintData getTintData(); + + /** + * (Deprecated) Sets the head scale of the NPC. + * + * @param x scale factor along the X-axis. + * @param y scale factor along the Y-axis. + * @param z scale factor along the Z-axis. + */ + @Deprecated + void setHeadScale(float x, float y, float z); + + /** + * (Deprecated) Sets the body scale of the NPC. + * + * @param x scale factor along the X-axis. + * @param y scale factor along the Y-axis. + * @param z scale factor along the Z-axis. + */ + @Deprecated + void setBodyScale(float x, float y, float z); + + /** + * (Deprecated) Sets the arms scale of the NPC. + * + * @param x scale factor along the X-axis. + * @param y scale factor along the Y-axis. + * @param z scale factor along the Z-axis. + */ + @Deprecated + void setArmsScale(float x, float y, float z); + + /** + * (Deprecated) Sets the legs scale of the NPC. + * + * @param x scale factor along the X-axis. + * @param y scale factor along the Y-axis. + * @param z scale factor along the Z-axis. + */ + @Deprecated + void setLegsScale(float x, float y, float z); + + /** + * Sets the NPC's explosion resistance. + * + * @param resistance the resistance (0–2, default is 1). + */ + void setExplosionResistance(float resistance); + + /** + * Returns the NPC's explosion resistance. + * + * @return the explosion resistance. + */ + float getExplosionResistance(); + + /** + * Sets the NPC's melee resistance. + * + * @param resistance the resistance (0–2, default is 1). + */ + void setMeleeResistance(float resistance); + + /** + * Returns the NPC's melee resistance. + * + * @return the melee resistance. + */ + float getMeleeResistance(); + + /** + * Sets the NPC's arrow resistance. + * + * @param resistance the resistance (0–2, default is 1). + */ + void setArrowResistance(float resistance); + + /** + * Returns the NPC's arrow resistance. + * + * @return the arrow resistance. + */ + float getArrowResistance(); + + /** + * Sets the NPC's knockback resistance. + * + * @param resistance the resistance (0–2, default is 1). + */ + void setKnockbackResistance(double resistance); + + /** + * Returns the NPC's knockback resistance. + * + * @return the knockback resistance. + */ + double getKnockbackResistance(); + + /** + * Returns whether all damage to this NPC is disabled. + * + * @return true if damage is disabled, false otherwise. + */ + boolean getDamageDisabled(); + + /** + * Sets whether all damage to this NPC is disabled. + * + * @param disabled true to disable all damage, false otherwise. + */ + void setDamageDisabled(boolean disabled); + + /** + * Returns whether the NPC takes no fall damage. + * + * @return true if fall damage is disabled, false otherwise. + */ + boolean getNoFallDamage(); + + /** + * Sets whether the NPC takes no fall damage. + * + * @param noFallDamage true to disable fall damage, false to enable. + */ + void setNoFallDamage(boolean noFallDamage); + + /** + * Returns whether the NPC is immune to fire. + * + * @return true if immune to fire, false otherwise. + */ + boolean getImmuneToFire(); + + /** + * Sets whether the NPC is immune to fire. + * + * @param immuneToFire true to make immune, false otherwise. + */ + void setImmuneToFire(boolean immuneToFire); + + /** + * Returns whether the NPC is immune to potion effects. + * + * @return true if potion immune, false otherwise. + */ + boolean getPotionImmune(); + + /** + * Sets whether the NPC is immune to potion effects. + * + * @param potionImmune true to make immune, false otherwise. + */ + void setPotionImmune(boolean potionImmune); + + /** + * Returns whether the NPC burns in sunlight. + * + * @return true if the NPC burns in the sun, false otherwise. + */ + boolean getBurnInSun(); + + /** + * Sets whether the NPC burns in sunlight. + * + * @param burnInSun true to burn in sunlight, false otherwise. + */ + void setBurnInSun(boolean burnInSun); + + /** + * Returns whether the NPC can attack invisible targets. + * + * @return true if the NPC attacks invisible entities, false otherwise. + */ + boolean getAttackInvisible(); + + /** + * Sets whether the NPC can attack invisible targets. + * + * @param attackInvisible true to allow attacking invisible entities, false otherwise. + */ + void setAttackInvisible(boolean attackInvisible); + + /** + * Returns the NPC's creature type. + * + * @return the creature type ordinal (0: Undefined, 1: Undead, 2: Arthropod). + */ + int getCreatureType(); + + /** + * Sets the NPC's creature type. + * + * @param type the creature type ordinal (0: Undefined, 1: Undead, 2: Arthropod). + */ + void setCreatureType(int type); + + /** + * Sets the NPC's retaliation type. + * + * @param type the retaliation type (0: normal, 1: panic, 2: retreat, 3: nothing). + */ + void setRetaliateType(int type); + + /** + * Returns the NPC's combat health regeneration per second. + * + * @return the combat regen rate. + */ + float getCombatRegen(); + + /** + * Sets the NPC's combat health regeneration per second. + * + * @param regen the combat regen rate. + */ + void setCombatRegen(float regen); + + /** + * Returns the NPC's health regeneration per second when not in combat. + * + * @return the health regen rate. + */ + float getHealthRegen(); + + /** + * Sets the NPC's health regeneration per second when not in combat. + * + * @param regen the health regen rate. + */ + void setHealthRegen(float regen); + + /** + * Returns the age of the NPC in ticks. + * + * @return the age. + */ + long getAge(); + + /** + * Sets the NPC's flying ability. + * + * @param fly 1 to enable flying, 0 to disable. + */ + void setFly(int fly); + + /** + * Returns whether the NPC can fly. + * + * @return true if flying is enabled, false otherwise. + */ + boolean canFly(); + + /** + * Sets the NPC's flying speed. + * + * @param flySpeed the fly speed. + */ + void setFlySpeed(double flySpeed); + + /** + * Returns the NPC's flying speed. + * + * @param unused unused parameter. + * @return the fly speed. + */ + double getFlySpeed(double unused); + + /** + * Sets the gravity effect on the NPC while flying. + * + * @param flyGravity the fly gravity (0.0–1.0). + */ + void setFlyGravity(double flyGravity); + + /** + * Returns the gravity effect on the NPC while flying. + * + * @param unused unused parameter. + * @return the fly gravity. + */ + double getFlyGravity(double unused); + + /** + * Sets the maximum flying height for the NPC. + * + * @param flyHeightLimit the height limit. + */ + void setFlyHeightLimit(int flyHeightLimit); + + /** + * Returns the maximum flying height for the NPC. + * + * @param unused unused parameter. + * @return the fly height limit. + */ + int getFlyHeightLimit(int unused); + + /** + * Enables or disables flying height limitation. + * + * @param limit true to enable limitation, false to disable. + */ + void limitFlyHeight(boolean limit); + + /** + * Checks if flying height is limited. + * + * @param unused unused parameter. + * @return true if limited, false otherwise. + */ + boolean isFlyHeightLimited(boolean unused); + + /** + * Sets the NPC's walking speed. + * + * @param speed the walking speed. + */ + void setSpeed(double speed); + + /** + * Returns the NPC's walking speed. + * + * @return the walking speed. + */ + double getSpeed(); + + /** + * Sets the NPC's skin type. + * + * @param type the skin type. + */ + void setSkinType(byte type); + + /** + * Returns the NPC's skin type. + * + * @return the skin type. + */ + byte getSkinType(); + + /** + * Sets the NPC's skin URL. + * + * @param url the skin URL. + */ + void setSkinUrl(String url); + + /** + * Returns the NPC's skin URL. + * + * @return the skin URL. + */ + String getSkinUrl(); + + /** + * Sets the NPC's cloak texture. + * + * @param cloakTexture the cloak texture. + */ + void setCloakTexture(String cloakTexture); + + /** + * Returns the NPC's cloak texture. + * + * @return the cloak texture. + */ + String getCloakTexture(); + + /** + * Adds an overlay texture to the NPC. + * + * @param overlayTexture the overlay texture. + */ + void setOverlayTexture(String overlayTexture); + + /** + * Returns the first overlay texture of the NPC. + * + * @return the overlay texture, or an empty string if none. + */ + String getOverlayTexture(); + + /** + * Returns the NPC's glow texture path. + * + * @return the glow texture path, or empty string if none. + */ + String getGlowTexture(); + + /** + * Sets the NPC's glow texture path. + * + * @param texture the glow texture path. + */ + void setGlowTexture(String texture); + + /** + * Sets the NPC's collision type. + * + * @param type the collision type. + */ + void setCollisionType(int type); + + /** + * Returns the NPC's collision type. + * + * @return the collision type. + */ + int getCollisionType(); + + /** + * Updates the client with the latest NPC state. + */ + void updateClient(); + + /** + * Updates the NPC's AI tasks. + */ + void updateAI(); + + /** + * Returns the Magic Data of an NPC + * + * @return Magic data + */ + IMagicData getMagicData(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/IEntity.java b/platform-api/src/main/java/noppes/npcs/api/entity/IEntity.java new file mode 100644 index 000000000..e26b2f4ea --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/IEntity.java @@ -0,0 +1,596 @@ +package noppes.npcs.api.entity; + +import noppes.npcs.api.INbt; +import noppes.npcs.api.IPos; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.item.IItemStack; + +/** + * Represents a generic entity in the world. + * Provides methods to access or modify the entity's position, motion, temporary and persistent data, + * and to perform various actions (such as dropping items or changing dimensions). + */ +public interface IEntity { + + /** + * Returns the unique entity ID. + * + * @return the entity ID. + */ + int getEntityId(); + + /** + * Returns the unique UUID string of the entity. + * + * @return the unique ID. + */ + String getUniqueID(); + + /** + * Returns the vertical offset for rendering. + * + * @return the Y offset. + */ + double getYOffset(); + + /** + * @return The entity's width. + */ + double getWidth(); + + /** + * @return The entity's height. + */ + double getHeight(); + + /** + * @return The entity's x position. + */ + double getX(); + + /** + * Sets the entity's x position. + * + * @param x the new x position. + */ + void setX(double x); + + /** + * @return The entity's y position. + */ + double getY(); + + /** + * Sets the entity's y position. + * + * @param y the new y position. + */ + void setY(double y); + + /** + * @return The entity's z position. + */ + double getZ(); + + /** + * Sets the entity's z position. + * + * @param z the new z position. + */ + void setZ(double z); + + /** + * @return The entity's x motion. + */ + double getMotionX(); + + /** + * Sets the entity's x motion. + * + * @param x the new x motion. + */ + void setMotionX(double x); + + /** + * @return The entity's y motion. + */ + double getMotionY(); + + /** + * Sets the entity's y motion. + * + * @param y the new y motion. + */ + void setMotionY(double y); + + /** + * @return The entity's z motion. + */ + double getMotionZ(); + + /** + * Sets the entity's z motion. + * + * @param z the new z motion. + */ + void setMotionZ(double z); + + /** + * Convenience method to set the entity's motion in all three axes. + * + * @param x the x motion. + * @param y the y motion. + * @param z the z motion. + */ + void setMotion(double x, double y, double z); + + /** + * Sets the entity's motion based on the given position. + * + * @param pos the position containing motion components. + */ + void setMotion(IPos pos); + + /** + * Returns the entity's current motion as an IPos object. + * + * @return the motion vector. + */ + IPos getMotion(); + + /** + * @return Whether the entity is airborne. + */ + boolean isAirborne(); + + /** + * @return The block (integer) x position. + */ + int getBlockX(); + + /** + * @return The block (integer) y position. + */ + int getBlockY(); + + /** + * @return The block (integer) z position. + */ + int getBlockZ(); + + /** + * Sets the entity's position to the specified coordinates. + * + * @param x the x coordinate. + * @param y the y coordinate. + * @param z the z coordinate. + */ + void setPosition(double x, double y, double z); + + /** + * Sets the entity's position using an IPos object. + * + * @param pos the position object. + */ + void setPosition(IPos pos); + + /** + * Returns the entity's current position as an IPos object. + * + * @return the position. + */ + IPos getPosition(); + + /** + * @return The dimension ID the entity is in. + */ + int getDimension(); + + /** + * Moves the entity to the specified dimension. + * + * @param dimensionId the dimension ID. + */ + void setDimension(int dimensionId); + + /** + * @return Array of entities that are colliding with this entity + */ + IEntity[] getCollidingEntities(); + + /** + * Returns an array of entities within the specified range. + * + * @param range the search range. + * @return an array of surrounding entities. + */ + IEntity[] getSurroundingEntities(int range); + + /** + * Returns an array of entities of a specified type within the given range. + * + * @param range the search range. + * @param type the EntityType to find. + * @return an array of surrounding entities. + */ + IEntity[] getSurroundingEntities(int range, int type); + + /** + * @return Whether the entity is alive. + */ + boolean isAlive(); + + /** + * Returns temporary data stored under the given key. + * + * @param key the key. + * @return the temporary data. + */ + Object getTempData(String key); + + /** + * Stores temporary data that is cleared when the entity is unloaded. + * + * @param key the key. + * @param value the value. + */ + void setTempData(String key, Object value); + + /** + * Checks if temporary data for the given key exists. + * + * @param key the key. + * @return true if it exists; false otherwise. + */ + boolean hasTempData(String key); + + /** + * Removes the temporary data for the given key. + * + * @param key the key. + */ + void removeTempData(String key); + + /** + * Clears all temporary data. + */ + void clearTempData(); + + /** + * Returns an array of keys for temporary data. + * + * @return the keys. + */ + String[] getTempDataKeys(); + + /** + * Returns stored (persistent) data for the given key. + * + * @param key the key. + * @return the stored data. + */ + Object getStoredData(String key); + + /** + * Stores persistent data under the given key. + * Only Numbers and Strings are supported. + * + * @param key the key. + * @param value the value. + */ + void setStoredData(String key, Object value); + + /** + * Checks if stored data for the given key exists. + * + * @param key the key. + * @return true if it exists; false otherwise. + */ + boolean hasStoredData(String key); + + /** + * Removes the stored data for the given key. + * + * @param key the key. + */ + void removeStoredData(String key); + + /** + * Clears all stored data. + */ + void clearStoredData(); + + /** + * Returns an array of keys for stored data. + * + * @return the keys. + */ + String[] getStoredDataKeys(); + + /** + * @return The age of the entity in ticks. + */ + long getAge(); + + /** + * Permanently despawns the entity. + */ + void despawn(); + + /** + * @return Whether the entity is standing in water. + */ + boolean inWater(); + + /** + * @return Whether the entity is standing in lava. + */ + boolean inLava(); + + /** + * @return Whether the entity is standing in fire. + */ + boolean inFire(); + + /** + * @return Whether the entity is on fire. + */ + boolean isBurning(); + + /** + * Sets the entity on fire for the given number of ticks (20 ticks = 1 second). + * + * @param ticks the burn duration. + */ + void setBurning(int ticks); + + /** + * Extinguishes any fire on the entity. + */ + void extinguish(); + + /** + * @return The entity type name as registered in Minecraft. + */ + String getTypeName(); + + /** + * Causes the entity to drop the given item. + * + * @param item the item to drop. + */ + void dropItem(IItemStack item); + + /** + * @return The entity riding this entity. + */ + IEntity getRider(); + + /** + * Sets the given entity as the rider of this entity. + * + * @param entity the rider. + */ + void setRider(IEntity entity); + + /** + * @return The entity this entity is riding. + */ + IEntity getMount(); + + /** + * Sets the entity to be mounted by this entity. + * + * @param entity the mount. + */ + void setMount(IEntity entity); + + /** + * Returns the EntityType as defined in the scripting constants. + * + * @return the EntityType. + */ + int getType(); + + /** + * Checks whether the entity is of the specified EntityType. + * + * @param type the type to check. + * @return true if the entity is of that type; false otherwise. + */ + boolean typeOf(int type); + + /** + * Sets the entity's rotation (yaw) in degrees (0-360). + * + * @param rotation the rotation angle. + */ + void setRotation(float rotation); + + /** + * Sets both the rotation (yaw) and pitch of the entity. + * + * @param rotationYaw the yaw angle. + * @param rotationPitch the pitch angle. + */ + void setRotation(float rotationYaw, float rotationPitch); + + /** + * @return The current rotation (yaw) of the entity. + */ + float getRotation(); + + /** + * Sets the entity's pitch. + * + * @param pitch the pitch angle. + */ + void setPitch(float pitch); + + /** + * Returns the entity's pitch. + * + * @return the pitch angle. + */ + float getPitch(); + + /** + * Applies a knockback effect to the entity. + * + * @param power the strength of the knockback. + * @param direction the direction in degrees (usually based on getRotation()). + */ + void knockback(int power, float direction); + + /** + * Applies knockback using individual power components. + * + * @param xpower the x-axis power. + * @param ypower the y-axis power. + * @param zpower the z-axis power. + * @param direction the direction in degrees. + */ + void knockback(double xpower, double ypower, double zpower, float direction); + + /** + * Applies knockback using a position vector. + * + * @param pos the position vector. + * @param direction the direction in degrees. + */ + void knockback(IPos pos, float direction); + + /** + * Sets the entity's immunity time (hurt resistance). + * + * @param ticks the number of ticks. + */ + void setImmune(int ticks); + + /** + * Sets the entity's invisibility. + * + * @param invisible true to make invisible. + */ + void setInvisible(boolean invisible); + + /** + * Sets whether the entity is sneaking. + * + * @param sneaking true to enable sneaking. + */ + void setSneaking(boolean sneaking); + + /** + * Sets whether the entity is sprinting. + * + * @param sprinting true to enable sprinting. + */ + void setSprinting(boolean sprinting); + + /** + * @return Whether the entity has collided with something. + */ + boolean hasCollided(); + + /** + * @return Whether the entity has collided vertically. + */ + boolean hasCollidedVertically(); + + /** + * @return Whether the entity has collided horizontally. + */ + boolean hasCollidedHorizontally(); + + /** + * @return Whether the entity is capturing drops. + */ + boolean capturesDrops(); + + /** + * Sets whether the entity captures drops. + * + * @param capture true to capture drops. + */ + void setCapturesDrops(boolean capture); + + /** + * Sets the captured drops for this entity. + * + * @param capturedDrops an array of captured drops. + */ + void setCapturedDrops(IEntity[] capturedDrops); + + /** + * Returns the captured drops. + * + * @return an array of captured drops. + */ + IEntity[] getCapturedDrops(); + + /** + * @return Whether the entity is sneaking. + * @since 1.7.10c + */ + boolean isSneaking(); + + /** + * @return Whether the entity is sprinting. + * @since 1.7.10c + */ + boolean isSprinting(); + + /** + * Expert users only. + * + * @return The underlying Minecraft entity. + */ + Object getMCEntity(); + + /** + * Returns the entity's NBT data. + * + * @return the NBT data. + */ + INbt getNbt(); + + /** + * Returns all NBT data for the entity. + * + * @return the complete NBT data. + */ + INbt getAllNbt(); + + /** + * Applies the given NBT data to the entity. + * + * @param nbt the NBT data. + */ + void setNbt(INbt nbt); + + /** + * Returns optional NBT data if available. + * + * @return the optional NBT data, or null if none. + */ + INbt getNbtOptional(); + + /** + * Stores the entity as a clone with the given tab and name. + * + * @param tab the tab index. + * @param name the name for the clone. + */ + void storeAsClone(int tab, String name); + + /** + * @return The world this entity exists in. + */ + IWorld getWorld(); + + /** + * Updates the entity's state. + */ + void updateEntity(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLiving.java b/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLiving.java new file mode 100644 index 000000000..338634cd6 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLiving.java @@ -0,0 +1,54 @@ +package noppes.npcs.api.entity; + +/** + * Platform-api version (MC-free). The src/api shadow adds generic type parameter. + * All methods are clean — no MC types needed. + */ +public interface IEntityLiving extends IEntityLivingBase { + + boolean isNavigating(); + + void clearNavigation(); + + void navigateTo(double x, double y, double z, double speed); + + Object getMCEntity(); + + void playLivingSound(); + + void spawnExplosionParticle(); + + void setMoveForward(float speed); + + void faceEntity(IEntity entity, float pitch, float yaw); + + boolean canPickUpLoot(); + + void setCanPickUpLoot(boolean pickUp); + + boolean isPersistent(); + + void enablePersistence(); + + void setCustomNameTag(String text); + + String getCustomNameTag(); + + boolean hasCustomNameTag(); + + void setAlwaysRenderNameTag(boolean alwaysRender); + + boolean getAlwaysRenderNameTag(); + + void clearLeashed(boolean sendPacket, boolean dropLeash); + + boolean allowLeashing(); + + boolean getLeashed(); + + IEntity getLeashedTo(); + + void setLeashedTo(IEntity entity, boolean sendPacket); + + boolean canBeSteered(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLivingBase.java b/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLivingBase.java new file mode 100644 index 000000000..b5e2af9f0 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/IEntityLivingBase.java @@ -0,0 +1,130 @@ +package noppes.npcs.api.entity; + +import noppes.npcs.api.IDamageSource; +import noppes.npcs.api.IPos; +import noppes.npcs.api.item.IItemStack; + +/** + * Platform-api version (MC-free). The src/api shadow adds generic type parameter + * and IBlock-dependent methods. + */ +public interface IEntityLivingBase extends IEntity { + + float getHealth(); + + void setHealth(float health); + + void hurt(float damage); + + void hurt(float damage, IEntity source); + + void hurt(float damage, IDamageSource damageSource); + + void setMaxHurtTime(int time); + + int getMaxHurtTime(); + + double getMaxHealth(); + + double getFollowRange(); + + double getKnockbackResistance(); + + double getSpeed(); + + double getMeleeStrength(); + + void setMaxHealth(double health); + + void setFollowRange(double range); + + void setKnockbackResistance(double knockbackResistance); + + void setSpeed(double speed); + + void setMeleeStrength(double attackDamage); + + boolean isAttacking(); + + void setAttackTarget(IEntityLivingBase living); + + IEntityLivingBase getAttackTarget(); + + int getAttackTargetTime(); + + void setLastAttacker(IEntity entity); + + IEntity getLastAttacker(); + + int getLastAttackerTime(); + + boolean canBreatheUnderwater(); + + int getType(); + + boolean typeOf(int type); + + IPos getLookVector(); + + // Note: getLookingAtBlock methods omitted — require IBlock (not in platform-api) + + IPos getLookingAtPos(int maxDistance, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IPos getLookingAtPos(int maxDistance); + + IEntity[] getLookingAtEntities(IEntity[] ignoreEntities, int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IEntity[] getLookingAtEntities(int maxDistance, double offset, double range, boolean stopOnBlock, boolean stopOnLiquid, boolean stopOnCollision); + + IEntity[] getLookingAtEntities(int maxDistance, double offset, double range); + + Object getMCEntity(); + + void swingHand(); + + void addPotionEffect(int effect, int duration, int strength, boolean hideParticles); + + void clearPotionEffects(); + + int getPotionEffect(int effect); + + IItemStack getHeldItem(); + + void setHeldItem(IItemStack item); + + IItemStack getArmor(int slot); + + void setArmor(int slot, IItemStack item); + + boolean isChild(); + + void renderBrokenItemStack(IItemStack itemStack); + + boolean isOnLadder(); + + int getTotalArmorValue(); + + int getArrowCountInEntity(); + + void setArrowCountInEntity(int count); + + void dismountEntity(IEntity entity); + + void setAIMoveSpeed(float speed); + + float getAIMoveSpeed(); + + void setAbsorptionAmount(float amount); + + float getAbsorptionAmount(); + + void setHurtTime(int time); + + void applyKnockback(float strength, IEntity source); + + void applyKnockback(float strength, double dirX, double dirZ); + + void forceKnockback(float strength, IEntity source); + + void forceKnockback(float strength, double dirX, double dirZ); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/entity/IPlayer.java b/platform-api/src/main/java/noppes/npcs/api/entity/IPlayer.java new file mode 100644 index 000000000..7463624ab --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/entity/IPlayer.java @@ -0,0 +1,187 @@ +package noppes.npcs.api.entity; + +import noppes.npcs.api.IPos; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.handler.data.IAnimationData; +import noppes.npcs.api.handler.data.IMagicData; +import noppes.npcs.api.item.IItemStack; + +/** + * Platform-api version (MC-free). The src/api shadow adds generic type parameter + * and methods requiring MC-only types (IBlock, IContainer, ICustomGui, ISound, + * IDialog, IQuest, ITimers, IPlayerData, etc.). + */ +public interface IPlayer extends IEntityLivingBase, IAnimatable { + + String getDisplayName(); + + String getName(); + + void kick(String reason); + + void setPosition(double x, double y, double z); + + void setPosition(IPos pos); + + void setPosition(double x, double y, double z, int dimensionId); + + void setPosition(IPos pos, int dimensionId); + + void setPosition(double x, double y, double z, IWorld world); + + void setPosition(IPos pos, IWorld world); + + void setDimension(int dimension); + + int getHunger(); + + void setHunger(int hunger); + + float getSaturation(); + + void setSaturation(float saturation); + + // Dialog methods (int-based — IDialog-based stay in shadow) + + void showDialog(int id); + + boolean hasReadDialog(int id); + + void readDialog(int id); + + void unreadDialog(int id); + + // Quest methods (int-based — IQuest-based stay in shadow) + + boolean hasFinishedQuest(int id); + + boolean hasActiveQuest(int id); + + void startQuest(int id); + + void finishQuest(int id); + + void stopQuest(int id); + + void removeQuest(int id); + + int getType(); + + boolean typeOf(int type); + + void addFactionPoints(int faction, int points); + + void setFactionPoints(int faction, int points); + + int getFactionPoints(int faction); + + void sendMessage(String message); + + int getMode(); + + void setMode(int type); + + IItemStack[] getInventory(); + + int inventoryItemCount(IItemStack item, boolean ignoreNBT, boolean ignoreDamage); + + boolean removeItem(String id, int damage, int amount); + + boolean removeItem(IItemStack item, int amount, boolean ignoreNBT, boolean ignoreDamage); + + int removeAllItems(IItemStack item, boolean ignoreNBT, boolean ignoreDamage); + + boolean giveItem(IItemStack item, int amount); + + boolean giveItem(String id, int damage, int amount); + + void setSpawnpoint(int x, int y, int z); + + void setSpawnpoint(IPos pos); + + void resetSpawnpoint(); + + void setRotation(float rotationYaw, float rotationPitch); + + void disableMouseInput(long time, int... buttonIds); + + void stopUsingItem(); + + void clearItemInUse(); + + void clearInventory(); + + void playSound(String name, float volume, float pitch); + + // playSound(ISound) and playSound(int, ISound) stay in shadow — ISound not in platform-api + + void stopSound(int id); + + void pauseSounds(); + + void continueSounds(); + + void stopSounds(); + + // mountEntity(Entity) stays in shadow — raw MC type + + IEntity dropOneItem(boolean dropStack); + + // canHarvestBlock(IBlock) stays in shadow — IBlock not in platform-api + + boolean interactWith(IEntity entity); + + boolean hasAchievement(String achievement); + + boolean hasBukkitPermission(String permission); + + int getExpLevel(); + + void setExpLevel(int level); + + // getPixelmonData(), getTimers(), getDBCPlayer(), getData(), + // getActionManager(), getAttributes(), getScreenSize(), + // getOpenContainer(), showCustomGui(), getCustomGui(), + // showCustomOverlay(), getOverlays() + // all stay in shadow — types not in platform-api + + void updatePlayerInventory(); + + boolean blocking(); + + boolean isScriptingDev(); + + void closeGui(); + + void closeOverlay(int id); + + IAnimationData getAnimationData(); + + void setConqueredEnd(boolean conqueredEnd); + + boolean conqueredEnd(); + + IMagicData getMagicData(); + + IPlayer[] getPartyMembers(); + + // ========================================= + // Currency Methods + // ========================================= + + long getCurrencyBalance(); + + void setCurrencyBalance(long amount); + + boolean depositCurrency(long amount); + + boolean withdrawCurrency(long amount); + + boolean canAffordCurrency(long amount); + + boolean isUsingVaultCurrency(); + + String getFormattedCurrencyBalance(); + + Object getMCEntity(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimation.java b/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimation.java new file mode 100644 index 000000000..a8fe90c01 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimation.java @@ -0,0 +1,73 @@ +package noppes.npcs.api.handler.data; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public interface IAnimation { + + IAnimationData getParent(); + + IFrame currentFrame(); + + IFrame[] getFrames(); + + IAnimation setFrames(IFrame[] frames); + + IAnimation clearFrames(); + + IAnimation addFrame(IFrame frame); + + IAnimation addFrame(int index, IFrame frame); + + IAnimation removeFrame(IFrame frame); + + IAnimation setName(String name); + + String getName(); + + IAnimation setSpeed(float speed); + + float getSpeed(); + + IAnimation setSmooth(byte smooth); + + byte isSmooth(); + + IAnimation doWhileStanding(boolean whileStanding); + + boolean doWhileStanding(); + + IAnimation doWhileMoving(boolean whileMoving); + + boolean doWhileMoving(); + + IAnimation doWhileAttacking(boolean whileAttacking); + + boolean doWhileAttacking(); + + IAnimation setLoop(int loopAtFrame); + + int loop(); + + IAnimation save(); + + int getID(); + + void setID(int id); + + long getTotalTime(); + + boolean hasData(String key); + + Object getData(String key); + + IAnimation setData(String key, Object v); + + IAnimation removeData(String key); + + IAnimation onStart(Consumer task); + + IAnimation onFrame(BiConsumer task); + + IAnimation onEnd(Consumer task); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimationData.java b/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimationData.java new file mode 100644 index 000000000..096fb6a5f --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/handler/data/IAnimationData.java @@ -0,0 +1,24 @@ +package noppes.npcs.api.handler.data; + +import noppes.npcs.api.entity.IAnimatable; + +public interface IAnimationData { + + IAnimatable getEntity(); + + void updateClient(); + + boolean isActive(); + + boolean isClientAnimating(); + + void setEnabled(boolean enabled); + + boolean enabled(); + + void setAnimation(IAnimation animation); + + IAnimation getAnimation(); + + long getAnimatingTime(); +} diff --git a/platform-api/src/main/java/noppes/npcs/api/handler/data/ISlot.java b/platform-api/src/main/java/noppes/npcs/api/handler/data/ISlot.java index ded3ee9b0..7864ff7a8 100644 --- a/platform-api/src/main/java/noppes/npcs/api/handler/data/ISlot.java +++ b/platform-api/src/main/java/noppes/npcs/api/handler/data/ISlot.java @@ -1,6 +1,6 @@ package noppes.npcs.api.handler.data; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import java.util.Map; @@ -19,11 +19,11 @@ public interface ISlot { void setTemporary(boolean temporary); - Map getComponents(); + Map getComponents(); - void setComponentData(String key, INBTCompound data); + void setComponentData(String key, INbt data); - INBTCompound getComponentData(String key); + INbt getComponentData(String key); - INBTCompound toNBT(); + INbt toNBT(); } diff --git a/platform-api/src/main/java/noppes/npcs/api/item/IItemStack.java b/platform-api/src/main/java/noppes/npcs/api/item/IItemStack.java new file mode 100644 index 000000000..256f41ff0 --- /dev/null +++ b/platform-api/src/main/java/noppes/npcs/api/item/IItemStack.java @@ -0,0 +1,382 @@ +package noppes.npcs.api.item; + +import noppes.npcs.api.INbt; + +/** + * Represents an item stack with extended functionality: + * enchantments, lore, and additional item data. + */ +public interface IItemStack { + String getName(); + + /** + * @return Returns the stack size. + */ + int getStackSize(); + + /** + * @return Returns whether the item has a custom name. + */ + boolean hasCustomName(); + + /** + * Sets the custom name for the item. + * + * @param name The custom name. + */ + void setCustomName(String name); + + /** + * @return Returns the in-game displayed name. This is either the item name or the custom name if set. + */ + String getDisplayName(); + + /** + * @return Returns the base item name, regardless of any custom name. + */ + String getItemName(); + + /** + * Sets the stack size of the item. + * + * @param size The new stack size (between 1 and 64). + */ + void setStackSize(int size); + + /** + * @return Returns the maximum stack size for this item. + */ + int getMaxStackSize(); + + /** + * @return Returns the item damage. For tools, this represents durability. + */ + int getItemDamage(); + + /** + * Sets the item damage value. + * + * @param value The new damage value. + */ + void setItemDamage(int value); + + /** + * Sets an NBT tag for this item. + * + * @param key The tag key. + * @param value The value to store (Number or String). + */ + void setTag(String key, Object value); + + /** + * Checks if the item has an NBT tag with the specified key. + * + * @param key The tag key. + * @return true if present, false otherwise. + */ + boolean hasTag(String key); + + /** + * Returns the value of the NBT tag with the specified key. + * + * @param key The tag key. + * @return The tag value, or null if not present. + */ + Object getTag(String key); + + /** + * Removes all custom tags from the item and returns the removed NBT data. + * + * @return The removed NBT data. + */ + INbt removeTags(); + + /** + * @return Returns whether the item is enchanted. + */ + boolean isEnchanted(); + + /** + * Checks if the item has the specified enchantment. + * + * @param id The enchantment id. + * @return true if present, false otherwise. + */ + boolean hasEnchant(int id); + + /** + * Adds an enchantment to the item. + * + * @param id The enchantment id. + * @param strength The enchantment strength. + */ + void addEnchant(int id, int strength); + + // --- Default MC Attribute Handling (legacy) --- + + /** + * Sets an attribute on the item using the default MC attribute system. + * + * @param name The attribute key. + * @param value The attribute value. + */ + void setAttribute(String name, double value); + + /** + * Retrieves the attribute value using the default MC attribute system. + * + * @param name The attribute key. + * @return The attribute value. + */ + double getAttribute(String name); + + /** + * Checks if the item has an attribute (using the default MC attribute system). + * + * @param name The attribute key. + * @return true if present, false otherwise. + */ + boolean hasAttribute(String name); + + + /** + * Sets the custom attribute value for the given key. + * The value is stored in the item's custom NBT structure. + * + * @param key The custom attribute key. + * @param value The attribute value. + */ + void setCustomAttribute(String key, double value); + + + /** + * Checks whether the item has a custom attribute with the specified key. + * + * @param key The custom attribute key. + * @return true if the attribute exists, false otherwise. + */ + boolean hasCustomAttribute(String key); + + /** + * Returns the custom attribute object associated with the given key. + * This may be a raw value or a more complex structure. + * + * @param key The custom attribute key. + * @return The attribute object value + */ + float getCustomAttribute(String key); + + /** + * Removes the custom attribute with the specified key from the item. + * + * @param key The custom attribute key. + */ + void removeCustomAttribute(String key); + + /** + * Sets the magic attribute value for the given key and magic identifier. + * The value is stored in the item's custom NBT under "RPGCore", "Magic". + * + * @param key The magic attribute key. + * @param magicId The magic identifier. + * @param value The attribute value. + */ + void setMagicAttribute(String key, int magicId, double value); + + + /** + * Checks whether the item has a magic attribute with the given key and magic identifier. + * + * @param key The magic attribute key. + * @param magicId The magic identifier. + * @return true if the attribute exists, false otherwise. + */ + boolean hasMagicAttribute(String key, int magicId); + + /** + * Returns the magic attribute object (typically a Float value) associated with the given key and magic identifier. + * + * @param key The magic attribute key. + * @param magicId The magic identifier. + * @return The attribute object, or null if not present. + */ + float getMagicAttribute(String key, int magicId); + + /** + * Removes the magic attribute with the specified key and magic identifier from the item. + * + * @param key The magic attribute key. + * @param magicId The magic identifier. + */ + void removeMagicAttribute(String key, int magicId); + + /** + * Sets (or applies) a requirement for the item using the given requirement key and value. + * The requirement data is stored under "RPGCore" → "Requirements" in the item's NBT. + * + * @param reqKey The requirement key. + * @param value The requirement value (Number or String). + */ + void setRequirement(String reqKey, Object value); + + /** + * Checks whether the item has a requirement with the specified key. + * + * @param reqKey The requirement key. + * @return true if the requirement exists, false otherwise. + */ + boolean hasRequirement(String reqKey); + + /** + * Retrieves the requirement value for the specified key. + * + * @param reqKey The requirement key. + * @return The requirement value as an Object (or null if not present). + */ + Object getRequirement(String reqKey); + + /** + * Removes the requirement with the specified key from the item. + * + * @param reqKey The requirement key. + */ + void removeRequirement(String reqKey); + + /** + * Returns an array of all custom attribute keys stored on the item. + * + * @return an array of custom attribute keys. + */ + String[] getCustomAttributeKeys(); + + /** + * Returns an array of all magic attribute keys (as strings) for the specified magic attribute key. + * + * @param key the magic attribute key (e.g. "magic_damage"). + * @return an array of magic identifier keys as strings. + */ + String[] getMagicAttributeKeys(String key); + + /** + * Returns an array of all requirement keys stored on the item. + * + * @return an array of requirement keys. + */ + String[] getRequirementKeys(); + + /** + * @return Returns the lore (descriptive text) for the item. + */ + String[] getLore(); + + /** + * @return Returns whether the item has lore. + */ + boolean hasLore(); + + /** + * Sets the lore for the item. + * + * @param lore An array of lore strings. + */ + void setLore(String[] lore); + + /** + * Creates a deep copy of this item stack. + * + * @return A copy of the item stack. + */ + IItemStack copy(); + + /** + * @return Returns the maximum damage the item can sustain. + */ + int getMaxItemDamage(); + + /** + * @return Returns whether the item is a written book. + */ + boolean isWrittenBook(); + + /** + * @return Returns the book's title. + */ + String getBookTitle(); + + /** + * @return Returns the book's author. + */ + String getBookAuthor(); + + /** + * @return If the item is a book, returns the book pages. + */ + String[] getBookText(); + + /** + * @return Returns whether the item represents a block. + */ + boolean isBlock(); + + /** + * Returns an INbt instance representing the item's custom NBT data. + * + * @return The custom NBT data. + */ + INbt getNbt(); + + /** + * Returns an INbt instance representing the full NBT data of the item. + * + * @return The complete NBT data. + */ + INbt getItemNbt(); + + /** + * Returns the underlying Minecraft ItemStack. + *

No support is given for this method. Use with caution.

+ * + * @return The Minecraft ItemStack. + */ + Object getMCItemStack(); + + /** + * Returns a hash value for the item. + * + * @return The item's hash code. + */ + int itemHash(); + + /** + * Returns the underlying Minecraft NBTTagCompound for the item. + * + * @return The NBTTagCompound. + */ + Object getMCNbt(); + + /** + * Sets the underlying Minecraft NBTTagCompound for the item. + * + * @param compound The NBTTagCompound to set. + */ + void setMCNbt(Object compound); + + /** + * Compares this item with another item, with an option to ignore NBT data. + * + * @param item The item to compare. + * @param ignoreNBT true to ignore NBT data. + * @return true if the items are considered equal, false otherwise. + */ + boolean compare(IItemStack item, boolean ignoreNBT); + + /** + * Compares this item with another item, with options to ignore damage and/or NBT data. + * + * @param item The item to compare. + * @param ignoreDamage true to ignore damage values. + * @param ignoreNBT true to ignore NBT data. + * @return true if the items are considered equal, false otherwise. + */ + boolean compare(IItemStack item, boolean ignoreDamage, boolean ignoreNBT); +} diff --git a/platform-api/src/main/java/noppes/npcs/platform/PlatformService.java b/platform-api/src/main/java/noppes/npcs/platform/PlatformService.java deleted file mode 100644 index 5eaef17b3..000000000 --- a/platform-api/src/main/java/noppes/npcs/platform/PlatformService.java +++ /dev/null @@ -1,147 +0,0 @@ -package noppes.npcs.platform; - -import kamkeel.npcs.platform.entity.IDamage; -import kamkeel.npcs.platform.entity.ILiving; -import kamkeel.npcs.platform.entity.IMob; -import kamkeel.npcs.platform.entity.IUser; -import kamkeel.npcs.platform.entity.IStack; -import kamkeel.npcs.platform.entity.IGameWorld; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; -import noppes.npcs.platform.nbt.NBTFactory; - -import java.io.File; -import java.io.IOException; - -/** - * Central platform abstraction that bridges CORE logic with MC-version-specific code. - * - * Each mc* module (mc1710, mc1122, mc1165, mc1201) provides an implementation - * that is registered during mod initialization via {@link PlatformServiceHolder#set(PlatformService)}. - * - * CORE code accesses this via {@link PlatformServiceHolder#get()}. - */ -public interface PlatformService { - - // --- NBT --- - - /** - * @return the NBT factory for creating and wrapping NBT objects - */ - NBTFactory nbt(); - - // --- NBT I/O --- - - /** - * Reads a compressed NBT compound from a file. - * Maps to CompressedStreamTools.readCompressed() in MC. - */ - INBTCompound readCompressedNBT(File file) throws IOException; - - /** - * Writes a compressed NBT compound to a file. - * Maps to CompressedStreamTools.writeCompressed() in MC. - */ - void writeCompressedNBT(INBTCompound compound, File file) throws IOException; - - // --- Paths --- - - /** - * @return the world save directory (server-side), e.g. "saves/MyWorld/customnpcs/" - */ - File getWorldSaveDirectory(); - - /** - * @return a subdirectory within the world save directory - */ - File getWorldSaveDirectory(String subdir); - - /** - * @return the global config directory, e.g. ".minecraft/config/" - */ - File getConfigDirectory(); - - // --- Environment --- - - /** - * @return true if running on the physical client (has a GUI) - */ - boolean isPhysicalClient(); - - /** - * @return the mod version string - */ - String getModVersion(); - - // --- Logging --- - - void logInfo(String message); - - void logWarn(String message); - - void logError(String message); - - void logError(String message, Throwable t); - - void logDebug(String message); - - // --- Entity Wrapping --- - - /** - * Wraps a raw MC player entity into a platform-independent player. - * - * @param mcPlayer the MC player object (e.g., EntityPlayerMP on 1.7.10) - * @return a platform player wrapper - */ - IUser wrapPlayer(Object mcPlayer); - - /** - * Wraps a raw MC entity into a platform-independent entity. - * - * @param mcEntity the MC entity object - * @return a platform entity wrapper - */ - IMob wrapEntity(Object mcEntity); - - /** - * Wraps a raw MC living entity into a platform-independent living entity. - * - * @param mcLiving the MC living entity object (e.g., EntityLivingBase on 1.7.10) - * @return a platform living wrapper - */ - ILiving wrapLiving(Object mcLiving); - - /** - * Wraps a raw MC item stack into a platform-independent stack. - * - * @param mcStack the MC ItemStack object - * @return a platform stack wrapper - */ - IStack wrapStack(Object mcStack); - - /** - * Wraps a raw MC world into a platform-independent world. - * - * @param mcWorld the MC World object - * @return a platform world wrapper - */ - IGameWorld wrapWorld(Object mcWorld); - - /** - * Wraps a raw MC damage source into a platform-independent damage source. - * - * @param mcSource the MC DamageSource object - * @return a platform damage source wrapper - */ - IDamage wrapDamageSource(Object mcSource); - - // --- Scheduling --- - - /** - * Runs a task on the main server thread. - * Safe to call from any thread. - * - * @param task the task to run - */ - void runOnMainThread(Runnable task); -} diff --git a/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTCompound.java b/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTCompound.java deleted file mode 100644 index a78d39915..000000000 --- a/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTCompound.java +++ /dev/null @@ -1,125 +0,0 @@ -package noppes.npcs.platform.nbt; - -/** - * Version-independent abstraction over Minecraft's NBT compound tag. - * - * Maps to: - * - 1.7.10 / 1.12: net.minecraft.nbt.NBTTagCompound - * - 1.16+: net.minecraft.nbt.CompoundNBT / CompoundTag - * - * Each mc* module provides a thin wrapper implementation that delegates - * to the real MC class. CORE code uses this interface exclusively. - */ -public interface INBTCompound { - - // --- Setters --- - - void setString(String key, String value); - - void setInteger(String key, int value); - - void setBoolean(String key, boolean value); - - void setDouble(String key, double value); - - void setFloat(String key, float value); - - void setLong(String key, long value); - - void setShort(String key, short value); - - void setByte(String key, byte value); - - void setByteArray(String key, byte[] value); - - void setIntArray(String key, int[] value); - - void setCompound(String key, INBTCompound compound); - - void setTag(String key, INBTCompound compound); - - void setList(String key, INBTList list); - - // --- Getters --- - - String getString(String key); - - int getInteger(String key); - - boolean getBoolean(String key); - - double getDouble(String key); - - float getFloat(String key); - - long getLong(String key); - - short getShort(String key); - - byte getByte(String key); - - byte[] getByteArray(String key); - - int[] getIntArray(String key); - - INBTCompound getCompound(String key); - - /** - * Gets a tag list from this compound. - * @param key the key - * @param type the element type ID (e.g. 10 for compounds, 8 for strings) - * @return the list, or an empty list if the key doesn't exist - */ - INBTList getList(String key, int type); - - // --- Query --- - - boolean hasKey(String key); - - /** - * Checks if this compound has a key of a specific NBT type. - * @param key the key - * @param type the NBT type ID - */ - boolean hasKey(String key, int type); - - /** - * @return a set of all keys in this compound - */ - java.util.Set getKeySet(); - - /** - * Removes a key from this compound. - */ - void removeTag(String key); - - /** - * Returns the NBT type ID for the tag with the given key. - * @return the type ID (see {@link noppes.npcs.constants.NBTTypes}), or 0 if not present - */ - int getTagType(String key); - - /** - * @return true if this compound has no keys - */ - boolean isEmpty(); - - // --- Interop --- - - /** - * Merges all tags from the given compound into this one. - */ - void merge(INBTCompound other); - - /** - * Creates a deep copy of this compound. - */ - INBTCompound copy(); - - /** - * Returns the underlying MC NBT object. - * Used at the boundary between CORE and version-specific code. - * CORE code should NEVER call this — only mc* modules should. - */ - Object getUnderlyingTag(); -} diff --git a/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTList.java b/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTList.java deleted file mode 100644 index a727b8cfc..000000000 --- a/platform-api/src/main/java/noppes/npcs/platform/nbt/INBTList.java +++ /dev/null @@ -1,88 +0,0 @@ -package noppes.npcs.platform.nbt; - -/** - * Version-independent abstraction over Minecraft's NBT list tag. - * - * Maps to: - * - 1.7.10 / 1.12: net.minecraft.nbt.NBTTagList - * - 1.16+: net.minecraft.nbt.ListNBT / ListTag - */ -public interface INBTList { - - /** - * @return the number of elements in this list - */ - int size(); - - /** - * Gets the compound tag at the given index. - * @throws ClassCastException if the element is not a compound - */ - INBTCompound getCompound(int index); - - /** - * Gets the string value at the given index. - */ - String getString(int index); - - /** - * Gets the integer value at the given index (from int array tags). - */ - int getInt(int index); - - /** - * Gets the double value at the given index. - */ - double getDouble(int index); - - /** - * Gets the float value at the given index. - */ - float getFloat(int index); - - /** - * Gets an int array at the given index (for lists of int arrays). - */ - int[] getIntArray(int index); - - /** - * @return the NBT type ID of elements in this list (see {@link noppes.npcs.constants.NBTTypes}), - * or 0 if the list is empty - */ - int getElementType(); - - // --- Mutators --- - - /** - * Appends a compound tag to the end of this list. - */ - void addCompound(INBTCompound compound); - - /** - * Appends a string to the end of this list. - */ - void addString(String value); - - /** - * Appends an integer tag to the end of this list. - */ - void addInt(int value); - - /** - * Appends a double tag to the end of this list. - */ - void addDouble(double value); - - /** - * Removes and returns the element at the given index. - */ - void remove(int index); - - // --- Interop --- - - /** - * Returns the underlying MC NBT list object. - * CORE code should NEVER call this — only mc* modules should. - */ - Object getUnderlyingTag(); -} diff --git a/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTFactory.java b/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTFactory.java index 77fb82429..ad5eac60a 100644 --- a/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTFactory.java +++ b/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTFactory.java @@ -1,5 +1,8 @@ package noppes.npcs.platform.nbt; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; + /** * Factory for creating new NBT instances. * Each mc* module provides an implementation via PlatformService. @@ -9,29 +12,28 @@ public interface NBTFactory { /** * Creates a new, empty compound tag. */ - INBTCompound createCompound(); + INbt createCompound(); /** * Creates a new, empty list tag. */ - INBTList createList(); + INbtList createList(); /** - * Wraps a raw MC NBT compound object into an INBTCompound. - * Used at the boundary when receiving NBT from MC code. + * Wraps a raw MC NBT compound object into an INbt. * * @param mcNBTTagCompound the raw MC NBTTagCompound / CompoundTag * @return the wrapped interface * @throws IllegalArgumentException if the object is not a valid MC NBT compound */ - INBTCompound wrap(Object mcNBTTagCompound); + INbt wrap(Object mcNBTTagCompound); /** - * Wraps a raw MC NBT list object into an INBTList. + * Wraps a raw MC NBT list object into an INbtList. * * @param mcNBTTagList the raw MC NBTTagList / ListTag * @return the wrapped interface * @throws IllegalArgumentException if the object is not a valid MC NBT list */ - INBTList wrapList(Object mcNBTTagList); + INbtList wrapList(Object mcNBTTagList); } diff --git a/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTIO.java b/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTIO.java index 83c528072..d28f921cf 100644 --- a/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTIO.java +++ b/platform-api/src/main/java/noppes/npcs/platform/nbt/NBTIO.java @@ -1,37 +1,21 @@ package noppes.npcs.platform.nbt; +import noppes.npcs.api.INbt; + import java.io.File; import java.io.IOException; /** * Abstraction for NBT file I/O operations. - * - * Maps to CompressedStreamTools in MC. Used by controllers for - * reading/writing world save data. + * Maps to CompressedStreamTools in MC. */ public interface NBTIO { - /** - * Reads a compressed NBT compound from a file. - * Equivalent to CompressedStreamTools.readCompressed(FileInputStream). - */ - INBTCompound readCompressed(File file) throws IOException; + INbt readCompressed(File file) throws IOException; - /** - * Writes a compressed NBT compound to a file. - * Equivalent to CompressedStreamTools.writeCompressed(NBTTagCompound, FileOutputStream). - */ - void writeCompressed(INBTCompound compound, File file) throws IOException; + void writeCompressed(INbt compound, File file) throws IOException; - /** - * Reads an uncompressed NBT compound from a file. - * Equivalent to CompressedStreamTools.read(File). - */ - INBTCompound read(File file) throws IOException; + INbt read(File file) throws IOException; - /** - * Writes an uncompressed NBT compound to a file (safe write with temp file). - * Equivalent to CompressedStreamTools.safeWrite(NBTTagCompound, File). - */ - void safeWrite(INBTCompound compound, File file) throws IOException; + void safeWrite(INbt compound, File file) throws IOException; } diff --git a/src/api b/src/api index f91e17ab3..5cb3a5bee 160000 --- a/src/api +++ b/src/api @@ -1 +1 @@ -Subproject commit f91e17ab3ef4bf168836f8619c60cf6806f6ab84 +Subproject commit 5cb3a5beefe4bae340da43fb3a05428afa30d6fd diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/DamageWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/DamageWrapper.java deleted file mode 100644 index 19ed07b15..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/DamageWrapper.java +++ /dev/null @@ -1,34 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IDamage; -import kamkeel.npcs.platform.entity.IMob; -import net.minecraft.util.DamageSource; - -/** - * MC 1.7.10 implementation of {@link IDamage}. - * Wraps a raw {@link DamageSource} instance. - */ -public class DamageWrapper implements IDamage { - - private final DamageSource source; - - public DamageWrapper(DamageSource source) { - this.source = source; - } - - @Override - public String getType() { - return source.getDamageType(); - } - - @Override - public IMob getSourceEntity() { - if (source.getEntity() == null) return null; - return new EntityWrapper(source.getEntity()); - } - - @Override - public Object getHandle() { - return source; - } -} diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/EntityWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/EntityWrapper.java deleted file mode 100644 index 1255b68ab..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/EntityWrapper.java +++ /dev/null @@ -1,73 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IMob; -import kamkeel.npcs.platform.entity.IGameWorld; -import net.minecraft.entity.Entity; - -/** - * MC 1.7.10 implementation of {@link IMob}. - * Wraps a raw {@link Entity} instance. - */ -public class EntityWrapper implements IMob { - - protected final Entity entity; - - public EntityWrapper(Entity entity) { - this.entity = entity; - } - - @Override - public int getEntityId() { - return entity.getEntityId(); - } - - @Override - public String getUniqueID() { - return entity.getUniqueID().toString(); - } - - @Override - public double getX() { - return entity.posX; - } - - @Override - public double getY() { - return entity.posY; - } - - @Override - public double getZ() { - return entity.posZ; - } - - @Override - public float getYaw() { - return entity.rotationYaw; - } - - @Override - public float getPitch() { - return entity.rotationPitch; - } - - @Override - public void setPosition(double x, double y, double z) { - entity.setPosition(x, y, z); - } - - @Override - public boolean isAlive() { - return !entity.isDead; - } - - @Override - public IGameWorld getWorld() { - return new WorldWrapper(entity.worldObj); - } - - @Override - public Object getHandle() { - return entity; - } -} diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/LivingWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/LivingWrapper.java deleted file mode 100644 index f14f78e05..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/LivingWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IDamage; -import kamkeel.npcs.platform.entity.ILiving; -import net.minecraft.entity.EntityLivingBase; -import net.minecraft.util.DamageSource; - -/** - * MC 1.7.10 implementation of {@link ILiving}. - * Wraps a raw {@link EntityLivingBase} instance. - */ -public class LivingWrapper extends EntityWrapper implements ILiving { - - protected final EntityLivingBase living; - - public LivingWrapper(EntityLivingBase living) { - super(living); - this.living = living; - } - - @Override - public float getHealth() { - return living.getHealth(); - } - - @Override - public void setHealth(float hp) { - living.setHealth(hp); - } - - @Override - public float getMaxHealth() { - return living.getMaxHealth(); - } - - @Override - public void damage(float amount, IDamage source) { - DamageSource mcSource = source != null ? (DamageSource) source.getHandle() : DamageSource.generic; - living.attackEntityFrom(mcSource, amount); - } -} diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/PlayerWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/PlayerWrapper.java deleted file mode 100644 index 42098dc71..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/PlayerWrapper.java +++ /dev/null @@ -1,47 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IUser; -import kamkeel.npcs.platform.entity.IStack; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.ChatComponentText; - -/** - * MC 1.7.10 implementation of {@link IUser}. - * Wraps a raw {@link EntityPlayerMP} instance. - */ -public class PlayerWrapper extends LivingWrapper implements IUser { - - private final EntityPlayerMP player; - - public PlayerWrapper(EntityPlayerMP player) { - super(player); - this.player = player; - } - - @Override - public String getName() { - return player.getCommandSenderName(); - } - - @Override - public String getUniqueID() { - return player.getUniqueID().toString(); - } - - @Override - public boolean isOp() { - return player.mcServer.getConfigurationManager() - .func_152596_g(player.getGameProfile()); - } - - @Override - public void sendMessage(String text) { - player.addChatMessage(new ChatComponentText(text)); - } - - @Override - public IStack getHeldItem() { - if (player.getHeldItem() == null) return null; - return new StackWrapper(player.getHeldItem()); - } -} diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/StackWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/StackWrapper.java deleted file mode 100644 index f438646f9..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/StackWrapper.java +++ /dev/null @@ -1,75 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IStack; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.wrapper.nbt.NBTWrapper; - -/** - * MC 1.7.10 implementation of {@link IStack}. - * Wraps a raw {@link ItemStack} instance. - */ -public class StackWrapper implements IStack { - - private final ItemStack stack; - - public StackWrapper(ItemStack stack) { - this.stack = stack; - } - - @Override - public String getItemId() { - if (stack == null || stack.getItem() == null) return "minecraft:air"; - return Item.itemRegistry.getNameForObject(stack.getItem()); - } - - @Override - public int getCount() { - return stack != null ? stack.stackSize : 0; - } - - @Override - public void setCount(int count) { - if (stack != null) stack.stackSize = count; - } - - @Override - public int getDamage() { - return stack != null ? stack.getItemDamage() : 0; - } - - @Override - public void setDamage(int dmg) { - if (stack != null) stack.setItemDamage(dmg); - } - - @Override - public INBTCompound getTag() { - if (stack == null || stack.stackTagCompound == null) return null; - return new NBTWrapper(stack.stackTagCompound); - } - - @Override - public void setTag(INBTCompound tag) { - if (stack != null) { - stack.stackTagCompound = tag != null ? ((NBTWrapper) tag).getMCTag() : null; - } - } - - @Override - public boolean isEmpty() { - return stack == null || stack.getItem() == null || stack.stackSize <= 0; - } - - @Override - public IStack copy() { - if (stack == null) return new StackWrapper(null); - return new StackWrapper(stack.copy()); - } - - @Override - public Object getHandle() { - return stack; - } -} diff --git a/src/main/java/kamkeel/npcs/wrapper/platform/WorldWrapper.java b/src/main/java/kamkeel/npcs/wrapper/platform/WorldWrapper.java deleted file mode 100644 index dd49a83b8..000000000 --- a/src/main/java/kamkeel/npcs/wrapper/platform/WorldWrapper.java +++ /dev/null @@ -1,41 +0,0 @@ -package kamkeel.npcs.wrapper.platform; - -import kamkeel.npcs.platform.entity.IMob; -import kamkeel.npcs.platform.entity.IGameWorld; -import net.minecraft.entity.Entity; -import net.minecraft.world.World; - -/** - * MC 1.7.10 implementation of {@link IGameWorld}. - * Wraps a raw {@link World} instance. - */ -public class WorldWrapper implements IGameWorld { - - private final World world; - - public WorldWrapper(World world) { - this.world = world; - } - - @Override - public int getDimensionId() { - return world.provider.dimensionId; - } - - @Override - public boolean isClient() { - return world.isRemote; - } - - @Override - public IMob getEntityById(int id) { - Entity entity = world.getEntityByID(id); - if (entity == null) return null; - return new EntityWrapper(entity); - } - - @Override - public Object getHandle() { - return world; - } -} diff --git a/src/main/java/noppes/npcs/CustomNpcs.java b/src/main/java/noppes/npcs/CustomNpcs.java index f72a7c156..218c7e3be 100644 --- a/src/main/java/noppes/npcs/CustomNpcs.java +++ b/src/main/java/noppes/npcs/CustomNpcs.java @@ -64,7 +64,7 @@ import nikedemos.markovnames.generators.MarkovSlavic; import nikedemos.markovnames.generators.MarkovSpanish; import nikedemos.markovnames.generators.MarkovWelsh; import noppes.npcs.compat.PixelmonHelper; -import noppes.npcs.platform.PlatformServiceHolder; +import kamkeel.npcs.platform.PlatformServiceHolder; import noppes.npcs.wrapper.MC1710PlatformService; import noppes.npcs.config.ConfigMain; import noppes.npcs.core.CoreConfig; diff --git a/src/main/java/noppes/npcs/scripted/ScriptNbt.java b/src/main/java/noppes/npcs/scripted/ScriptNbt.java index fcc26ac7f..7351c4ff5 100644 --- a/src/main/java/noppes/npcs/scripted/ScriptNbt.java +++ b/src/main/java/noppes/npcs/scripted/ScriptNbt.java @@ -9,9 +9,13 @@ import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.util.NBTJsonUtil; +import noppes.npcs.wrapper.nbt.NBTListWrapper; +import noppes.npcs.wrapper.nbt.NBTWrapper; import java.util.Iterator; +import java.util.Set; public class ScriptNbt implements INbt { private NBTTagCompound compound; @@ -20,192 +24,260 @@ public class ScriptNbt implements INbt { this.compound = compound; } - public void remove(String key) { - this.compound.removeTag(key); - } - - public boolean has(String key) { - return this.compound.hasKey(key); - } - - public boolean getBoolean(String key) { - return this.compound.getBoolean(key); - } - - public void setBoolean(String key, boolean value) { - this.compound.setBoolean(key, value); - } - - public short getShort(String key) { - return this.compound.getShort(key); - } - - public void setShort(String key, short value) { - this.compound.setShort(key, value); - } - - public int getInteger(String key) { - return this.compound.getInteger(key); - } - - public void setInteger(String key, int value) { - this.compound.setInteger(key, value); - } - - public byte getByte(String key) { - return this.compound.getByte(key); - } - - public void setByte(String key, byte value) { - this.compound.setByte(key, value); - } - - public long getLong(String key) { - return this.compound.getLong(key); - } - - public void setLong(String key, long value) { - this.compound.setLong(key, value); - } - - public double getDouble(String key) { - return this.compound.getDouble(key); - } - - public void setDouble(String key, double value) { - this.compound.setDouble(key, value); - } - - public float getFloat(String key) { - return this.compound.getFloat(key); - } - - public void setFloat(String key, float value) { - this.compound.setFloat(key, value); - } - - public String getString(String key) { - return this.compound.getString(key); - } + // ======================== Setters ======================== + @Override public void setString(String key, String value) { this.compound.setString(key, value); } - public byte[] getByteArray(String key) { - return this.compound.getByteArray(key); + @Override + public void setInteger(String key, int value) { + this.compound.setInteger(key, value); } + @Override + public void setBoolean(String key, boolean value) { + this.compound.setBoolean(key, value); + } + + @Override + public void setDouble(String key, double value) { + this.compound.setDouble(key, value); + } + + @Override + public void setFloat(String key, float value) { + this.compound.setFloat(key, value); + } + + @Override + public void setLong(String key, long value) { + this.compound.setLong(key, value); + } + + @Override + public void setShort(String key, short value) { + this.compound.setShort(key, value); + } + + @Override + public void setByte(String key, byte value) { + this.compound.setByte(key, value); + } + + @Override public void setByteArray(String key, byte[] value) { this.compound.setByteArray(key, value); } - public int[] getIntegerArray(String key) { - return this.compound.getIntArray(key); - } - - public void setIntegerArray(String key, int[] value) { + @Override + public void setIntArray(String key, int[] value) { this.compound.setIntArray(key, value); } + @Override + public void setCompound(String key, INbt value) { + if (value == null) { + throw new CustomNPCsException("Value cant be null", new Object[0]); + } + this.compound.setTag(key, value.getMCNBT()); + } + + @Override + public void setTagList(String key, INbtList list) { + this.compound.setTag(key, (NBTTagList) list.getMCTagList()); + } + + @Override + public void setList(String key, Object[] value) { + NBTTagList list = new NBTTagList(); + for (Object nbt : value) { + if (nbt instanceof INbt) { + list.appendTag(((INbt) nbt).getMCNBT()); + } else if (nbt instanceof String) { + list.appendTag(new NBTTagString((String) nbt)); + } else if (nbt instanceof Double) { + list.appendTag(new NBTTagDouble((Double) nbt)); + } else if (nbt instanceof Float) { + list.appendTag(new NBTTagFloat((Float) nbt)); + } else if (nbt instanceof Integer) { + list.appendTag(new NBTTagInt((Integer) nbt)); + } else if (nbt instanceof int[]) { + list.appendTag(new NBTTagIntArray((int[]) nbt)); + } + } + this.compound.setTag(key, list); + } + + // ======================== Getters ======================== + + @Override + public String getString(String key) { + return this.compound.getString(key); + } + + @Override + public int getInteger(String key) { + return this.compound.getInteger(key); + } + + @Override + public boolean getBoolean(String key) { + return this.compound.getBoolean(key); + } + + @Override + public double getDouble(String key) { + return this.compound.getDouble(key); + } + + @Override + public float getFloat(String key) { + return this.compound.getFloat(key); + } + + @Override + public long getLong(String key) { + return this.compound.getLong(key); + } + + @Override + public short getShort(String key) { + return this.compound.getShort(key); + } + + @Override + public byte getByte(String key) { + return this.compound.getByte(key); + } + + @Override + public byte[] getByteArray(String key) { + return this.compound.getByteArray(key); + } + + @Override + public int[] getIntArray(String key) { + return this.compound.getIntArray(key); + } + + @Override + public INbt getCompound(String key) { + return new ScriptNbt(this.compound.getCompoundTag(key)); + } + + @Override + public INbtList getTagList(String key, int type) { + return new NBTListWrapper(this.compound.getTagList(key, type)); + } + + @Override public Object[] getList(String key, int type) { NBTTagList list = this.compound.getTagList(key, type); Object[] nbts = new Object[list.tagCount()]; - - for (int i = 0; i < list.tagCount(); ++i) { - if (list.func_150303_d() == 10) { + for (int i = 0; i < list.tagCount(); i++) { + int elemType = list.func_150303_d(); + if (elemType == 10) { nbts[i] = new ScriptNbt(list.getCompoundTagAt(i)); - } else if (list.func_150303_d() == 8) { + } else if (elemType == 8) { nbts[i] = list.getStringTagAt(i); - } else if (list.func_150303_d() == 6) { - nbts[i] = Double.valueOf(list.func_150309_d(i)); - } else if (list.func_150303_d() == 5) { - nbts[i] = Float.valueOf(list.func_150308_e(i)); - } else if (list.func_150303_d() == 3) { - nbts[i] = Integer.valueOf(list.getStringTagAt(i)); - } else if (list.func_150303_d() == 11) { + } else if (elemType == 6) { + nbts[i] = list.func_150309_d(i); + } else if (elemType == 5) { + nbts[i] = list.func_150308_e(i); + } else if (elemType == 3) { + nbts[i] = Integer.parseInt(list.getStringTagAt(i)); + } else if (elemType == 11) { nbts[i] = list.func_150306_c(i); } } - return nbts; } + @Override public int getListType(String key) { NBTBase b = this.compound.getTag(key); if (b == null) { return 0; } else if (b.getId() != 9) { throw new CustomNPCsException("NBT tag " + key + " isn\'t a list", new Object[0]); - } else { - return ((NBTTagList) b).func_150303_d(); } + return ((NBTTagList) b).func_150303_d(); } - public void setList(String key, Object[] value) { - NBTTagList list = new NBTTagList(); - Object[] var4 = value; - int var5 = value.length; + // ======================== Query ======================== - for (int var6 = 0; var6 < var5; ++var6) { - Object nbt = var4[var6]; - if (nbt instanceof INbt) { - list.appendTag(((INbt) nbt).getMCNBT()); - } else if (nbt instanceof String) { - list.appendTag(new NBTTagString((String) nbt)); - } else if (nbt instanceof Double) { - list.appendTag(new NBTTagDouble(((Double) nbt).doubleValue())); - } else if (nbt instanceof Float) { - list.appendTag(new NBTTagFloat(((Float) nbt).floatValue())); - } else if (nbt instanceof Integer) { - list.appendTag(new NBTTagInt(((Integer) nbt).intValue())); - } else if (nbt instanceof int[]) { - list.appendTag(new NBTTagIntArray((int[]) ((int[]) nbt))); - } - } - - this.compound.setTag(key, list); + @Override + public boolean hasKey(String key) { + return this.compound.hasKey(key); } - public INbt getCompound(String key) { - return new ScriptNbt(this.compound.getCompoundTag(key)); + @Override + public boolean hasKey(String key, int type) { + return this.compound.hasKey(key, type); } - public void setCompound(String key, INbt value) { - if (value == null) { - throw new CustomNPCsException("Value cant be null", new Object[0]); - } else { - this.compound.setTag(key, value.getMCNBT()); - } + @Override + @SuppressWarnings("unchecked") + public Set getKeySet() { + return (Set) this.compound.func_150296_c(); } - public String[] getKeys() { - return (String[]) this.compound.func_150296_c().toArray(new String[this.compound.func_150296_c().size()]); + @Override + public void removeTag(String key) { + this.compound.removeTag(key); } - public int getType(String key) { + @Override + public int getTagType(String key) { return this.compound.func_150299_b(key); } + @Override + public boolean isEmpty() { + return this.compound.hasNoTags(); + } + + // ======================== Interop ======================== + + @Override + public void merge(INbt other) { + NBTTagCompound otherTag = other.getMCNBT(); + for (Object keyObj : otherTag.func_150296_c()) { + String key = (String) keyObj; + this.compound.setTag(key, otherTag.getTag(key).copy()); + } + } + + @Override + public INbt copy() { + return new ScriptNbt((NBTTagCompound) this.compound.copy()); + } + + @Override public NBTTagCompound getMCNBT() { return this.compound; } + // ======================== Convenience ======================== + + @Override public String toJsonString() { return NBTJsonUtil.Convert(this.compound); } + @Override public boolean isEqual(INbt nbt) { return nbt != null && this.compound.equals(nbt.getMCNBT()); } + @Override public void clear() { - Iterator var1 = this.compound.func_150296_c().iterator(); - - while (var1.hasNext()) { - String name = (String) var1.next(); - this.compound.removeTag(name); + Iterator it = this.compound.func_150296_c().iterator(); + while (it.hasNext()) { + it.next(); + it.remove(); } - } } diff --git a/src/main/java/noppes/npcs/wrapper/MC1710PlatformService.java b/src/main/java/noppes/npcs/wrapper/MC1710PlatformService.java index 4225cc637..4af55c66e 100644 --- a/src/main/java/noppes/npcs/wrapper/MC1710PlatformService.java +++ b/src/main/java/noppes/npcs/wrapper/MC1710PlatformService.java @@ -8,21 +8,28 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.util.DamageSource; import net.minecraft.world.World; import noppes.npcs.CustomNpcs; -import noppes.npcs.platform.PlatformService; -import kamkeel.npcs.platform.entity.*; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import kamkeel.npcs.platform.PlatformService; +import noppes.npcs.api.IDamageSource; +import noppes.npcs.api.INbt; +import noppes.npcs.api.IWorld; +import noppes.npcs.api.entity.IEntity; +import noppes.npcs.api.entity.IEntityLivingBase; +import noppes.npcs.api.entity.IPlayer; +import noppes.npcs.api.item.IItemStack; import noppes.npcs.platform.nbt.NBTFactory; +import noppes.npcs.scripted.NpcAPI; +import noppes.npcs.scripted.ScriptDamageSource; +import noppes.npcs.scripted.ScriptWorld; +import noppes.npcs.scripted.item.ScriptItemStack; import noppes.npcs.wrapper.nbt.NBTWrapperFactory; import noppes.npcs.wrapper.nbt.NBTWrapperIO; -import kamkeel.npcs.wrapper.platform.*; import java.io.File; import java.io.IOException; /** * 1.7.10 implementation of PlatformService. - * Bridges CORE code to MC 1.7.10 APIs. + * Bridges CORE code to MC 1.7.10 APIs via Script* wrappers. */ public class MC1710PlatformService implements PlatformService { @@ -35,12 +42,12 @@ public class MC1710PlatformService implements PlatformService { } @Override - public INBTCompound readCompressedNBT(File file) throws IOException { + public INbt readCompressedNBT(File file) throws IOException { return nbtIO.readCompressed(file); } @Override - public void writeCompressedNBT(INBTCompound compound, File file) throws IOException { + public void writeCompressedNBT(INbt compound, File file) throws IOException { nbtIO.writeCompressed(compound, file); } @@ -62,7 +69,6 @@ public class MC1710PlatformService implements PlatformService { @Override public boolean isPhysicalClient() { try { - // If Minecraft class is loadable, we're on the client Class.forName("net.minecraft.client.Minecraft"); return true; } catch (ClassNotFoundException e) { @@ -104,33 +110,35 @@ public class MC1710PlatformService implements PlatformService { // --- Entity Wrapping --- @Override - public IUser wrapPlayer(Object mcPlayer) { - return new PlayerWrapper((EntityPlayerMP) mcPlayer); + @SuppressWarnings("unchecked") + public IPlayer wrapPlayer(Object mcPlayer) { + return (IPlayer) NpcAPI.Instance().getIEntity((Entity) mcPlayer); } @Override - public IMob wrapEntity(Object mcEntity) { - return new EntityWrapper((Entity) mcEntity); + public IEntity wrapEntity(Object mcEntity) { + return NpcAPI.Instance().getIEntity((Entity) mcEntity); } @Override - public ILiving wrapLiving(Object mcLiving) { - return new LivingWrapper((EntityLivingBase) mcLiving); + @SuppressWarnings("unchecked") + public IEntityLivingBase wrapLiving(Object mcLiving) { + return (IEntityLivingBase) NpcAPI.Instance().getIEntity((Entity) mcLiving); } @Override - public IStack wrapStack(Object mcStack) { - return new StackWrapper((ItemStack) mcStack); + public IItemStack wrapStack(Object mcStack) { + return NpcAPI.Instance().getIItemStack((ItemStack) mcStack); } @Override - public IGameWorld wrapWorld(Object mcWorld) { - return new WorldWrapper((World) mcWorld); + public IWorld wrapWorld(Object mcWorld) { + return NpcAPI.Instance().getIWorld((World) mcWorld); } @Override - public IDamage wrapDamageSource(Object mcSource) { - return new DamageWrapper((DamageSource) mcSource); + public IDamageSource wrapDamageSource(Object mcSource) { + return NpcAPI.Instance().getIDamageSource((DamageSource) mcSource); } // --- Scheduling --- @@ -139,8 +147,6 @@ public class MC1710PlatformService implements PlatformService { public void runOnMainThread(Runnable task) { MinecraftServer server = MinecraftServer.getServer(); if (server != null) { - // 1.7.10 doesn't have addScheduledTask — just run directly if on main thread - // or queue via the server's next tick task.run(); } else { task.run(); diff --git a/src/main/java/noppes/npcs/wrapper/nbt/NBTListWrapper.java b/src/main/java/noppes/npcs/wrapper/nbt/NBTListWrapper.java index 551a8605f..31112d1a2 100644 --- a/src/main/java/noppes/npcs/wrapper/nbt/NBTListWrapper.java +++ b/src/main/java/noppes/npcs/wrapper/nbt/NBTListWrapper.java @@ -5,14 +5,14 @@ import net.minecraft.nbt.NBTTagFloat; import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagString; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; /** - * 1.7.10 implementation of INBTList. + * 1.7.10 implementation of INbtList. * Thin wrapper that delegates to NBTTagList. */ -public class NBTListWrapper implements INBTList { +public class NBTListWrapper implements INbtList { private final NBTTagList tag; @@ -36,7 +36,7 @@ public class NBTListWrapper implements INBTList { } @Override - public INBTCompound getCompound(int index) { + public INbt getCompound(int index) { return new NBTWrapper(tag.getCompoundTagAt(index)); } @@ -47,10 +47,6 @@ public class NBTListWrapper implements INBTList { @Override public int getInt(int index) { - // 1.7.10 doesn't have a direct getIntAt on NBTTagList. - // Parse from the string representation or use the compound approach. - // In practice, int lists are stored as compounds with "Slot" keys. - // For direct int tag lists, use getStringTagAt and parse. return Integer.parseInt(tag.getStringTagAt(index)); } @@ -77,7 +73,7 @@ public class NBTListWrapper implements INBTList { // --- Mutators --- @Override - public void addCompound(INBTCompound compound) { + public void addCompound(INbt compound) { tag.appendTag(((NBTWrapper) compound).getMCTag()); } @@ -104,7 +100,7 @@ public class NBTListWrapper implements INBTList { // --- Interop --- @Override - public Object getUnderlyingTag() { + public Object getMCTagList() { return tag; } } diff --git a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapper.java b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapper.java index 0c67ef1ce..38ac70771 100644 --- a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapper.java +++ b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapper.java @@ -1,17 +1,25 @@ package noppes.npcs.wrapper.nbt; +import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagInt; +import net.minecraft.nbt.NBTTagIntArray; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import net.minecraft.nbt.NBTTagString; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; +import noppes.npcs.util.NBTJsonUtil; +import java.util.Iterator; import java.util.Set; /** - * 1.7.10 implementation of INBTCompound. + * 1.7.10 implementation of the unified INbt interface. * Thin wrapper that delegates to NBTTagCompound. */ -public class NBTWrapper implements INBTCompound { +public class NBTWrapper implements INbt { private final NBTTagCompound tag; @@ -21,13 +29,13 @@ public class NBTWrapper implements INBTCompound { /** * Direct access to the underlying MC tag. - * For use within 1.7.10 code only — avoids the cast from getUnderlyingTag(). + * For use within 1.7.10 code only — avoids casting from getMCNBT(). */ public NBTTagCompound getMCTag() { return tag; } - // --- Setters --- + // ======================== Setters ======================== @Override public void setString(String key, String value) { @@ -80,21 +88,16 @@ public class NBTWrapper implements INBTCompound { } @Override - public void setCompound(String key, INBTCompound compound) { + public void setCompound(String key, INbt compound) { tag.setTag(key, ((NBTWrapper) compound).getMCTag()); } @Override - public void setTag(String key, INBTCompound compound) { - setCompound(key, compound); + public void setTagList(String key, INbtList list) { + tag.setTag(key, (NBTTagList) list.getMCTagList()); } - @Override - public void setList(String key, INBTList list) { - tag.setTag(key, (NBTTagList) list.getUnderlyingTag()); - } - - // --- Getters --- + // ======================== Getters ======================== @Override public String getString(String key) { @@ -147,16 +150,71 @@ public class NBTWrapper implements INBTCompound { } @Override - public INBTCompound getCompound(String key) { + public INbt getCompound(String key) { return new NBTWrapper(tag.getCompoundTag(key)); } @Override - public INBTList getList(String key, int type) { + public INbtList getTagList(String key, int type) { return new NBTListWrapper(tag.getTagList(key, type)); } - // --- Query --- + @Override + public Object[] getList(String key, int type) { + NBTTagList list = tag.getTagList(key, type); + Object[] result = new Object[list.tagCount()]; + for (int i = 0; i < list.tagCount(); i++) { + int elemType = list.func_150303_d(); + if (elemType == 10) { + result[i] = new NBTWrapper(list.getCompoundTagAt(i)); + } else if (elemType == 8) { + result[i] = list.getStringTagAt(i); + } else if (elemType == 6) { + result[i] = list.func_150309_d(i); + } else if (elemType == 5) { + result[i] = list.func_150308_e(i); + } else if (elemType == 3) { + result[i] = Integer.parseInt(list.getStringTagAt(i)); + } else if (elemType == 11) { + result[i] = list.func_150306_c(i); + } + } + return result; + } + + @Override + public void setList(String key, Object[] value) { + NBTTagList list = new NBTTagList(); + for (Object nbt : value) { + if (nbt instanceof INbt) { + list.appendTag((NBTTagCompound) ((INbt) nbt).getMCNBT()); + } else if (nbt instanceof String) { + list.appendTag(new NBTTagString((String) nbt)); + } else if (nbt instanceof Double) { + list.appendTag(new NBTTagDouble((Double) nbt)); + } else if (nbt instanceof Float) { + list.appendTag(new NBTTagFloat((Float) nbt)); + } else if (nbt instanceof Integer) { + list.appendTag(new NBTTagInt((Integer) nbt)); + } else if (nbt instanceof int[]) { + list.appendTag(new NBTTagIntArray((int[]) nbt)); + } + } + tag.setTag(key, list); + } + + @Override + public int getListType(String key) { + NBTBase b = tag.getTag(key); + if (b == null) { + return 0; + } else if (b.getId() != 9) { + return 0; + } + return ((NBTTagList) b).func_150303_d(); + } + + // ======================== Query ======================== @Override public boolean hasKey(String key) { @@ -189,10 +247,10 @@ public class NBTWrapper implements INBTCompound { return tag.hasNoTags(); } - // --- Interop --- + // ======================== Interop ======================== @Override - public void merge(INBTCompound other) { + public void merge(INbt other) { NBTTagCompound otherTag = ((NBTWrapper) other).getMCTag(); for (Object keyObj : otherTag.func_150296_c()) { String key = (String) keyObj; @@ -201,15 +259,36 @@ public class NBTWrapper implements INBTCompound { } @Override - public INBTCompound copy() { + public INbt copy() { return new NBTWrapper((NBTTagCompound) tag.copy()); } @Override - public Object getUnderlyingTag() { + public NBTTagCompound getMCNBT() { return tag; } + // ======================== Convenience ======================== + + @Override + public String toJsonString() { + return NBTJsonUtil.Convert(tag); + } + + @Override + public boolean isEqual(INbt nbt) { + return nbt != null && tag.equals(nbt.getMCNBT()); + } + + @Override + public void clear() { + Iterator it = tag.func_150296_c().iterator(); + while (it.hasNext()) { + it.next(); + it.remove(); + } + } + @Override public boolean equals(Object obj) { if (obj instanceof NBTWrapper) { diff --git a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperFactory.java b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperFactory.java index c5f885546..08284caf3 100644 --- a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperFactory.java +++ b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperFactory.java @@ -2,8 +2,8 @@ package noppes.npcs.wrapper.nbt; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import noppes.npcs.platform.nbt.INBTCompound; -import noppes.npcs.platform.nbt.INBTList; +import noppes.npcs.api.INbt; +import noppes.npcs.api.INbtList; import noppes.npcs.platform.nbt.NBTFactory; /** @@ -12,17 +12,17 @@ import noppes.npcs.platform.nbt.NBTFactory; public class NBTWrapperFactory implements NBTFactory { @Override - public INBTCompound createCompound() { + public INbt createCompound() { return new NBTWrapper(new NBTTagCompound()); } @Override - public INBTList createList() { + public INbtList createList() { return new NBTListWrapper(new NBTTagList()); } @Override - public INBTCompound wrap(Object mcNBTTagCompound) { + public INbt wrap(Object mcNBTTagCompound) { if (!(mcNBTTagCompound instanceof NBTTagCompound)) { throw new IllegalArgumentException( "Expected NBTTagCompound, got " + mcNBTTagCompound.getClass().getName() @@ -32,7 +32,7 @@ public class NBTWrapperFactory implements NBTFactory { } @Override - public INBTList wrapList(Object mcNBTTagList) { + public INbtList wrapList(Object mcNBTTagList) { if (!(mcNBTTagList instanceof NBTTagList)) { throw new IllegalArgumentException( "Expected NBTTagList, got " + mcNBTTagList.getClass().getName() diff --git a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperIO.java b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperIO.java index c4b9473ea..d3de5b9c1 100644 --- a/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperIO.java +++ b/src/main/java/noppes/npcs/wrapper/nbt/NBTWrapperIO.java @@ -2,7 +2,7 @@ package noppes.npcs.wrapper.nbt; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; -import noppes.npcs.platform.nbt.INBTCompound; +import noppes.npcs.api.INbt; import noppes.npcs.platform.nbt.NBTIO; import java.io.File; @@ -17,7 +17,7 @@ import java.io.IOException; public class NBTWrapperIO implements NBTIO { @Override - public INBTCompound readCompressed(File file) throws IOException { + public INbt readCompressed(File file) throws IOException { FileInputStream fis = new FileInputStream(file); try { NBTTagCompound tag = CompressedStreamTools.readCompressed(fis); @@ -28,7 +28,7 @@ public class NBTWrapperIO implements NBTIO { } @Override - public void writeCompressed(INBTCompound compound, File file) throws IOException { + public void writeCompressed(INbt compound, File file) throws IOException { NBTTagCompound tag = ((NBTWrapper) compound).getMCTag(); FileOutputStream fos = new FileOutputStream(file); try { @@ -39,15 +39,14 @@ public class NBTWrapperIO implements NBTIO { } @Override - public INBTCompound read(File file) throws IOException { + public INbt read(File file) throws IOException { NBTTagCompound tag = CompressedStreamTools.read(file); return new NBTWrapper(tag); } @Override - public void safeWrite(INBTCompound compound, File file) throws IOException { + public void safeWrite(INbt compound, File file) throws IOException { NBTTagCompound tag = ((NBTWrapper) compound).getMCTag(); - // 1.7.10 doesn't have safeWrite, implement with temp file File tempFile = new File(file.getAbsolutePath() + ".tmp"); FileOutputStream fos = new FileOutputStream(tempFile); try { @@ -55,7 +54,6 @@ public class NBTWrapperIO implements NBTIO { } finally { fos.close(); } - // Atomic rename if (file.exists()) { file.delete(); }