use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class FluidHandlerItemStackSimple method setFluid.
protected void setFluid(FluidStack fluid) {
if (!container.hasTag()) {
container.setTag(new CompoundTag());
}
CompoundTag fluidTag = new CompoundTag();
fluid.writeToNBT(fluidTag);
container.getTag().put(FLUID_NBT_KEY, fluidTag);
}
use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class ItemStackHandler method serializeNBT.
@Override
public CompoundTag serializeNBT() {
ListTag nbtTagList = new ListTag();
for (int i = 0; i < stacks.size(); i++) {
if (!stacks.get(i).isEmpty()) {
CompoundTag itemTag = new CompoundTag();
itemTag.putInt("Slot", i);
stacks.get(i).save(itemTag);
nbtTagList.add(itemTag);
}
}
CompoundTag nbt = new CompoundTag();
nbt.put("Items", nbtTagList);
nbt.putInt("Size", stacks.size());
return nbt;
}
use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class ItemStackHandler method deserializeNBT.
@Override
public void deserializeNBT(CompoundTag nbt) {
setSize(nbt.contains("Size", Tag.TAG_INT) ? nbt.getInt("Size") : stacks.size());
ListTag tagList = nbt.getList("Items", Tag.TAG_COMPOUND);
for (int i = 0; i < tagList.size(); i++) {
CompoundTag itemTags = tagList.getCompound(i);
int slot = itemTags.getInt("Slot");
if (slot >= 0 && slot < stacks.size()) {
stacks.set(slot, ItemStack.of(itemTags));
}
}
onLoad();
}
use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class FluidHandlerItemStack method setFluid.
protected void setFluid(FluidStack fluid) {
if (!container.hasTag()) {
container.setTag(new CompoundTag());
}
CompoundTag fluidTag = new CompoundTag();
fluid.writeToNBT(fluidTag);
container.getTag().put(FLUID_NBT_KEY, fluidTag);
}
use of net.minecraft.nbt.CompoundTag in project MinecraftForge by MinecraftForge.
the class ForgeChunkManager method writeForcedChunkOwners.
private static <T extends Comparable<? super T>> void writeForcedChunkOwners(Map<String, Long2ObjectMap<CompoundTag>> forcedEntries, Map<TicketOwner<T>, LongSet> forcedChunks, String listKey, int listType, BiConsumer<T, ListTag> ownerWriter) {
for (Map.Entry<TicketOwner<T>, LongSet> entry : forcedChunks.entrySet()) {
Long2ObjectMap<CompoundTag> modForced = forcedEntries.computeIfAbsent(entry.getKey().modId, modId -> new Long2ObjectOpenHashMap<>());
for (long chunk : entry.getValue()) {
CompoundTag modEntry = modForced.computeIfAbsent(chunk, chunkPos -> {
CompoundTag baseEntry = new CompoundTag();
baseEntry.putLong("Chunk", chunkPos);
return baseEntry;
});
ListTag ownerList = modEntry.getList(listKey, listType);
ownerWriter.accept(entry.getKey().owner, ownerList);
// Note: As getList returns a new list in the case the data is of the wrong type,
// we need to mimic was vanilla does in various places and put our list back in
// the CompoundNBT regardless.
modEntry.put(listKey, ownerList);
}
}
}
Aggregations