Search in sources :

Example 1 with ISaveFormat

use of net.minecraft.world.storage.ISaveFormat in project malmo by Microsoft.

the class MapFileHelper method cleanupTemporaryWorlds.

/**
 * Attempts to delete all Minecraft Worlds with "TEMP_" in front of the name
 * @param currentWorld excludes this world from deletion, can be null
 */
public static void cleanupTemporaryWorlds(String currentWorld) {
    List<WorldSummary> saveList;
    ISaveFormat isaveformat = Minecraft.getMinecraft().getSaveLoader();
    isaveformat.flushCache();
    try {
        saveList = isaveformat.getSaveList();
    } catch (AnvilConverterException e) {
        e.printStackTrace();
        return;
    }
    String searchString = tempMark + AddressHelper.getMissionControlPort() + "_";
    for (WorldSummary s : saveList) {
        String folderName = s.getFileName();
        if (folderName.startsWith(searchString) && !folderName.equals(currentWorld)) {
            isaveformat.deleteWorldDirectory(folderName);
        }
    }
}
Also used : WorldSummary(net.minecraft.world.storage.WorldSummary) ISaveFormat(net.minecraft.world.storage.ISaveFormat) AnvilConverterException(net.minecraft.client.AnvilConverterException)

Example 2 with ISaveFormat

use of net.minecraft.world.storage.ISaveFormat in project malmo by Microsoft.

the class FileWorldGeneratorImplementation method createWorld.

@Override
public boolean createWorld(MissionInit missionInit) {
    if (this.mapFilename == null || this.mapFilename.length() == 0) {
        this.errorDetails = "No basemap URI provided - check your Mission XML.";
        return false;
    }
    File mapSource = new File(this.mapFilename);
    if (!mapSource.exists()) {
        this.errorDetails = "Basemap file " + this.mapFilename + " was not found - check your Mission XML and ensure the file exists on the Minecraft client machine.";
        return false;
    }
    if (!mapSource.isDirectory()) {
        this.errorDetails = "Basemap location " + this.mapFilename + " needs to be a folder. Check the path in your Mission XML.";
        return false;
    }
    File mapCopy = MapFileHelper.copyMapFiles(mapSource, this.fwparams.isDestroyAfterUse());
    if (mapCopy == null) {
        this.errorDetails = "Unable to copy " + this.mapFilename + " - is the hard drive full?";
        return false;
    }
    if (!Minecraft.getMinecraft().getSaveLoader().canLoadWorld(mapCopy.getName())) {
        this.errorDetails = "Minecraft is unable to load " + this.mapFilename + " - is it a valid saved world?";
        return false;
    }
    ISaveFormat isaveformat = Minecraft.getMinecraft().getSaveLoader();
    List<WorldSummary> worldlist;
    try {
        worldlist = isaveformat.getSaveList();
    } catch (AnvilConverterException anvilconverterexception) {
        this.errorDetails = "Minecraft couldn't rebuild saved world list.";
        return false;
    }
    WorldSummary newWorld = null;
    for (WorldSummary ws : worldlist) {
        if (ws.getFileName().equals(mapCopy.getName()))
            newWorld = ws;
    }
    if (newWorld == null) {
        this.errorDetails = "Minecraft could not find the copied world.";
        return false;
    }
    net.minecraftforge.fml.client.FMLClientHandler.instance().tryLoadExistingWorld(null, newWorld);
    IntegratedServer server = Minecraft.getMinecraft().getIntegratedServer();
    String worldName = (server != null) ? server.getWorldName() : null;
    if (worldName == null || !worldName.equals(newWorld.getDisplayName())) {
        this.errorDetails = "Minecraft could not load " + this.mapFilename + " - is it a valid saved world?";
        return false;
    }
    // Now we are safely running a new file, we can attempt to clean up old ones.
    MapFileHelper.cleanupTemporaryWorlds(mapCopy.getName());
    return true;
}
Also used : IntegratedServer(net.minecraft.server.integrated.IntegratedServer) ISaveFormat(net.minecraft.world.storage.ISaveFormat) WorldSummary(net.minecraft.world.storage.WorldSummary) AnvilConverterException(net.minecraft.client.AnvilConverterException) File(java.io.File)

Aggregations

AnvilConverterException (net.minecraft.client.AnvilConverterException)2 ISaveFormat (net.minecraft.world.storage.ISaveFormat)2 WorldSummary (net.minecraft.world.storage.WorldSummary)2 File (java.io.File)1 IntegratedServer (net.minecraft.server.integrated.IntegratedServer)1