use of net.minecraftforge.common.util.INBTSerializable in project minecolonies by Minecolonies.
the class AbstractCombinedItemHandler method deserializeNBT.
@SuppressWarnings({ RAWTYPES, UNCHECKED })
@Override
public void deserializeNBT(final NBTTagCompound nbt) {
final NBTTagList handlerList = nbt.getTagList(NBT_KEY_NAME, Constants.NBT.TAG_COMPOUND);
final NBTTagList indexList = nbt.getTagList(NBT_KEY_HANDLERS_INDEXLIST, Constants.NBT.TAG_INT);
if (handlerList.tagCount() == handlers.length) {
for (int i = 0; i < handlerList.tagCount(); i++) {
final NBTTagCompound handlerCompound = handlerList.getCompoundTagAt(i);
final IItemHandlerModifiable modifiable = handlers[indexList.getIntAt(i)];
if (modifiable instanceof INBTSerializable) {
final INBTSerializable serializable = (INBTSerializable) modifiable;
serializable.deserializeNBT(handlerCompound);
}
}
}
setName(nbt.hasKey(NBT_KEY_NAME) ? nbt.getString(NBT_KEY_NAME) : null);
}
use of net.minecraftforge.common.util.INBTSerializable in project minecolonies by Minecolonies.
the class AbstractCombinedItemHandler method serializeNBT.
@SuppressWarnings(RAWTYPES)
@Override
public NBTTagCompound serializeNBT() {
final NBTTagCompound compound = new NBTTagCompound();
int index = 0;
final NBTTagList handlerList = new NBTTagList();
final NBTTagList indexList = new NBTTagList();
for (final IItemHandlerModifiable handlerModifiable : handlers) {
if (handlerModifiable instanceof INBTSerializable) {
final INBTSerializable serializable = (INBTSerializable) handlerModifiable;
handlerList.appendTag(serializable.serializeNBT());
indexList.appendTag(new NBTTagInt(index));
}
index++;
}
compound.setTag(NBT_KEY_HANDLERS, handlerList);
if (hasCustomName()) {
compound.setString(NBT_KEY_NAME, customName);
}
return compound;
}
Aggregations