Fix Forge's tps and gen commands.

This commit is contained in:
LexManos 2020-03-15 16:27:58 -07:00
parent 23541ab175
commit 52b8070692
3 changed files with 12 additions and 18 deletions

View file

@ -19,7 +19,6 @@
package net.minecraftforge.server.command;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Queue;
@ -28,11 +27,9 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
import net.minecraft.world.chunk.IChunk;
import net.minecraft.world.dimension.DimensionType;
import net.minecraft.world.storage.SessionLockException;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.WorldWorkerManager.IWorker;
@ -146,17 +143,18 @@ public class ChunkGenWorker implements IWorker
int x = next.getX();
int z = next.getZ();
IChunk chunk = world.getChunk(x, z, ChunkStatus.FULL, false);
/* TODO: Mark things to unload
PlayerChunkMapEntry watchers = world.getPlayerChunkMap().getEntry(chunk.x, chunk.z);
if (watchers == null) //If there are no players watching this, this will be null, so we can unload.
world.getChunkProvider().queueUnload(chunk);
*/
if (!world.chunkExists(x, z)) { //Chunk is unloaded
IChunk chunk = world.getChunk(x, z, ChunkStatus.EMPTY, true);
if (!chunk.getStatus().isAtLeast(ChunkStatus.FULL)) {
chunk = world.getChunk(x, z, ChunkStatus.FULL);
genned++; //There isn't a way to check if the chunk is actually created just if it was loaded
}
}
}
if (queue.size() == 0)
{
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.complete", genned, total, dim), true);
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.complete", genned, total, DimensionType.getKey(dim)), true);
if (keepingLoaded != null && !keepingLoaded)
{
DimensionManager.keepLoaded(dim, false);

View file

@ -20,12 +20,8 @@
package net.minecraftforge.server.command;
import java.text.DecimalFormat;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.command.arguments.DimensionArgument;
@ -34,8 +30,8 @@ import net.minecraft.world.dimension.DimensionType;
class CommandTps
{
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslationTextComponent("commands.forge.tps.invalid", dim, StreamSupport.stream(DimensionType.getAll().spliterator(), false).map(d -> DimensionType.getKey(d).toString()).sorted().collect(Collectors.joining(", "))));
private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
private static final long[] UNLOADED = new long[] {0};
static ArgumentBuilder<CommandSource, ?> register()
{
@ -61,8 +57,8 @@ class CommandTps
{
long[] times = cs.getServer().getTickTime(dim);
if (times == null)
throw INVALID_DIMENSION.create(DimensionType.getKey(dim));
if (times == null) /// Null means the world is unloaded. Not invalid. That's taken car of by DimensionArgument itself.
times = UNLOADED;
double worldTickTime = mean(times) * 1.0E-6D;
double worldTPS = Math.min(1000.0 / worldTickTime, 20);

View file

@ -83,7 +83,7 @@
"commands.forge.gen.usage": "Use /forge gen <x> <y> <z> <chunkCount> [dimension] [interval]",
"commands.forge.gen.dim_fail": "Failed to load world for dimension {0}, Task terminated.",
"commands.forge.gen.progress": "Generation Progress: {0}/{1}",
"commands.forge.gen.complete": "Finished generating {0} new chunks (out of {2}) for dimension {3}.",
"commands.forge.gen.complete": "Finished generating {0} new chunks (out of {1}) for dimension {2}.",
"commands.forge.gen.start": "Starting to generate {0} chunks in a spiral around {1}, {2} in dimension {3}.",
"commands.forge.setdim.invalid.entity": "The entity selected ({0}) is not valid.",
"commands.forge.setdim.invalid.dim": "The dimension ID specified ({0}) is not valid.",