Files
CustomNPC-Plus/src/main/java/kamkeel/npcs/controllers/data/Profile.java
T

56 lines
1.9 KiB
Java
Raw Normal View History

2025-01-29 13:20:04 -05:00
package kamkeel.npcs.controllers.data;
2025-01-23 16:10:01 -05:00
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import java.util.HashMap;
import java.util.Set;
public class Profile {
public EntityPlayer player;
public int currentID;
public HashMap<Integer, Slot> slots = new HashMap<>();
2025-02-18 22:22:40 -05:00
public boolean locked = false;
2025-01-23 16:10:01 -05:00
2025-02-18 22:22:40 -05:00
public Profile(EntityPlayer player, NBTTagCompound compound) {
2025-01-23 16:10:01 -05:00
this.player = player;
if(compound.hasKey("CurrentID")){
this.currentID = compound.getInteger("CurrentID");
} else {
2025-02-18 06:25:09 -05:00
this.currentID = 0;
2025-01-23 16:10:01 -05:00
}
2025-02-18 22:22:40 -05:00
if(compound.hasKey("Slots")) {
2025-01-23 16:10:01 -05:00
NBTTagCompound slotsCompound = compound.getCompoundTag("Slots");
2025-02-18 22:22:40 -05:00
for(String key : (Set<String>) slotsCompound.func_150296_c()){
2025-01-23 16:10:01 -05:00
int slotID = Integer.parseInt(key);
NBTTagCompound slotNBT = slotsCompound.getCompoundTag(key);
Slot slot = Slot.fromNBT(slotID, slotNBT);
slots.put(slotID, slot);
}
}
}
public NBTTagCompound writeToNBT() {
NBTTagCompound fullCompound = new NBTTagCompound();
if(this.player != null)
fullCompound.setString("Name", player.getCommandSenderName());
fullCompound.setInteger("CurrentID", currentID);
if(!slots.isEmpty()){
NBTTagCompound slotsCompound = new NBTTagCompound();
for (HashMap.Entry<Integer, Slot> entry : slots.entrySet()) {
Slot slot = entry.getValue();
2025-02-18 06:25:09 -05:00
if(slot.isTemporary())
2025-02-18 22:22:40 -05:00
continue;
2025-02-18 06:25:09 -05:00
int id = entry.getKey();
2025-01-23 16:10:01 -05:00
slot.setId(id);
NBTTagCompound slotTag = slot.toNBT();
slotsCompound.setTag(String.valueOf(id), slotTag);
}
fullCompound.setTag("Slots", slotsCompound);
}
return fullCompound;
}
}