Fix Forge's tps and gen commands.
This commit is contained in:
parent
23541ab175
commit
52b8070692
3 changed files with 12 additions and 18 deletions
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package net.minecraftforge.server.command;
|
package net.minecraftforge.server.command;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Queue;
|
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.TextComponent;
|
||||||
import net.minecraft.util.text.TranslationTextComponent;
|
import net.minecraft.util.text.TranslationTextComponent;
|
||||||
import net.minecraft.world.server.ServerWorld;
|
import net.minecraft.world.server.ServerWorld;
|
||||||
import net.minecraft.world.chunk.Chunk;
|
|
||||||
import net.minecraft.world.chunk.ChunkStatus;
|
import net.minecraft.world.chunk.ChunkStatus;
|
||||||
import net.minecraft.world.chunk.IChunk;
|
import net.minecraft.world.chunk.IChunk;
|
||||||
import net.minecraft.world.dimension.DimensionType;
|
import net.minecraft.world.dimension.DimensionType;
|
||||||
import net.minecraft.world.storage.SessionLockException;
|
|
||||||
import net.minecraftforge.common.DimensionManager;
|
import net.minecraftforge.common.DimensionManager;
|
||||||
import net.minecraftforge.common.WorldWorkerManager.IWorker;
|
import net.minecraftforge.common.WorldWorkerManager.IWorker;
|
||||||
|
|
||||||
|
@ -146,17 +143,18 @@ public class ChunkGenWorker implements IWorker
|
||||||
int x = next.getX();
|
int x = next.getX();
|
||||||
int z = next.getZ();
|
int z = next.getZ();
|
||||||
|
|
||||||
IChunk chunk = world.getChunk(x, z, ChunkStatus.FULL, false);
|
if (!world.chunkExists(x, z)) { //Chunk is unloaded
|
||||||
/* TODO: Mark things to unload
|
IChunk chunk = world.getChunk(x, z, ChunkStatus.EMPTY, true);
|
||||||
PlayerChunkMapEntry watchers = world.getPlayerChunkMap().getEntry(chunk.x, chunk.z);
|
if (!chunk.getStatus().isAtLeast(ChunkStatus.FULL)) {
|
||||||
if (watchers == null) //If there are no players watching this, this will be null, so we can unload.
|
chunk = world.getChunk(x, z, ChunkStatus.FULL);
|
||||||
world.getChunkProvider().queueUnload(chunk);
|
genned++; //There isn't a way to check if the chunk is actually created just if it was loaded
|
||||||
*/
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (queue.size() == 0)
|
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)
|
if (keepingLoaded != null && !keepingLoaded)
|
||||||
{
|
{
|
||||||
DimensionManager.keepLoaded(dim, false);
|
DimensionManager.keepLoaded(dim, false);
|
||||||
|
|
|
@ -20,12 +20,8 @@
|
||||||
package net.minecraftforge.server.command;
|
package net.minecraftforge.server.command;
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.StreamSupport;
|
|
||||||
|
|
||||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
|
||||||
import net.minecraft.command.CommandSource;
|
import net.minecraft.command.CommandSource;
|
||||||
import net.minecraft.command.Commands;
|
import net.minecraft.command.Commands;
|
||||||
import net.minecraft.command.arguments.DimensionArgument;
|
import net.minecraft.command.arguments.DimensionArgument;
|
||||||
|
@ -34,8 +30,8 @@ import net.minecraft.world.dimension.DimensionType;
|
||||||
|
|
||||||
class CommandTps
|
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 DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
|
||||||
|
private static final long[] UNLOADED = new long[] {0};
|
||||||
|
|
||||||
static ArgumentBuilder<CommandSource, ?> register()
|
static ArgumentBuilder<CommandSource, ?> register()
|
||||||
{
|
{
|
||||||
|
@ -61,8 +57,8 @@ class CommandTps
|
||||||
{
|
{
|
||||||
long[] times = cs.getServer().getTickTime(dim);
|
long[] times = cs.getServer().getTickTime(dim);
|
||||||
|
|
||||||
if (times == null)
|
if (times == null) /// Null means the world is unloaded. Not invalid. That's taken car of by DimensionArgument itself.
|
||||||
throw INVALID_DIMENSION.create(DimensionType.getKey(dim));
|
times = UNLOADED;
|
||||||
|
|
||||||
double worldTickTime = mean(times) * 1.0E-6D;
|
double worldTickTime = mean(times) * 1.0E-6D;
|
||||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
"commands.forge.gen.usage": "Use /forge gen <x> <y> <z> <chunkCount> [dimension] [interval]",
|
"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.dim_fail": "Failed to load world for dimension {0}, Task terminated.",
|
||||||
"commands.forge.gen.progress": "Generation Progress: {0}/{1}",
|
"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.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.entity": "The entity selected ({0}) is not valid.",
|
||||||
"commands.forge.setdim.invalid.dim": "The dimension ID specified ({0}) is not valid.",
|
"commands.forge.setdim.invalid.dim": "The dimension ID specified ({0}) is not valid.",
|
||||||
|
|
Loading…
Reference in a new issue