mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 11:29:15 +00:00
Update to 1.17
Update to Official classnames Patchwork Make the game compile and run Merge in the new HUD overlay API Merge in the new render properties API PEEL Use Gradle 7.2 snapshot to fix eclipse integration bug in 7.1, Would use 7.0 but FG needs 7.1 for some reason. New FML installer Update to 1.17.1 Co-authored-by: LexManos <[email protected]> Co-authored-by: SizableShrimp <[email protected]> Co-authored-by: cpw <[email protected]> Co-authored-by: Curle <[email protected]> Co-authored-by: Unnoen <[email protected]> Co-authored-by: covers1624 <[email protected]> Co-authored-by: DaemonUmbra <[email protected]> Co-authored-by: gigaherz <[email protected]> Signed-off-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
064ae6961b
commit
be5446b91c
1990 files changed
+35661
-37544
No files matched your search
@@ -22,22 +22,21 @@ package net.minecraftforge.server.command;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Queue;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
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.DimensionType;
|
||||
import net.minecraft.world.chunk.ChunkStatus;
|
||||
import net.minecraft.world.chunk.IChunk;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.ChunkStatus;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraftforge.common.WorldWorkerManager.IWorker;
|
||||
|
||||
public class ChunkGenWorker implements IWorker
|
||||
{
|
||||
private final CommandSource listener;
|
||||
private final CommandSourceStack listener;
|
||||
protected final BlockPos start;
|
||||
protected final int total;
|
||||
private final ServerWorld dim;
|
||||
private final ServerLevel dim;
|
||||
private final Queue<BlockPos> queue;
|
||||
private final int notificationFrequency;
|
||||
private int lastNotification = 0;
|
||||
@@ -45,7 +44,7 @@ public class ChunkGenWorker implements IWorker
|
||||
private int genned = 0;
|
||||
private Boolean keepingLoaded;
|
||||
|
||||
public ChunkGenWorker(CommandSource listener, BlockPos start, int total, ServerWorld dim, int interval)
|
||||
public ChunkGenWorker(CommandSourceStack listener, BlockPos start, int total, ServerLevel dim, int interval)
|
||||
{
|
||||
this.listener = listener;
|
||||
this.start = start;
|
||||
@@ -82,9 +81,9 @@ public class ChunkGenWorker implements IWorker
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TextComponent getStartMessage(CommandSource sender)
|
||||
public BaseComponent getStartMessage(CommandSourceStack sender)
|
||||
{
|
||||
return new TranslationTextComponent("commands.forge.gen.start", total, start.getX(), start.getZ(), dim);
|
||||
return new TranslatableComponent("commands.forge.gen.start", total, start.getX(), start.getZ(), dim);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +121,7 @@ public class ChunkGenWorker implements IWorker
|
||||
|
||||
if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60*1000)
|
||||
{
|
||||
listener.sendSuccess(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
|
||||
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.progress", total - queue.size(), total), true);
|
||||
lastNotification = 0;
|
||||
lastNotifcationTime = System.currentTimeMillis();
|
||||
}
|
||||
@@ -131,7 +130,7 @@ public class ChunkGenWorker implements IWorker
|
||||
int z = next.getZ();
|
||||
|
||||
if (!dim.hasChunk(x, z)) { //Chunk is unloaded
|
||||
IChunk chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
|
||||
ChunkAccess chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
|
||||
if (!chunk.getStatus().isOrAfter(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
|
||||
@@ -141,7 +140,7 @@ public class ChunkGenWorker implements IWorker
|
||||
|
||||
if (queue.size() == 0)
|
||||
{
|
||||
listener.sendSuccess(new TranslationTextComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
|
||||
listener.sendSuccess(new TranslatableComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
|
||||
/* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
|
||||
if (keepingLoaded != null && !keepingLoaded)
|
||||
DimensionManager.keepLoaded(dim, false);
|
||||
|
||||
@@ -19,17 +19,16 @@
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -39,21 +38,21 @@ import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
|
||||
public class CommandDimensions
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("dimensions")
|
||||
.requires(cs->cs.hasPermission(0)) //permission
|
||||
.executes(ctx -> {
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.dimensions.list"), true);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
|
||||
final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
|
||||
Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
|
||||
for (ServerWorld dim : ctx.getSource().getServer().getAllLevels()) {
|
||||
for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) {
|
||||
types.computeIfAbsent(reg.getKey(dim.dimensionType()), k -> new ArrayList<>()).add(dim.dimension().location());
|
||||
}
|
||||
|
||||
types.keySet().stream().sorted().forEach(key -> {
|
||||
ctx.getSource().sendSuccess(new StringTextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
|
||||
ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
|
||||
});
|
||||
return 0;
|
||||
});
|
||||
|
||||
@@ -33,17 +33,17 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.command.arguments.DimensionArgument;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
@@ -51,7 +51,7 @@ import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
class CommandEntity
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("entity")
|
||||
.then(EntityListCommand.register()); //TODO: //Kill, spawn, etc..
|
||||
@@ -59,15 +59,15 @@ class CommandEntity
|
||||
|
||||
private static class EntityListCommand
|
||||
{
|
||||
private static final SimpleCommandExceptionType INVALID_FILTER = new SimpleCommandExceptionType(new TranslationTextComponent("commands.forge.entity.list.invalid"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslationTextComponent("commands.forge.entity.list.invalidworld", dim));
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslationTextComponent("commands.forge.entity.list.none"));
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
private static final SimpleCommandExceptionType INVALID_FILTER = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.entity.list.invalid"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslatableComponent("commands.forge.entity.list.invalidworld", dim));
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.entity.list.none"));
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("list")
|
||||
.requires(cs->cs.hasPermission(2)) //permission
|
||||
.then(Commands.argument("filter", StringArgumentType.string())
|
||||
.suggests((ctx, builder) -> ISuggestionProvider.suggest(ForgeRegistries.ENTITIES.getKeys().stream().map(ResourceLocation::toString).map(StringArgumentType::escapeIfRequired), builder))
|
||||
.suggests((ctx, builder) -> SharedSuggestionProvider.suggest(ForgeRegistries.ENTITIES.getKeys().stream().map(ResourceLocation::toString).map(StringArgumentType::escapeIfRequired), builder))
|
||||
.then(Commands.argument("dim", DimensionArgument.dimension())
|
||||
.executes(ctx -> execute(ctx.getSource(), StringArgumentType.getString(ctx, "filter"), DimensionArgument.getDimension(ctx, "dim").dimension()))
|
||||
)
|
||||
@@ -76,7 +76,7 @@ class CommandEntity
|
||||
.executes(ctx -> execute(ctx.getSource(), "*", ctx.getSource().getLevel().dimension()));
|
||||
}
|
||||
|
||||
private static int execute(CommandSource sender, String filter, RegistryKey<World> dim) throws CommandSyntaxException
|
||||
private static int execute(CommandSourceStack sender, String filter, ResourceKey<Level> dim) throws CommandSyntaxException
|
||||
{
|
||||
final String cleanFilter = filter.replace("?", ".?").replace("*", ".*?");
|
||||
|
||||
@@ -85,12 +85,12 @@ class CommandEntity
|
||||
if (names.isEmpty())
|
||||
throw INVALID_FILTER.create();
|
||||
|
||||
ServerWorld world = sender.getServer().getLevel(dim); //TODO: DimensionManager so we can hotload? DimensionManager.getWorld(sender.getServer(), dim, false, false);
|
||||
ServerLevel world = sender.getServer().getLevel(dim); //TODO: DimensionManager so we can hotload? DimensionManager.getWorld(sender.getServer(), dim, false, false);
|
||||
if (world == null)
|
||||
throw INVALID_DIMENSION.create(dim);
|
||||
|
||||
Map<ResourceLocation, MutablePair<Integer, Map<ChunkPos, Integer>>> list = Maps.newHashMap();
|
||||
world.getEntities().forEach(e -> {
|
||||
world.getEntities().getAll().forEach(e -> {
|
||||
MutablePair<Integer, Map<ChunkPos, Integer>> info = list.computeIfAbsent(e.getType().getRegistryName(), k -> MutablePair.of(0, Maps.newHashMap()));
|
||||
ChunkPos chunk = new ChunkPos(e.blockPosition());
|
||||
info.left++;
|
||||
@@ -104,7 +104,7 @@ class CommandEntity
|
||||
if (info == null)
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
sender.sendSuccess(new TranslationTextComponent("commands.forge.entity.list.single.header", name, info.getLeft()), false);
|
||||
sender.sendSuccess(new TranslatableComponent("commands.forge.entity.list.single.header", name, info.getLeft()), false);
|
||||
List<Map.Entry<ChunkPos, Integer>> toSort = new ArrayList<>();
|
||||
toSort.addAll(info.getRight().entrySet());
|
||||
toSort.sort((a, b) -> {
|
||||
@@ -118,7 +118,7 @@ class CommandEntity
|
||||
for (Map.Entry<ChunkPos, Integer> e : toSort)
|
||||
{
|
||||
if (limit-- == 0) break;
|
||||
sender.sendSuccess(new StringTextComponent(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z), false);
|
||||
sender.sendSuccess(new TextComponent(" " + e.getValue() + ": " + e.getKey().x + ", " + e.getKey().z), false);
|
||||
}
|
||||
return toSort.size();
|
||||
}
|
||||
@@ -144,8 +144,8 @@ class CommandEntity
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
int count = info.stream().mapToInt(Pair::getRight).sum();
|
||||
sender.sendSuccess(new TranslationTextComponent("commands.forge.entity.list.multiple.header", count), false);
|
||||
info.forEach(e -> sender.sendSuccess(new StringTextComponent(" " + e.getValue() + ": " + e.getKey()), false));
|
||||
sender.sendSuccess(new TranslatableComponent("commands.forge.entity.list.multiple.header", count), false);
|
||||
info.forEach(e -> sender.sendSuccess(new TextComponent(" " + e.getValue() + ": " + e.getKey()), false));
|
||||
return info.size();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,18 +23,18 @@ import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.BlockPosArgument;
|
||||
import net.minecraft.command.arguments.DimensionArgument;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.commands.CommandRuntimeException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.WorldWorkerManager;
|
||||
|
||||
class CommandGenerate
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("generate")
|
||||
.requires(cs->cs.hasPermission(4)) //permission
|
||||
@@ -42,21 +42,21 @@ class CommandGenerate
|
||||
.then(Commands.argument("count", IntegerArgumentType.integer(1))
|
||||
.then(Commands.argument("dim", DimensionArgument.dimension())
|
||||
.then(Commands.argument("interval", IntegerArgumentType.integer())
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getOrLoadBlockPos(ctx, "pos"), getInt(ctx, "count"), DimensionArgument.getDimension(ctx, "dim"), getInt(ctx, "interval")))
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getSpawnablePos(ctx, "pos"), getInt(ctx, "count"), DimensionArgument.getDimension(ctx, "dim"), getInt(ctx, "interval")))
|
||||
)
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getOrLoadBlockPos(ctx, "pos"), getInt(ctx, "count"), DimensionArgument.getDimension(ctx, "dim"), -1))
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getSpawnablePos(ctx, "pos"), getInt(ctx, "count"), DimensionArgument.getDimension(ctx, "dim"), -1))
|
||||
)
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getOrLoadBlockPos(ctx, "pos"), getInt(ctx, "count"), ctx.getSource().getLevel(), -1))
|
||||
.executes(ctx -> execute(ctx.getSource(), BlockPosArgument.getSpawnablePos(ctx, "pos"), getInt(ctx, "count"), ctx.getSource().getLevel(), -1))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static int getInt(CommandContext<CommandSource> ctx, String name)
|
||||
private static int getInt(CommandContext<CommandSourceStack> ctx, String name)
|
||||
{
|
||||
return IntegerArgumentType.getInteger(ctx, name);
|
||||
}
|
||||
|
||||
private static int execute(CommandSource source, BlockPos pos, int count, ServerWorld dim, int interval) throws CommandException
|
||||
private static int execute(CommandSourceStack source, BlockPos pos, int count, ServerLevel dim, int interval) throws CommandRuntimeException
|
||||
{
|
||||
BlockPos chunkpos = new BlockPos(pos.getX() >> 4, 0, pos.getZ() >> 4);
|
||||
|
||||
|
||||
@@ -20,19 +20,19 @@
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandModList {
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("mods")
|
||||
.requires(cs->cs.hasPermission(0)) //permission
|
||||
.executes(ctx -> {
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.mods.list",
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.mods.list",
|
||||
ModList.get().applyForEachModFile(modFile ->
|
||||
// locator - filename : firstmod (version) - numberofmods\n
|
||||
String.format("%s %s : %s (%s) - %d",
|
||||
|
||||
@@ -19,18 +19,18 @@
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.BlockPosArgument;
|
||||
import net.minecraft.command.arguments.DimensionArgument;
|
||||
import net.minecraft.command.arguments.EntityArgument;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.coordinates.BlockPosArgument;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
@@ -47,23 +47,23 @@ import java.util.Collection;
|
||||
@Deprecated
|
||||
public class CommandSetDimension
|
||||
{
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslationTextComponent("commands.forge.setdim.invalid.entity"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslationTextComponent("commands.forge.setdim.invalid.dim", dim));
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.setdim.invalid.entity"));
|
||||
private static final DynamicCommandExceptionType INVALID_DIMENSION = new DynamicCommandExceptionType(dim -> new TranslatableComponent("commands.forge.setdim.invalid.dim", dim));
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("setdimension")
|
||||
.requires(cs->cs.hasPermission(2)) //permission
|
||||
.then(Commands.argument("targets", EntityArgument.entities())
|
||||
.then(Commands.argument("dim", DimensionArgument.dimension())
|
||||
.then(Commands.argument("pos", BlockPosArgument.blockPos())
|
||||
.executes(ctx -> execute(ctx, EntityArgument.getOptionalEntities(ctx, "targets"), DimensionArgument.getDimension(ctx, "dim"), BlockPosArgument.getOrLoadBlockPos(ctx, "pos")))
|
||||
.executes(ctx -> execute(ctx, EntityArgument.getOptionalEntities(ctx, "targets"), DimensionArgument.getDimension(ctx, "dim"), BlockPosArgument.getSpawnablePos(ctx, "pos")))
|
||||
)
|
||||
.executes(ctx -> execute(ctx, EntityArgument.getOptionalEntities(ctx, "targets"), DimensionArgument.getDimension(ctx, "dim"), new BlockPos(ctx.getSource().getPosition())))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private static int execute(CommandContext<CommandSource> ctx, Collection<? extends Entity> entities, ServerWorld dim, BlockPos pos) throws CommandSyntaxException
|
||||
private static int execute(CommandContext<CommandSourceStack> ctx, Collection<? extends Entity> entities, ServerLevel dim, BlockPos pos) throws CommandSyntaxException
|
||||
{
|
||||
entities.removeIf(e -> !canEntityTeleport(e));
|
||||
if (entities.isEmpty())
|
||||
@@ -71,9 +71,9 @@ public class CommandSetDimension
|
||||
|
||||
String cmdTarget = "@s";
|
||||
String posTarget = "";
|
||||
for (ParsedCommandNode<CommandSource> parsed : ctx.getNodes())
|
||||
for (ParsedCommandNode<CommandSourceStack> parsed : ctx.getNodes())
|
||||
{
|
||||
final CommandNode<CommandSource> node = parsed.getNode();
|
||||
final CommandNode<CommandSourceStack> node = parsed.getNode();
|
||||
if (parsed.getNode() instanceof ArgumentCommandNode)
|
||||
{
|
||||
if ("target".equals(parsed.getNode().getName()))
|
||||
@@ -89,9 +89,9 @@ public class CommandSetDimension
|
||||
final String dimName = dim.dimension().location().toString();
|
||||
final String finalCmdTarget = cmdTarget;
|
||||
final String finalPosTarget = posTarget;
|
||||
ITextComponent suggestion = new TranslationTextComponent("/execute in %s run tp %s%s", dimName, cmdTarget, finalPosTarget)
|
||||
.withStyle((style) -> style.withColor(TextFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/execute in " + dimName + " run tp " + finalCmdTarget + finalPosTarget)));
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.setdim.deprecated", suggestion), true);
|
||||
Component suggestion = new TranslatableComponent("/execute in %s run tp %s%s", dimName, cmdTarget, finalPosTarget)
|
||||
.withStyle((style) -> style.withColor(ChatFormatting.GREEN).withClickEvent(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/execute in " + dimName + " run tp " + finalCmdTarget + finalPosTarget)));
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.setdim.deprecated", suggestion), true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -22,20 +22,20 @@ package net.minecraftforge.server.command;
|
||||
import java.text.DecimalFormat;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.command.arguments.DimensionArgument;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.world.DimensionType;
|
||||
import net.minecraft.world.server.ServerWorld;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.DimensionArgument;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
class CommandTps
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
|
||||
private static final long[] UNLOADED = new long[] {0};
|
||||
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("tps")
|
||||
.requires(cs->cs.hasPermission(0)) //permission
|
||||
@@ -43,20 +43,20 @@ class CommandTps
|
||||
.executes(ctx -> sendTime(ctx.getSource(), DimensionArgument.getDimension(ctx, "dim")))
|
||||
)
|
||||
.executes(ctx -> {
|
||||
for (ServerWorld dim : ctx.getSource().getServer().getAllLevels())
|
||||
for (ServerLevel dim : ctx.getSource().getServer().getAllLevels())
|
||||
sendTime(ctx.getSource(), dim);
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
double meanTickTime = mean(ctx.getSource().getServer().tickTimes) * 1.0E-6D;
|
||||
double meanTPS = Math.min(1000.0/meanTickTime, 20);
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private static int sendTime(CommandSource cs, ServerWorld dim) throws CommandSyntaxException
|
||||
private static int sendTime(CommandSourceStack cs, ServerLevel dim) throws CommandSyntaxException
|
||||
{
|
||||
long[] times = cs.getServer().getTickTime(dim.dimension());
|
||||
|
||||
@@ -66,7 +66,7 @@ class CommandTps
|
||||
final Registry<DimensionType> reg = cs.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
|
||||
double worldTickTime = mean(times) * 1.0E-6D;
|
||||
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
|
||||
cs.sendSuccess(new TranslationTextComponent("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
|
||||
cs.sendSuccess(new TranslatableComponent("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.command.CommandException;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.commands.CommandRuntimeException;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.server.timings.ForgeTimings;
|
||||
import net.minecraftforge.server.timings.TimeTracker;
|
||||
|
||||
@@ -43,19 +43,19 @@ class CommandTrack
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMAT = new DecimalFormat("#####0.00");
|
||||
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("track")
|
||||
.then(StartTrackingCommand.register())
|
||||
.then(ResetTrackingCommand.register())
|
||||
.then(TrackResultsEntity.register())
|
||||
.then(TrackResultsTileEntity.register())
|
||||
.then(TrackResultsBlockEntity.register())
|
||||
.then(StartTrackingCommand.register());
|
||||
}
|
||||
|
||||
private static class StartTrackingCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("start")
|
||||
.requires(cs->cs.hasPermission(2)) //permission
|
||||
@@ -63,9 +63,9 @@ class CommandTrack
|
||||
.then(Commands.argument("duration", IntegerArgumentType.integer(1))
|
||||
.executes(ctx -> {
|
||||
int duration = IntegerArgumentType.getInteger(ctx, "duration");
|
||||
TimeTracker.TILE_ENTITY_UPDATE.reset();
|
||||
TimeTracker.TILE_ENTITY_UPDATE.enable(duration);
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.tracking.te.enabled", duration), true);
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.reset();
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.enable(duration);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.be.enabled", duration), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
@@ -76,7 +76,7 @@ class CommandTrack
|
||||
int duration = IntegerArgumentType.getInteger(ctx, "duration");
|
||||
TimeTracker.ENTITY_UPDATE.reset();
|
||||
TimeTracker.ENTITY_UPDATE.enable(duration);
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.tracking.entity.enabled", duration), true);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.entity.enabled", duration), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
@@ -86,21 +86,21 @@ class CommandTrack
|
||||
|
||||
private static class ResetTrackingCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("reset")
|
||||
.requires(cs->cs.hasPermission(2)) //permission
|
||||
.then(Commands.literal("te")
|
||||
.executes(ctx -> {
|
||||
TimeTracker.TILE_ENTITY_UPDATE.reset();
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.tracking.te.reset"), true);
|
||||
TimeTracker.BLOCK_ENTITY_UPDATE.reset();
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.be.reset"), true);
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
.then(Commands.literal("entity")
|
||||
.executes(ctx -> {
|
||||
TimeTracker.ENTITY_UPDATE.reset();
|
||||
ctx.getSource().sendSuccess(new TranslationTextComponent("commands.forge.tracking.entity.reset"), true);
|
||||
ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tracking.entity.reset"), true);
|
||||
return 0;
|
||||
})
|
||||
);
|
||||
@@ -125,12 +125,12 @@ class CommandTrack
|
||||
return list;
|
||||
}
|
||||
|
||||
private static <T> int execute(CommandSource source, TimeTracker<T> tracker, Function<ForgeTimings<T>, ITextComponent> toString) throws CommandException
|
||||
private static <T> int execute(CommandSourceStack source, TimeTracker<T> tracker, Function<ForgeTimings<T>, Component> toString) throws CommandRuntimeException
|
||||
{
|
||||
List<ForgeTimings<T>> timingsList = getSortedTimings(tracker);
|
||||
if (timingsList.isEmpty())
|
||||
{
|
||||
source.sendSuccess(new TranslationTextComponent("commands.forge.tracking.no_data"), true);
|
||||
source.sendSuccess(new TranslatableComponent("commands.forge.tracking.no_data"), true);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -145,39 +145,39 @@ class CommandTrack
|
||||
|
||||
private static class TrackResultsEntity
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("entity").executes(ctx -> TrackResults.execute(ctx.getSource(), TimeTracker.ENTITY_UPDATE, data ->
|
||||
{
|
||||
Entity entity = data.getObject().get();
|
||||
if (entity == null)
|
||||
return new TranslationTextComponent("commands.forge.tracking.invalid");
|
||||
return new TranslatableComponent("commands.forge.tracking.invalid");
|
||||
|
||||
BlockPos pos = entity.blockPosition();
|
||||
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.level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
return new TranslatableComponent("commands.forge.tracking.timing_entry", entity.getType().getRegistryName(), entity.level.dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
})
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private static class TrackResultsTileEntity
|
||||
private static class TrackResultsBlockEntity
|
||||
{
|
||||
static ArgumentBuilder<CommandSource, ?> register()
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("te").executes(ctx -> TrackResults.execute(ctx.getSource(), TimeTracker.TILE_ENTITY_UPDATE, data ->
|
||||
return Commands.literal("te").executes(ctx -> TrackResults.execute(ctx.getSource(), TimeTracker.BLOCK_ENTITY_UPDATE, data ->
|
||||
{
|
||||
TileEntity te = data.getObject().get();
|
||||
BlockEntity te = data.getObject().get();
|
||||
if (te == null)
|
||||
return new TranslationTextComponent("commands.forge.tracking.invalid");
|
||||
return new TranslatableComponent("commands.forge.tracking.invalid");
|
||||
|
||||
BlockPos pos = te.getBlockPos();
|
||||
|
||||
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.getLevel().dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
return new TranslatableComponent("commands.forge.tracking.timing_entry", te.getType().getRegistryName(), te.getLevel().dimension().location().toString(), pos.getX(), pos.getY(), pos.getZ(), tickTime);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -22,19 +22,19 @@ package net.minecraftforge.server.command;
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.command.Commands;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.util.text.event.ClickEvent;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraftforge.fml.config.ConfigTracker;
|
||||
import net.minecraftforge.fml.config.ModConfig;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class ConfigCommand {
|
||||
public static void register(CommandDispatcher<CommandSource> dispatcher) {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||
dispatcher.register(
|
||||
Commands.literal("config").
|
||||
then(ShowFile.register())
|
||||
@@ -42,7 +42,7 @@ public class ConfigCommand {
|
||||
}
|
||||
|
||||
public static class ShowFile {
|
||||
static ArgumentBuilder<CommandSource, ?> register() {
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register() {
|
||||
return Commands.literal("showfile").
|
||||
requires(cs->cs.hasPermission(0)).
|
||||
then(Commands.argument("mod", ModIdArgument.modIdArgument()).
|
||||
@@ -52,19 +52,19 @@ public class ConfigCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private static int showFile(final CommandContext<CommandSource> context) {
|
||||
private static int showFile(final CommandContext<CommandSourceStack> context) {
|
||||
final String modId = context.getArgument("mod", String.class);
|
||||
final ModConfig.Type type = context.getArgument("type", ModConfig.Type.class);
|
||||
final String configFileName = ConfigTracker.INSTANCE.getConfigFileName(modId, type);
|
||||
if (configFileName != null) {
|
||||
File f = new File(configFileName);
|
||||
context.getSource().sendSuccess(new TranslationTextComponent("commands.config.getwithtype",
|
||||
context.getSource().sendSuccess(new TranslatableComponent("commands.config.getwithtype",
|
||||
modId, type,
|
||||
new StringTextComponent(f.getName()).withStyle(TextFormatting.UNDERLINE).
|
||||
new TextComponent(f.getName()).withStyle(ChatFormatting.UNDERLINE).
|
||||
withStyle((style) -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, f.getAbsolutePath())))
|
||||
), true);
|
||||
} else {
|
||||
context.getSource().sendSuccess(new TranslationTextComponent("commands.config.noconfig", modId, type),
|
||||
context.getSource().sendSuccess(new TranslatableComponent("commands.config.noconfig", modId, type),
|
||||
true);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -27,10 +27,10 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.Dynamic2CommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.command.arguments.IArgumentSerializer;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraft.commands.synchronization.ArgumentSerializer;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -40,7 +40,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
private static final Dynamic2CommandExceptionType INVALID_ENUM = new Dynamic2CommandExceptionType(
|
||||
(found, constants) -> new TranslationTextComponent("commands.forge.arguments.enum.invalid", constants, found));
|
||||
(found, constants) -> new TranslatableComponent("commands.forge.arguments.enum.invalid", constants, found));
|
||||
private final Class<T> enumClass;
|
||||
|
||||
public static <R extends Enum<R>> EnumArgument<R> enumArgument(Class<R> enumClass) {
|
||||
@@ -62,7 +62,7 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
|
||||
return ISuggestionProvider.suggest(Stream.of(enumClass.getEnumConstants()).map(Object::toString), builder);
|
||||
return SharedSuggestionProvider.suggest(Stream.of(enumClass.getEnumConstants()).map(Object::toString), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,17 +70,17 @@ public class EnumArgument<T extends Enum<T>> implements ArgumentType<T> {
|
||||
return Stream.of(enumClass.getEnumConstants()).map(Object::toString).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static class Serializer implements IArgumentSerializer<EnumArgument<?>>
|
||||
public static class Serializer implements ArgumentSerializer<EnumArgument<?>>
|
||||
{
|
||||
@Override
|
||||
public void serializeToNetwork(EnumArgument<?> argument, PacketBuffer buffer)
|
||||
public void serializeToNetwork(EnumArgument<?> argument, FriendlyByteBuf buffer)
|
||||
{
|
||||
buffer.writeUtf(argument.enumClass.getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@Override
|
||||
public EnumArgument<?> deserializeFromNetwork(PacketBuffer buffer)
|
||||
public EnumArgument<?> deserializeFromNetwork(FriendlyByteBuf buffer)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -21,14 +21,14 @@ package net.minecraftforge.server.command;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
|
||||
public class ForgeCommand
|
||||
{
|
||||
public ForgeCommand(CommandDispatcher<CommandSource> dispatcher)
|
||||
public ForgeCommand(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(
|
||||
LiteralArgumentBuilder.<CommandSource>literal("forge")
|
||||
LiteralArgumentBuilder.<CommandSourceStack>literal("forge")
|
||||
.then(CommandTps.register())
|
||||
.then(CommandTrack.register())
|
||||
.then(CommandEntity.register())
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||
|
||||
import net.minecraft.command.ISuggestionProvider;
|
||||
import net.minecraft.commands.SharedSuggestionProvider;
|
||||
import net.minecraftforge.fml.ModContainer;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ModIdArgument implements ArgumentType<String> {
|
||||
|
||||
@Override
|
||||
public <S> CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
|
||||
return ISuggestionProvider.suggest(ModList.get().applyForEachModContainer(ModContainer::getModId), builder);
|
||||
return SharedSuggestionProvider.suggest(ModList.get().applyForEachModContainer(ModContainer::getModId), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import net.minecraft.command.ICommandSource;
|
||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||
import net.minecraft.network.play.ServerPlayNetHandler;
|
||||
import net.minecraft.util.text.LanguageMap;
|
||||
import net.minecraft.util.text.TextComponent;
|
||||
import net.minecraft.util.text.StringTextComponent;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.fml.network.ConnectionType;
|
||||
import net.minecraftforge.fml.network.NetworkHooks;
|
||||
import net.minecraft.commands.CommandSource;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.locale.Language;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.fmllegacy.network.ConnectionType;
|
||||
import net.minecraftforge.fmllegacy.network.NetworkHooks;
|
||||
|
||||
public class TextComponentHelper
|
||||
{
|
||||
@@ -37,21 +37,21 @@ public class TextComponentHelper
|
||||
* Detects when sending to a vanilla client and falls back to sending english,
|
||||
* since they don't have the lang data necessary to translate on the client.
|
||||
*/
|
||||
public static TextComponent createComponentTranslation(ICommandSource source, final String translation, final Object... args)
|
||||
public static BaseComponent createComponentTranslation(CommandSource source, final String translation, final Object... args)
|
||||
{
|
||||
if (isVanillaClient(source))
|
||||
{
|
||||
return new StringTextComponent(String.format(LanguageMap.getInstance().getOrDefault(translation), args));
|
||||
return new TextComponent(String.format(Language.getInstance().getOrDefault(translation), args));
|
||||
}
|
||||
return new TranslationTextComponent(translation, args);
|
||||
return new TranslatableComponent(translation, args);
|
||||
}
|
||||
|
||||
private static boolean isVanillaClient(ICommandSource sender)
|
||||
private static boolean isVanillaClient(CommandSource sender)
|
||||
{
|
||||
if (sender instanceof ServerPlayerEntity)
|
||||
if (sender instanceof ServerPlayer)
|
||||
{
|
||||
ServerPlayerEntity playerMP = (ServerPlayerEntity) sender;
|
||||
ServerPlayNetHandler channel = playerMP.connection;
|
||||
ServerPlayer playerMP = (ServerPlayer) sender;
|
||||
ServerGamePacketListenerImpl channel = playerMP.connection;
|
||||
return NetworkHooks.getConnectionType(()->channel.connection) == ConnectionType.VANILLA;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -21,6 +21,6 @@
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in new issue
Block a user