Fixed Forge commands. Closes #6973 Closes #6974 Closes #6976

This commit is contained in:
LexManos committed 2020-07-16 14:08:13 -07:00
1 parent 00013865b0
commit 638d1d31de
9 files changed
+62 -43

No files matched your search

@@ -96,21 +96,8 @@ public class ChunkGenWorker implements IWorker
@Override
public boolean doWork()
{
/*
ServerWorld world = DimensionManager.getWorld(listener.getServer(), dim, false, false);
if (world == null)
{
world = DimensionManager.initWorld(listener.getServer(), dim);
if (world == null)
{
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.dim_fail", dim), true);
queue.clear();
return false;
}
}
/* TODO: Check how many things are pending save, and slow down world gen if to many
AnvilChunkLoader loader = world.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
AnvilChunkLoader loader = dim.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
if (loader != null && loader.getPendingSaveCount() > 100)
{
@@ -121,17 +108,17 @@ public class ChunkGenWorker implements IWorker
}
return false;
}
* /
*/
BlockPos next = queue.poll();
if (next != null)
{
// While we work we don't want to cause world load spam so pause unloading the world.
/* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
if (keepingLoaded == null)
{
keepingLoaded = DimensionManager.keepLoaded(dim, true);
}
*/
if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60*1000)
{
@@ -143,10 +130,10 @@ public class ChunkGenWorker implements IWorker
int x = next.getX();
int z = next.getZ();
if (!world.chunkExists(x, z)) { //Chunk is unloaded
IChunk chunk = world.getChunk(x, z, ChunkStatus.EMPTY, true);
if (!dim.chunkExists(x, z)) { //Chunk is unloaded
IChunk chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
if (!chunk.getStatus().isAtLeast(ChunkStatus.FULL)) {
chunk = world.getChunk(x, z, ChunkStatus.FULL);
chunk = dim.getChunk(x, z, ChunkStatus.FULL);
genned++; //There isn't a way to check if the chunk is actually created just if it was loaded
}
}
@@ -154,14 +141,13 @@ public class ChunkGenWorker implements IWorker
if (queue.size() == 0)
{
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.complete", genned, total, DimensionType.getKey(dim)), true);
listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.complete", genned, total, dim.func_234923_W_().func_240901_a_()), true);
/* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
if (keepingLoaded != null && !keepingLoaded)
{
DimensionManager.keepLoaded(dim, false);
}
*/
return false;
}
*/
return true;
}
}
@@ -21,8 +21,11 @@ package net.minecraftforge.server.command;
import net.minecraft.command.CommandSource;
import net.minecraft.command.Commands;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.server.ServerWorld;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -39,19 +42,13 @@ public class CommandDimensions
.requires(cs->cs.hasPermissionLevel(0)) //permission
.executes(ctx -> {
ctx.getSource().sendFeedback(new TranslationTextComponent("commands.forge.dimensions.list"), true);
/*
Map<String, List<String>> types = new HashMap<>();
for (DimensionType dim : DimensionType.getAll()) {
String key = dim.getModType() == null ? "Vanilla" : dim.getModType().getRegistryName().toString();
types.computeIfAbsent(key, k -> new ArrayList<>()).add(DimensionType.getKey(dim).toString());
Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
for (ServerWorld dim : ctx.getSource().getServer().getWorlds()) {
types.computeIfAbsent(dim.func_234922_V_().func_240901_a_(), k -> new ArrayList<>()).add(dim.func_234923_W_().func_240901_a_());
}
types.keySet().stream().sorted().forEach(key -> {
ctx.getSource().sendFeedback(new StringTextComponent(key + ": " + types.get(key).stream().sorted().collect(Collectors.joining(", "))), false);
});
*/
ctx.getSource().getServer().func_240770_D_().stream().sorted().forEach(key -> {
ctx.getSource().sendFeedback(new StringTextComponent(key.func_240901_a_().toString()), false);
ctx.getSource().sendFeedback(new StringTextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
});
return 0;
});
@@ -69,7 +69,7 @@ class CommandEntity
return Commands.literal("list")
.requires(cs->cs.hasPermissionLevel(2)) //permission
.then(Commands.argument("filter", StringArgumentType.string())
.suggests((ctx, builder) -> ISuggestionProvider.suggest(ForgeRegistries.ENTITIES.getKeys().stream().map(ResourceLocation::toString), builder))
.suggests((ctx, builder) -> ISuggestionProvider.suggest(ForgeRegistries.ENTITIES.getKeys().stream().map(ResourceLocation::toString).map(StringArgumentType::escapeIfRequired), builder))
.then(Commands.argument("dim", DimensionArgument.getDimension())
.executes(ctx -> execute(ctx.getSource(), StringArgumentType.getString(ctx, "filter"), DimensionArgument.getDimensionArgument(ctx, "dim").func_234923_W_()))
)
@@ -44,7 +44,7 @@ public class CommandModList {
modFile.getModInfos().get(0).getModId(),
modFile.getModInfos().get(0).getVersion(),
modFile.getModInfos().size())).
collect(Collectors.joining("\n• ","• ", ""))),
collect(Collectors.joining("\n\u2022 ","\n\u2022 ", ""))),
false);
return 0;
}
@@ -44,6 +44,7 @@ class CommandTps
for (ServerWorld dim : ctx.getSource().getServer().getWorlds())
sendTime(ctx.getSource(), dim);
@SuppressWarnings("resource")
double meanTickTime = mean(ctx.getSource().getServer().tickTimeArray) * 1.0E-6D;
double meanTPS = Math.min(1000.0/meanTickTime, 20);
ctx.getSource().sendFeedback(new TranslationTextComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
@@ -62,7 +63,7 @@ class CommandTps
double worldTickTime = mean(times) * 1.0E-6D;
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
cs.sendFeedback(new TranslationTextComponent("commands.forge.tps.summary.named", dim.func_234923_W_().toString(), dim.func_234922_V_().toString(), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
cs.sendFeedback(new TranslationTextComponent("commands.forge.tps.summary.named", dim.func_234923_W_().func_240901_a_().toString(), dim.func_234922_V_().func_240901_a_().toString(), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
return 1;
}
@@ -157,7 +157,7 @@ class CommandTrack
double averageTimings = data.getAverageTimings();
String tickTime = (averageTimings > 1000 ? TIME_FORMAT.format(averageTimings / 1000) : TIME_FORMAT.format(averageTimings)) + (averageTimings < 1000 ? "\u03bcs" : "ms");
return new TranslationTextComponent("commands.forge.tracking.timing_entry", entity.getType().getRegistryName(), entity.world.func_234923_W_().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
return new TranslationTextComponent("commands.forge.tracking.timing_entry", entity.getType().getRegistryName(), entity.world.func_234923_W_().func_240901_a_().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
})
);
}
@@ -177,7 +177,7 @@ class CommandTrack
double averageTimings = data.getAverageTimings();
String tickTime = (averageTimings > 1000 ? TIME_FORMAT.format(averageTimings / 1000) : TIME_FORMAT.format(averageTimings)) + (averageTimings < 1000 ? "\u03bcs" : "ms");
return new TranslationTextComponent("commands.forge.tracking.timing_entry", te.getType().getRegistryName(), te.getWorld().func_234923_W_().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
return new TranslationTextComponent("commands.forge.tracking.timing_entry", te.getType().getRegistryName(), te.getWorld().func_234923_W_().func_240901_a_().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
})
);
}