Search in sources :

Example 1 with WorldSummary

use of net.minecraft.world.storage.WorldSummary 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 WorldSummary

use of net.minecraft.world.storage.WorldSummary 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)

Example 3 with WorldSummary

use of net.minecraft.world.storage.WorldSummary in project FoamFix by asiekierka.

the class PleaseTrustMeLookImADolphin method onGuiActive.

@SubscribeEvent
@SuppressWarnings("unchecked")
public void onGuiActive(GuiScreenEvent.DrawScreenEvent.Pre event) {
    try {
        if (event.getGui() instanceof GuiWorldSelection) {
            initialize();
            GuiWorldSelection gws = (GuiWorldSelection) event.getGui();
            GuiListWorldSelection gwls = (GuiListWorldSelection) gwls_f.get(gws);
            List<GuiListWorldSelectionEntry> lglwse = (List<GuiListWorldSelectionEntry>) lglwse_f.get(gwls);
            if (gwls.getSelectedWorld() instanceof TotallyADolphinEntry) {
                for (int i = 0; i < enabledButton_f.length; i++) {
                    Field f = enabledButton_f[i];
                    if (f != null) {
                        GuiButton button = ((GuiButton) f.get(gws));
                        button.enabled = true;
                        if (nameRestore[i] == null) {
                            nameRestore[i] = button.displayString;
                            button.displayString = newNames[i];
                        }
                    }
                }
                for (Field f : disabledButton_f) {
                    if (f != null)
                        ((GuiButton) f.get(gws)).enabled = false;
                }
            } else {
                restore(gws);
            }
            for (GuiListWorldSelectionEntry entry : lglwse) {
                if (entry instanceof TotallyADolphinEntry) {
                    return;
                }
            }
            WorldInfo worldInfo = new WorldInfo(new WorldSettings(0, GameType.NOT_SET, false, false, WorldType.DEFAULT), "Flamingo1");
            WorldSummary worldSummary = new WorldSummary(worldInfo, "Flamingo2", "Flamingo3", 0, false);
            TotallyADolphinEntry dolphin = new TotallyADolphinEntry(gwls, worldSummary, new TotallyADolphinSaveFormat(worldInfo));
            lglwse.add(dolphin);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WorldSummary(net.minecraft.world.storage.WorldSummary) WorldSettings(net.minecraft.world.WorldSettings) IOException(java.io.IOException) Field(java.lang.reflect.Field) WorldInfo(net.minecraft.world.storage.WorldInfo) List(java.util.List) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

WorldSummary (net.minecraft.world.storage.WorldSummary)3 AnvilConverterException (net.minecraft.client.AnvilConverterException)2 ISaveFormat (net.minecraft.world.storage.ISaveFormat)2 File (java.io.File)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 List (java.util.List)1 IntegratedServer (net.minecraft.server.integrated.IntegratedServer)1 WorldSettings (net.minecraft.world.WorldSettings)1 WorldInfo (net.minecraft.world.storage.WorldInfo)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1