net.minecraft.world.storage.WorldSummary Java Examples

The following examples show how to use net.minecraft.world.storage.WorldSummary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapFileHelper.java    From malmo with MIT License 6 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example #2
Source File: WorldSaveRow.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
WorldSaveRow(WorldSummary worldSummary, SaveFormat saveLoader, Consumer<ControlListEntry> setSelectedEntry) {
    this.worldSummary = worldSummary;
    this.saveLoader = saveLoader;
    this.setSelectedEntry = setSelectedEntry;
    this.client = Minecraft.getInstance();
    this.iconLocation = new ResourceLocation("worlds/" + Hashing.sha1().hashUnencodedChars(worldSummary.getFileName()) + "/icon");
    this.iconFile = saveLoader.getFile(worldSummary.getFileName(), "icon.png");
    if (!this.iconFile.isFile()) {
        this.iconFile = null;
    }

    this.icon = this.loadIcon();
}
 
Example #3
Source File: LoadSavesScreen.java    From BoundingBoxOutlineReloaded with MIT License 5 votes vote down vote up
@Override
protected ControlList buildList(int top, int bottom) {
    controlList = new SelectableControlList(this.width, this.height, top, bottom);
    try {
        final SaveFormat saveLoader = this.minecraft.getSaveLoader();
        List<WorldSummary> saveList = saveLoader.getSaveList();
        saveList.sort(null);
        saveList.forEach(world -> controlList.add(new WorldSaveRow(world, saveLoader, controlList::setSelectedEntry)));
    } catch (AnvilConverterException e) {
        e.printStackTrace();
    }
    return controlList;
}
 
Example #4
Source File: FileWorldGeneratorImplementation.java    From malmo with MIT License 4 votes vote down vote up
@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;
    }
    MapFileHelper.cleanupTemporaryWorlds(mapCopy.getName());    // Now we are safely running a new file, we can attempt to clean up old ones.
    return true;
}