mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-21 09:12:22 +00:00
Magic for PlayerData and NPCs
This commit is contained in:
1 parent
d4eddf4551
commit
7a16cdf520
7 files changed
+178
-70
No files matched your search
@@ -0,0 +1,79 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import noppes.npcs.api.handler.data.IMagicData;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MagicData implements IMagicData {
|
||||
private HashMap<Integer, MagicEntry> magics = new HashMap<>();
|
||||
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound magicData = new NBTTagCompound();
|
||||
for (int key : magics.keySet()) {
|
||||
magicData.setTag(String.valueOf(key), magics.get(key).writeToNBT());
|
||||
}
|
||||
compound.setTag("MagicData", magicData);
|
||||
}
|
||||
|
||||
public void readToNBT(NBTTagCompound compound) {
|
||||
NBTTagCompound magicData = compound.getCompoundTag("MagicData");
|
||||
magics.clear();
|
||||
if(magicData == null)
|
||||
return;
|
||||
for (Object key : magicData.func_150296_c()) {
|
||||
int i = Integer.parseInt((String) key);
|
||||
MagicEntry entry = new MagicEntry();
|
||||
entry.readToNBT(magicData.getCompoundTag((String) key));
|
||||
magics.put(i, entry);
|
||||
}
|
||||
}
|
||||
|
||||
public MagicEntry getMagic(int id) {
|
||||
return magics.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeMagic(int id) {
|
||||
magics.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMagic(int id) {
|
||||
return magics.containsKey(id);
|
||||
}
|
||||
|
||||
public HashMap<Integer, MagicEntry> getMagics() {
|
||||
return magics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
magics.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return magics.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMagic(int id, float damage, float split) {
|
||||
MagicEntry entry = new MagicEntry();
|
||||
entry.damage = damage;
|
||||
entry.split = split;
|
||||
magics.put(id, entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMagicDamage(int id) {
|
||||
MagicEntry entry = magics.get(id);
|
||||
return entry == null ? 0 : entry.damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMagicSplit(int id) {
|
||||
MagicEntry entry = magics.get(id);
|
||||
return entry == null ? 0 : entry.split;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class MagicEntry {
|
||||
public float damage;
|
||||
public float split;
|
||||
|
||||
public NBTTagCompound writeToNBT() {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setFloat("Dmg", damage);
|
||||
compound.setFloat("Split", split);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public void readToNBT(NBTTagCompound compound) {
|
||||
damage = compound.getFloat("Dmg");
|
||||
split = compound.getFloat("Split");
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
public PlayerEffectData effectData = new PlayerEffectData(this);
|
||||
public DataTimers timers = new DataTimers(this);
|
||||
public DataSkinOverlays skinOverlays = new DataSkinOverlays(this);
|
||||
public MagicData magicData = new MagicData();
|
||||
|
||||
public EntityNPCInterface editingNpc;
|
||||
public NBTTagCompound cloned;
|
||||
@@ -115,6 +116,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
skinOverlays.readFromNBT(data);
|
||||
animationData.readFromNBT(data);
|
||||
effectData.readFromNBT(data);
|
||||
magicData.readToNBT(data);
|
||||
|
||||
if(player != null){
|
||||
playername = player.getCommandSenderName();
|
||||
@@ -156,6 +158,7 @@ public class PlayerData implements IExtendedEntityProperties, IPlayerData {
|
||||
skinOverlays.writeToNBT(compound);
|
||||
animationData.writeToNBT(compound);
|
||||
effectData.writeToNBT(compound);
|
||||
magicData.writeToNBT(compound);
|
||||
|
||||
compound.setString("PlayerName", playername);
|
||||
compound.setString("UUID", uuid);
|
||||
|
||||
Reference in new issue
Block a user