use of net.minecraft.nbt.NBTTagCompound in project MinecraftForge by MinecraftForge.
the class DimensionManager method saveDimensionDataMap.
public static NBTTagCompound saveDimensionDataMap() {
int[] data = new int[(dimensionMap.length() + Integer.SIZE - 1) / Integer.SIZE];
NBTTagCompound dimMap = new NBTTagCompound();
for (int i = 0; i < data.length; i++) {
int val = 0;
for (int j = 0; j < Integer.SIZE; j++) {
val |= dimensionMap.get(i * Integer.SIZE + j) ? (1 << j) : 0;
}
data[i] = val;
}
dimMap.setIntArray("DimensionArray", data);
return dimMap;
}
use of net.minecraft.nbt.NBTTagCompound 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.NBTTagCompound 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.NBTTagCompound in project MinecraftForge by MinecraftForge.
the class FMLClientHandler method tryLoadExistingWorld.
public void tryLoadExistingWorld(GuiWorldSelection selectWorldGUI, WorldSummary comparator) {
File dir = new File(getSavesDir(), comparator.getFileName());
NBTTagCompound leveldat;
try {
leveldat = CompressedStreamTools.readCompressed(new FileInputStream(new File(dir, "level.dat")));
} catch (Exception e) {
try {
leveldat = CompressedStreamTools.readCompressed(new FileInputStream(new File(dir, "level.dat_old")));
} catch (Exception e1) {
FMLLog.warning("There appears to be a problem loading the save %s, both level files are unreadable.", comparator.getFileName());
return;
}
}
NBTTagCompound fmlData = leveldat.getCompoundTag("FML");
if (fmlData.hasKey("ModItemData")) {
showGuiScreen(new GuiOldSaveLoadConfirm(comparator.getFileName(), comparator.getDisplayName(), selectWorldGUI));
} else {
try {
client.launchIntegratedServer(comparator.getFileName(), comparator.getDisplayName(), null);
} catch (StartupQuery.AbortedException e) {
// ignore
}
}
}
use of net.minecraft.nbt.NBTTagCompound in project MinecraftForge by MinecraftForge.
the class GameRegistry method makeItemStack.
/**
* Makes an {@link ItemStack} based on the itemName reference, with supplied meta, stackSize and nbt, if possible
* <p/>
* Will return null if the item doesn't exist (because it's not from a loaded mod for example)
* Will throw a {@link RuntimeException} if the nbtString is invalid for use in an {@link ItemStack}
*
* @param itemName a registry name reference
* @param meta the meta
* @param stackSize the stack size
* @param nbtString an nbt stack as a string, will be processed by {@link JsonToNBT}
* @return a new itemstack
*/
@Nonnull
public static ItemStack makeItemStack(String itemName, int meta, int stackSize, String nbtString) {
if (itemName == null) {
throw new IllegalArgumentException("The itemName cannot be null");
}
Item item = GameData.getItemRegistry().getObject(new ResourceLocation(itemName));
if (item == null) {
FMLLog.getLogger().log(Level.TRACE, "Unable to find item with name {}", itemName);
return ItemStack.EMPTY;
}
ItemStack is = new ItemStack(item, stackSize, meta);
if (!Strings.isNullOrEmpty(nbtString)) {
NBTBase nbttag = null;
try {
nbttag = JsonToNBT.getTagFromJson(nbtString);
} catch (NBTException e) {
FMLLog.getLogger().log(Level.WARN, "Encountered an exception parsing ItemStack NBT string {}", nbtString, e);
throw Throwables.propagate(e);
}
if (!(nbttag instanceof NBTTagCompound)) {
FMLLog.getLogger().log(Level.WARN, "Unexpected NBT string - multiple values {}", nbtString);
throw new RuntimeException("Invalid NBT JSON");
} else {
is.setTagCompound((NBTTagCompound) nbttag);
}
}
return is;
}
Aggregations