I'm having trouble finding a method of iterating through an NBTTagCompound. It seems like I'm finding this a lot more difficult than it should be. I'm trying to use it in the following code:
public static class QubHealthStorage implements Capability.IStorage<IQubHealth>
{
@Nullable
@Override
public NBTBase writeNBT(Capability<IQubHealth> capability, IQubHealth instance, EnumFacing side) {
return new NBTTagInt(instance.get());
}
@Override
public void readNBT(Capability<IQubHealth> capability, IQubHealth instance, EnumFacing side, NBTBase nbt) {
if (nbt instanceof NBTTagInt)
{
// The state is being loaded and not updated. We set the value silently to avoid unnecessary dirty chunks
instance.set(((NBTTagInt) nbt).getInt(), false);
}
}
}
That's the int implementation.
This is what I have in my current Map implementation
public static class QubHealthStorage implements Capability.IStorage<IQubHealth>
{
@Nullable
@Override
public NBTBase writeNBT(Capability<IQubHealth> capability, IQubHealth instance, EnumFacing side) {
NBTTagCompound compound = new NBTTagCompound();
for (Entry<BlockPos, Integer> entry : instance.get().entrySet())
{
compound.setInteger(entry.getKey().toString(), entry.getValue());
}
return compound;
}
@Override
public void readNBT(Capability<IQubHealth> capability, IQubHealth instance, EnumFacing side, NBTBase nbt) {
if (nbt instanceof NBTTagCompound)
{
//iterate through compound and set values
}
}
}
Seems like it'll end up being a lot less hassle, thanks.