use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.
the class FluidRegistry method loadFluidDefaults.
public static void loadFluidDefaults(NBTTagCompound tag) {
Set<String> defaults = Sets.newHashSet();
if (tag.hasKey("DefaultFluidList", 9)) {
FMLLog.getLogger().log(Level.DEBUG, "Loading persistent fluid defaults from world");
NBTTagList tl = tag.getTagList("DefaultFluidList", 8);
for (int i = 0; i < tl.tagCount(); i++) {
defaults.add(tl.getStringTagAt(i));
}
} else {
FMLLog.getLogger().log(Level.DEBUG, "World is missing persistent fluid defaults - using local defaults");
}
loadFluidDefaults(HashBiMap.create(fluidIDs), defaults);
}
use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.
the class ForgeChunkManager method saveWorld.
static void saveWorld(World world) {
// only persist persistent worlds
if (!(world instanceof WorldServer)) {
return;
}
WorldServer worldServer = (WorldServer) world;
File chunkDir = worldServer.getChunkSaveLocation();
File chunkLoaderData = new File(chunkDir, "forcedchunks.dat");
NBTTagCompound forcedChunkData = new NBTTagCompound();
NBTTagList ticketList = new NBTTagList();
forcedChunkData.setTag("TicketList", ticketList);
Multimap<String, Ticket> ticketSet = tickets.get(worldServer);
if (ticketSet == null)
return;
for (String modId : ticketSet.keySet()) {
NBTTagCompound ticketHolder = new NBTTagCompound();
ticketList.appendTag(ticketHolder);
ticketHolder.setString("Owner", modId);
NBTTagList tickets = new NBTTagList();
ticketHolder.setTag("Tickets", tickets);
for (Ticket tick : ticketSet.get(modId)) {
NBTTagCompound ticket = new NBTTagCompound();
ticket.setByte("Type", (byte) tick.ticketType.ordinal());
ticket.setByte("ChunkListDepth", (byte) tick.maxDepth);
if (tick.isPlayerTicket()) {
ticket.setString("ModId", tick.modId);
ticket.setString("Player", tick.player);
}
if (tick.modData != null) {
ticket.setTag("ModData", tick.modData);
}
if (tick.ticketType == Type.ENTITY && tick.entity != null && tick.entity.writeToNBTOptional(new NBTTagCompound())) {
ticket.setInteger("chunkX", MathHelper.floor(tick.entity.chunkCoordX));
ticket.setInteger("chunkZ", MathHelper.floor(tick.entity.chunkCoordZ));
ticket.setLong("PersistentIDMSB", tick.entity.getPersistentID().getMostSignificantBits());
ticket.setLong("PersistentIDLSB", tick.entity.getPersistentID().getLeastSignificantBits());
tickets.appendTag(ticket);
} else if (tick.ticketType != Type.ENTITY) {
tickets.appendTag(ticket);
}
}
}
try {
CompressedStreamTools.write(forcedChunkData, chunkLoaderData);
} catch (IOException e) {
FMLLog.log(Level.WARN, e, "Unable to write forced chunk data to %s - chunkloading won't work", chunkLoaderData.getAbsolutePath());
return;
}
}
use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.
the class FMLContainer method getDataForWriting.
@Override
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info) {
NBTTagCompound fmlData = new NBTTagCompound();
NBTTagList modList = new NBTTagList();
for (ModContainer mc : Loader.instance().getActiveModList()) {
NBTTagCompound mod = new NBTTagCompound();
mod.setString("ModId", mc.getModId());
mod.setString("ModVersion", mc.getVersion());
modList.appendTag(mod);
}
fmlData.setTag("ModList", modList);
NBTTagCompound registries = new NBTTagCompound();
fmlData.setTag("Registries", registries);
FMLLog.fine("Gathering id map for writing to world save %s", info.getWorldName());
PersistentRegistryManager.GameDataSnapshot dataSnapshot = PersistentRegistryManager.takeSnapshot();
for (Map.Entry<ResourceLocation, PersistentRegistryManager.GameDataSnapshot.Entry> e : dataSnapshot.entries.entrySet()) {
NBTTagCompound data = new NBTTagCompound();
registries.setTag(e.getKey().toString(), data);
NBTTagList ids = new NBTTagList();
for (Entry<ResourceLocation, Integer> item : e.getValue().ids.entrySet()) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("K", item.getKey().toString());
tag.setInteger("V", item.getValue());
ids.appendTag(tag);
}
data.setTag("ids", ids);
NBTTagList aliases = new NBTTagList();
for (Entry<ResourceLocation, ResourceLocation> entry : e.getValue().aliases.entrySet()) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("K", entry.getKey().toString());
tag.setString("V", entry.getValue().toString());
aliases.appendTag(tag);
}
data.setTag("aliases", aliases);
NBTTagList subs = new NBTTagList();
for (ResourceLocation entry : e.getValue().substitutions) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("K", entry.toString());
subs.appendTag(tag);
}
data.setTag("substitutions", subs);
int[] blocked = new int[e.getValue().blocked.size()];
int idx = 0;
for (Integer i : e.getValue().blocked) {
blocked[idx++] = i;
}
data.setIntArray("blocked", blocked);
NBTTagList dummied = new NBTTagList();
for (ResourceLocation entry : e.getValue().dummied) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString("K", entry.toString());
dummied.appendTag(tag);
}
data.setTag("dummied", dummied);
}
return fmlData;
}
use of net.minecraft.nbt.NBTTagList in project MinecraftForge by MinecraftForge.
the class ItemStackHandler method serializeNBT.
@Override
public NBTTagCompound serializeNBT() {
NBTTagList nbtTagList = new NBTTagList();
for (int i = 0; i < stacks.size(); i++) {
if (!stacks.get(i).isEmpty()) {
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setInteger("Slot", i);
stacks.get(i).writeToNBT(itemTag);
nbtTagList.appendTag(itemTag);
}
}
NBTTagCompound nbt = new NBTTagCompound();
nbt.setTag("Items", nbtTagList);
nbt.setInteger("Size", stacks.size());
return nbt;
}
use of net.minecraft.nbt.NBTTagList in project Minechem by iopleke.
the class AugmentedItem method getAugments.
@Override
public Map<IAugment, Integer> getAugments(ItemStack stack) {
Map<IAugment, Integer> result = new HashMap<IAugment, Integer>();
if (stack.hasTagCompound() && stack.getTagCompound().hasKey(augmentList, Compendium.NBTTags.tagList)) {
NBTTagList augments = stack.getTagCompound().getTagList(augmentList, Compendium.NBTTags.tagString);
for (int i = 0; i < augments.tagCount(); i++) {
String key = augments.getStringTagAt(i);
result.put(AugmentRegistry.getAugment(key), (int) stack.getTagCompound().getCompoundTag(key).getByte(level));
}
}
return result;
}
Aggregations