Add new /forge gen command to generate large amounts of chunks.

Usage: /forge gen <position> <count> [dimension] [notifications]
Position is in Block Coords, and can be relative to the player. These will be converted to chunk coords for you.
Count is the number of chunks to load. This is not a radius, actual total number of chunks.
Dimension is optional, you can use this to pregen other worlds.
Notifications is the chunk interval to inform you of the generating progress. This is optional and will be 5% or 100 whichever is higher.

Added new config option to modify vanilla world gen to fix various cascading issues. MC-117810 MC-114332 and more.
This WILL change block placement from vanilla world gen. So this is a opt-in value. Do not report differences in worlds with this flag enabled.
This commit is contained in:
LexManos committed 2017-09-15 19:01:59 -07:00
1 parent 036191cd52
commit 0ad4218bc2
9 files changed
+349 -9

No files matched your search

@@ -30,6 +30,8 @@ import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent.ServerTickEvent;
public class ForgeInternalHandler
{
@@ -68,7 +70,7 @@ public class ForgeInternalHandler
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onDimensionSave(WorldEvent.Save event)
{
ForgeChunkManager.saveWorld(event.getWorld());
ForgeChunkManager.saveWorld(event.getWorld());
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
@@ -78,4 +80,11 @@ public class ForgeInternalHandler
if (event.getWorld() instanceof WorldServer)
FakePlayerFactory.unloadWorld((WorldServer) event.getWorld());
}
@SubscribeEvent
public void onServerTick(ServerTickEvent event)
{
WorldWorkerManager.tick(event.phase == TickEvent.Phase.START);
}
}
@@ -91,6 +91,7 @@ import net.minecraftforge.fml.common.event.FMLModIdMappingEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import net.minecraftforge.fml.common.event.FMLServerStoppingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
@@ -117,6 +118,8 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
public static boolean alwaysSetupTerrainOffThread = false; // In RenderGlobal.setupTerrain, always force the chunk render updates to be queued to the thread
public static int dimensionUnloadQueueDelay = 0;
public static boolean logCascadingWorldGeneration = true; // see Chunk#logCascadingWorldGeneration()
public static boolean fixVanillaCascading = false; // There are various places in vanilla that cause cascading worldgen. Enabling this WILL change where blocks are placed to prevent this.
// DO NOT contact Forge about worldgen not 'matching' vanilla if this flag is set.
static final Logger log = LogManager.getLogger(ForgeVersion.MOD_ID);
@@ -288,6 +291,12 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
prop.setLanguageKey("forge.configgui.logCascadingWorldGeneration");
propOrder.add(prop.getName());
prop = config.get(Configuration.CATEGORY_GENERAL, "fixVanillaCascading", false,
"Fix vanilla issues that cause worldgen cascading. This DOES change vanilla worldgen so DO NOT report bugs related to world differences if this flag is on.");
fixVanillaCascading = prop.getBoolean();
prop.setLanguageKey("forge.configgui.fixVanillaCascading");
propOrder.add(prop.getName());
prop = config.get(Configuration.CATEGORY_GENERAL, "dimensionUnloadQueueDelay", 0,
"The time in ticks the server will wait when a dimension was queued to unload. " +
"This can be useful when rapidly loading and unloading dimensions, like e.g. throwing items through a nether portal a few time per second.");
@@ -509,6 +518,13 @@ public class ForgeModContainer extends DummyModContainer implements WorldAccessC
{
evt.registerServerCommand(new ForgeCommand());
}
@Subscribe
public void serverStopping(FMLServerStoppingEvent evt)
{
WorldWorkerManager.clear();
}
@Override
public NBTTagCompound getDataForWriting(SaveHandler handler, WorldInfo info)
{
@@ -0,0 +1,84 @@
/*
* Minecraft Forge
* Copyright (c) 2016.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.common;
import java.util.ArrayList;
import java.util.List;
public class WorldWorkerManager
{
private static List<IWorker> workers = new ArrayList<IWorker>();
private static long startTime = -1;
public static void tick(boolean start)
{
if (start)
{
startTime = System.currentTimeMillis();
return;
}
IWorker task = getNext();
if (task == null)
return;
long time = 50 - (System.currentTimeMillis() - startTime);
if (time < 10)
time = 10; //If ticks are lagging, give us at least 10ms to do something.
time += System.currentTimeMillis();
while (System.currentTimeMillis() < time)
{
task.work();
if (!task.hasWork())
{
time = 0; //Break loop
remove(task);
}
}
}
public static synchronized void addWorker(IWorker worker)
{
workers.add(worker);
}
private static synchronized IWorker getNext()
{
return workers.size() > 0 ? workers.get(0) : null;
}
private static synchronized void remove(IWorker worker)
{
workers.remove(worker);
}
//Internal only, used to clear everything when the server shuts down.
public static synchronized void clear()
{
workers.clear();
}
public static interface IWorker
{
boolean hasWork();
void work();
}
}