Add the Essential APIs

This commit is contained in:
Kam committed 2026-03-14 15:32:07 -04:00
1 parent 5e448c3324
commit 0833425d57
93 files changed
+4909 -1523

No files matched your search

@@ -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");
@@ -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");
@@ -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<String, Float> 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<String> keys = multNbt.getKeySet();
for (String key : keys) {
damageMultipliers.put(key, multNbt.getFloat(key));
@@ -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;
@@ -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;
@@ -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");
@@ -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;
@@ -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");
@@ -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;
@@ -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;
@@ -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"),
@@ -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<String, INBTCompound> components = new HashMap<>();
private Map<String, INbt> components = new HashMap<>();
public Slot(int id, String name) {
this.id = id;
this.name = name;
}
public Slot(int id, String name, long lastLoaded, boolean temporary, Map<String, INBTCompound> components) {
public Slot(int id, String name, long lastLoaded, boolean temporary, Map<String, INbt> components) {
this.id = id;
this.name = name;
this.lastLoaded = lastLoaded;
@@ -68,35 +68,35 @@ public class Slot implements ISlot {
}
@Override
public Map<String, INBTCompound> getComponents() {
public Map<String, INbt> 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<String, INBTCompound> entry : components.entrySet()) {
INbt compCompound = NBT.compound();
for (Map.Entry<String, INbt> 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<String> keys = compCompound.getKeySet();
for (String key : keys) {
slot.setComponentData(key, compCompound.getCompound(key));
@@ -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 {
+100 -100
View File
@@ -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<Integer, ItemStack>) - uses NoppesUtilServer.writeItem()
// OLD: nbtItemStackArray(ItemStack[]) - uses NoppesUtilServer.writeItem()
public static ArrayList<int[]> getIntegerArraySet(INBTList tagList) {
public static ArrayList<int[]> getIntegerArraySet(INbtList tagList) {
ArrayList<int[]> set = new ArrayList<int[]>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound compound = tagList.getCompound(i);
INbt compound = tagList.getCompound(i);
set.add(compound.getIntArray("Array"));
}
return set;
}
public static HashMap<Integer, Boolean> getBooleanList(INBTList tagList) {
public static HashMap<Integer, Boolean> getBooleanList(INbtList tagList) {
HashMap<Integer, Boolean> list = new HashMap<Integer, Boolean>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getBoolean("Boolean"));
}
return list;
}
public static HashMap<Integer, Integer> getIntegerIntegerMap(INBTList tagList) {
public static HashMap<Integer, Integer> getIntegerIntegerMap(INbtList tagList) {
HashMap<Integer, Integer> list = new HashMap<Integer, Integer>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getInteger("Integer"));
}
return list;
}
public static HashMap<Integer, Float> getIntegerFloatMap(INBTList tagList) {
public static HashMap<Integer, Float> getIntegerFloatMap(INbtList tagList) {
HashMap<Integer, Float> list = new HashMap<Integer, Float>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getFloat("Float"));
}
return list;
}
public static HashMap<Integer, Double> getIntegerDoubleMap(INBTList tagList) {
public static HashMap<Integer, Double> getIntegerDoubleMap(INbtList tagList) {
HashMap<Integer, Double> list = new HashMap<Integer, Double>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getDouble("Double"));
}
return list;
}
public static HashMap<Integer, Long> getIntegerLongMap(INBTList tagList) {
public static HashMap<Integer, Long> getIntegerLongMap(INbtList tagList) {
HashMap<Integer, Long> list = new HashMap<Integer, Long>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getLong("Long"));
}
return list;
}
public static HashSet<String> getStringSet(INBTList tagList) {
public static HashSet<String> getStringSet(INbtList tagList) {
HashSet<String> list = new HashSet<>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.add(nbttagcompound.getString("String"));
}
return list;
}
public static HashMap<Integer, Byte> getIntegerByteMap(INBTList tagList) {
public static HashMap<Integer, Byte> getIntegerByteMap(INbtList tagList) {
HashMap<Integer, Byte> list = new HashMap<Integer, Byte>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getByte("Byte"));
}
return list;
}
public static INBTList nbtIntegerByteMap(Map<Integer, Byte> lines) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerByteMap(Map<Integer, Byte> lines) {
INbtList nbttaglist = NBT.list();
if (lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<String> collection) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtStringSet(HashSet<String> 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<Integer> getIntegerSet(INBTList tagList) {
public static HashSet<Integer> getIntegerSet(INbtList tagList) {
HashSet<Integer> list = new HashSet<Integer>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.add(nbttagcompound.getInteger("Integer"));
}
return list;
}
public static INBTList nbtIntegerSet(HashSet<Integer> set) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerSet(HashSet<Integer> set) {
INbtList nbttaglist = NBT.list();
if (set == null)
return nbttaglist;
for (int slot : set) {
INBTCompound nbttagcompound = NBT.compound();
INbt nbttagcompound = NBT.compound();
nbttagcompound.setInteger("Integer", slot);
nbttaglist.addCompound(nbttagcompound);
}
return nbttaglist;
}
public static HashMap<String, String> getStringStringMap(INBTList tagList) {
public static HashMap<String, String> getStringStringMap(INbtList tagList) {
HashMap<String, String> list = new HashMap<String, String>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getString("Value"));
}
return list;
}
public static HashMap<Integer, String> getIntegerStringMap(INBTList tagList) {
public static HashMap<Integer, String> getIntegerStringMap(INbtList tagList) {
HashMap<Integer, String> list = new HashMap<Integer, String>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getInteger("Slot"), nbttagcompound.getString("Value"));
}
return list;
}
public static HashMap<String, Integer> getStringIntegerMap(INBTList tagList) {
public static HashMap<String, Integer> getStringIntegerMap(INbtList tagList) {
HashMap<String, Integer> list = new HashMap<String, Integer>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getInteger("Value"));
}
return list;
}
public static HashMap<String, int[]> getStringIntegerArrayMap(INBTList tagList) {
public static HashMap<String, int[]> getStringIntegerArrayMap(INbtList tagList) {
HashMap<String, int[]> list = new HashMap<String, int[]>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getString("Slot"), nbttagcompound.getIntArray("Value"));
}
return list;
}
public static HashMap<String, int[]> getStringIntegerArrayMap(INBTList tagList, int arrayLength) {
public static HashMap<String, int[]> getStringIntegerArrayMap(INbtList tagList, int arrayLength) {
HashMap<String, int[]> list = new HashMap<String, int[]>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
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<String, Vector<String>> getVectorMap(INBTList tagList) {
public static HashMap<String, Vector<String>> getVectorMap(INbtList tagList) {
HashMap<String, Vector<String>> map = new HashMap<String, Vector<String>>();
for (int i = 0; i < tagList.size(); i++) {
Vector<String> values = new Vector<String>();
INBTCompound nbttagcompound = tagList.getCompound(i);
INBTList list = nbttagcompound.getList("Values", 10);
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<String> getStringList(INBTList tagList) {
public static List<String> getStringList(INbtList tagList) {
List<String> list = new ArrayList<String>();
for (int i = 0; i < tagList.size(); i++) {
INBTCompound nbttagcompound = tagList.getCompound(i);
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<int[]> set) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerArraySet(List<int[]> 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<Integer, Boolean> updatedSlots) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtBooleanList(HashMap<Integer, Boolean> updatedSlots) {
INbtList nbttaglist = NBT.list();
if (updatedSlots == null)
return nbttaglist;
HashMap<Integer, Boolean> inventory2 = updatedSlots;
for (Integer slot : inventory2.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<Integer, Integer> lines) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerIntegerMap(Map<Integer, Integer> lines) {
INbtList nbttaglist = NBT.list();
if (lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<Integer, Float> lines) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerFloatMap(Map<Integer, Float> lines) {
INbtList nbttaglist = NBT.list();
if (lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<Integer, Double> lines) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerDoubleMap(Map<Integer, Double> lines) {
INbtList nbttaglist = NBT.list();
if (lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<Integer, Long> lines) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerLongMap(Map<Integer, Long> lines) {
INbtList nbttaglist = NBT.list();
if (lines == null)
return nbttaglist;
for (int slot : lines.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<String, Vector<String>> map) {
INBTList list = NBT.list();
public static INbtList nbtVectorMap(Map<String, Vector<String>> map) {
INbtList list = NBT.list();
if (map == null)
return list;
for (String key : map.keySet()) {
INBTCompound compound = NBT.compound();
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<String, String> map) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtStringStringMap(Map<String, String> map) {
INbtList nbttaglist = NBT.list();
if (map == null)
return nbttaglist;
for (String slot : map.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<String, Integer> map) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtStringIntegerMap(Map<String, Integer> map) {
INbtList nbttaglist = NBT.list();
if (map == null)
return nbttaglist;
for (String slot : map.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<String, int[]> map) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtStringIntegerArrayMap(Map<String, int[]> map) {
INbtList nbttaglist = NBT.list();
if (map == null)
return nbttaglist;
for (String slot : map.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<Integer, String> map) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtIntegerStringMap(HashMap<Integer, String> map) {
INbtList nbttaglist = NBT.list();
if (map == null)
return nbttaglist;
for (int slot : map.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
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<String> list) {
INBTList nbttaglist = NBT.list();
public static INbtList nbtStringList(List<String> 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<String> 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<Long, String> GetLongStringMap(INBTList tagList) {
public static TreeMap<Long, String> GetLongStringMap(INbtList tagList) {
TreeMap<Long, String> list = new TreeMap<>();
for (int i = 0; i < tagList.size(); ++i) {
INBTCompound nbttagcompound = tagList.getCompound(i);
INbt nbttagcompound = tagList.getCompound(i);
list.put(nbttagcompound.getLong("Long"), nbttagcompound.getString("String"));
}
return list;
}
public static INBTList NBTLongStringMap(Map<Long, String> map) {
INBTList nbttaglist = NBT.list();
public static INbtList NBTLongStringMap(Map<Long, String> map) {
INbtList nbttaglist = NBT.list();
if (map == null) {
return nbttaglist;
} else {
for (long slot : map.keySet()) {
INBTCompound nbttagcompound = NBT.compound();
INbt nbttagcompound = NBT.compound();
nbttagcompound.setLong("Long", slot);
nbttagcompound.setString("String", map.get(slot));
nbttaglist.addCompound(nbttagcompound);
@@ -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 {
@@ -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<Integer, Faction> factions = new HashMap<Integer, Faction>();
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;
}
@@ -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");
@@ -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;
}
@@ -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);
}
@@ -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<Integer, Tag> tags = new HashMap<Integer, Tag>();
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<UUID> tagUUIDs) {
public static void writeTagUUIDs(INbt compound, String key, HashSet<UUID> 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<UUID> readTagUUIDs(INBTCompound compound, String key) {
public static HashSet<UUID> readTagUUIDs(INbt compound, String key) {
HashSet<UUID> 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)));
@@ -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<Integer, TransportLocation> locations = new HashMap<Integer, TransportLocation>();
@@ -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;
}
@@ -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");
}
@@ -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"));
@@ -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;
@@ -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;
@@ -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");
@@ -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");
@@ -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:
@@ -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<EnumAnimationPart, FramePart> 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;
}
@@ -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]);
@@ -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");
@@ -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);
}
@@ -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<Integer, Line> lines = new HashMap<Integer, Line>();
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<Integer, Line> map = new HashMap<Integer, Line>();
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");
@@ -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<Integer, Float> 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()) {
@@ -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() {
@@ -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<Integer, MagicEntry> 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;
@@ -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");
}
@@ -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);
@@ -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<Integer> dialogsRead = new HashSet<Integer>();
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) {
@@ -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<EffectKey, PlayerEffect> 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<EffectKey> 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");
@@ -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<Integer> dialogsRead = new HashSet<Integer>();
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) {
@@ -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());
@@ -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());
@@ -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());
}
@@ -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<String, HashSet<UUID>>();
}
public void readNBT(INBTCompound compound) {
public void readNBT(INbt compound) {
this.tagMap = new HashMap<String, HashSet<UUID>>();
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<UUID> uuids = new HashSet<UUID>();
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<UUID> 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;
}
@@ -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");
@@ -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<String, PlayerTraderStock> 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;
@@ -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() {
@@ -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);
+5 -5
View File
@@ -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();
}
}
@@ -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;
@@ -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);
}
@@ -1,4 +1,4 @@
package noppes.npcs.platform;
package kamkeel.npcs.platform;
/**
* Static accessor for the active {@link PlatformService} implementation.
@@ -1,4 +1,4 @@
package noppes.npcs.platform.config;
package kamkeel.npcs.platform.config;
/**
* Version-independent abstraction over Minecraft Forge's Configuration system.
@@ -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();
}
@@ -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();
}
@@ -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);
}
@@ -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();
}
@@ -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();
}
@@ -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();
}
@@ -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();
}
@@ -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()}).
*
* <p>Compound tags contain uniquely-keyed tags of various types:
* <pre>
* 1: Byte 2: Short 3: Int 4: Long
* 5: Float 6: Double 7: Byte[] 8: String
* 9: List 10: Compound 11: Int[]
* </pre>
*/
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<String> 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();
}
@@ -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();
}
@@ -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 &amp; 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 &amp; 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);
}
@@ -0,0 +1,8 @@
package noppes.npcs.api.entity;
import noppes.npcs.api.handler.data.IAnimationData;
public interface IAnimatable {
IAnimationData getAnimationData();
}
File diff suppressed because it is too large. Load diff
@@ -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();
}
@@ -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();
}
@@ -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);
}
@@ -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();
}
@@ -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<IAnimation> task);
IAnimation onFrame(BiConsumer<Integer, IAnimation> task);
IAnimation onEnd(Consumer<IAnimation> task);
}
@@ -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();
}
@@ -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<String, INBTCompound> getComponents();
Map<String, INbt> 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();
}
@@ -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.
* <p>No support is given for this method. Use with caution.</p>
*
* @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);
}
@@ -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);
}
@@ -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<String> 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();
}
@@ -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();
}
@@ -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);
}
@@ -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;
}
+1 -1
Submodule src/api updated: f91e17ab3e...5cb3a5beef.
@@ -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;
}
}
@@ -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;
}
}
@@ -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);
}
}
@@ -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());
}
}
@@ -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;
}
}
@@ -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;
}
}
+1 -1
View File
@@ -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;
+199 -127
View File
@@ -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<String> getKeySet() {
return (Set<String>) 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();
}
}
}
@@ -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();
@@ -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;
}
}
@@ -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) {
@@ -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()
@@ -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();
}