Search in sources :

Example 1 with IntegratedServer

use of net.minecraft.server.integrated.IntegratedServer 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

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