mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +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;
|
||||
@@ -23,7 +23,7 @@ import com.mojang.brigadier.ParseResults;
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.brigadier.suggestion.Suggestions;
|
||||
import net.minecraft.command.CommandSource;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.server.dedicated.DedicatedServer;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -70,7 +70,7 @@ final class ConsoleCommandCompleter implements Completer
|
||||
|
||||
try
|
||||
{
|
||||
ParseResults<CommandSource> results = this.server.getCommands().getDispatcher().parse(stringReader, this.server.createCommandSourceStack());
|
||||
ParseResults<CommandSourceStack> results = this.server.getCommands().getDispatcher().parse(stringReader, this.server.createCommandSourceStack());
|
||||
Suggestions tabComplete = this.server.getCommands().getDispatcher().getCompletionSuggestions(results).get();
|
||||
for (Suggestion suggestion : tabComplete.getList())
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.minecraftforge.server.permission;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraftforge.fml.server.ServerLifecycleHooks;
|
||||
import net.minecraftforge.fmllegacy.server.ServerLifecycleHooks;
|
||||
import net.minecraftforge.server.permission.context.IContext;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -21,7 +21,7 @@ package net.minecraftforge.server.permission;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.server.permission.context.IContext;
|
||||
import net.minecraftforge.server.permission.context.PlayerContext;
|
||||
|
||||
@@ -90,7 +90,7 @@ public class PermissionAPI
|
||||
*
|
||||
* @see PermissionAPI#hasPermission(GameProfile, String, IContext)
|
||||
*/
|
||||
public static boolean hasPermission(PlayerEntity player, String node)
|
||||
public static boolean hasPermission(Player player, String node)
|
||||
{
|
||||
Preconditions.checkNotNull(player, "Player can't be null!");
|
||||
return hasPermission(player.getGameProfile(), node, new PlayerContext(player));
|
||||
|
||||
@@ -20,16 +20,16 @@
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class AreaContext extends PlayerContext
|
||||
{
|
||||
private final AxisAlignedBB area;
|
||||
private final AABB area;
|
||||
|
||||
public AreaContext(PlayerEntity ep, AxisAlignedBB aabb)
|
||||
public AreaContext(Player ep, AABB aabb)
|
||||
{
|
||||
super(ep);
|
||||
area = Preconditions.checkNotNull(aabb, "AxisAlignedBB can't be null in AreaContext!");
|
||||
|
||||
@@ -20,11 +20,11 @@
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class BlockPosContext extends PlayerContext
|
||||
private BlockState blockState;
|
||||
private Direction facing;
|
||||
|
||||
public BlockPosContext(PlayerEntity ep, BlockPos pos, @Nullable BlockState state, @Nullable Direction f)
|
||||
public BlockPosContext(Player ep, BlockPos pos, @Nullable BlockState state, @Nullable Direction f)
|
||||
{
|
||||
super(ep);
|
||||
blockPos = Preconditions.checkNotNull(pos, "BlockPos can't be null in BlockPosContext!");
|
||||
@@ -42,7 +42,7 @@ public class BlockPosContext extends PlayerContext
|
||||
facing = f;
|
||||
}
|
||||
|
||||
public BlockPosContext(PlayerEntity ep, ChunkPos pos)
|
||||
public BlockPosContext(Player ep, ChunkPos pos)
|
||||
{
|
||||
this(ep, new BlockPos(pos.getMinBlockX() + 8, 0, pos.getMinBlockZ() + 8), null, null);
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
@@ -32,14 +32,14 @@ public class Context implements IContext
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public World getWorld()
|
||||
public Level getWorld()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PlayerEntity getPlayer()
|
||||
public Player getPlayer()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.Direction;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
/**
|
||||
* Some default context keys, for easier compatibility
|
||||
@@ -41,6 +41,6 @@ public class ContextKeys
|
||||
public static final ContextKey<Entity> TARGET = ContextKey.create("target", Entity.class);
|
||||
|
||||
public static final ContextKey<Direction> FACING = ContextKey.create("facing", Direction.class);
|
||||
public static final ContextKey<AxisAlignedBB> AREA = ContextKey.create("area", AxisAlignedBB.class);
|
||||
public static final ContextKey<AABB> AREA = ContextKey.create("area", AABB.class);
|
||||
public static final ContextKey<BlockState> BLOCK_STATE = ContextKey.create("blockstate", BlockState.class);
|
||||
}
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -33,13 +33,13 @@ public interface IContext
|
||||
* World from where permission is requested. Can be null
|
||||
*/
|
||||
@Nullable
|
||||
World getWorld();
|
||||
Level getWorld();
|
||||
|
||||
/**
|
||||
* @return Player requesting permission. Can be null
|
||||
*/
|
||||
@Nullable
|
||||
PlayerEntity getPlayer();
|
||||
Player getPlayer();
|
||||
|
||||
/**
|
||||
* @param key Context key
|
||||
|
||||
@@ -20,26 +20,26 @@
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class PlayerContext extends Context
|
||||
{
|
||||
private final PlayerEntity player;
|
||||
private final Player player;
|
||||
|
||||
public PlayerContext(PlayerEntity ep)
|
||||
public PlayerContext(Player ep)
|
||||
{
|
||||
player = Preconditions.checkNotNull(ep, "Player can't be null in PlayerContext!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
public Level getWorld()
|
||||
{
|
||||
return player.getCommandSenderWorld();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerEntity getPlayer()
|
||||
public Player getPlayer()
|
||||
{
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TargetContext extends PlayerContext
|
||||
{
|
||||
private final Entity target;
|
||||
|
||||
public TargetContext(PlayerEntity ep, @Nullable Entity entity)
|
||||
public TargetContext(Player ep, @Nullable Entity entity)
|
||||
{
|
||||
super(ep);
|
||||
target = entity;
|
||||
|
||||
@@ -20,29 +20,29 @@
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WorldContext extends Context
|
||||
{
|
||||
private final World world;
|
||||
private final Level world;
|
||||
|
||||
public WorldContext(World w)
|
||||
public WorldContext(Level w)
|
||||
{
|
||||
world = Preconditions.checkNotNull(w, "World can't be null in WorldContext!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
public Level getWorld()
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public PlayerEntity getPlayer()
|
||||
public Player getPlayer()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@mcp.MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraftforge.server.permission.context;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -17,6 +17,10 @@
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@javax.annotation.ParametersAreNonnullByDefault
|
||||
@mcp.MethodsReturnNonnullByDefault
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraftforge.server.permission;
|
||||
|
||||
import net.minecraft.MethodsReturnNonnullByDefault;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -20,7 +20,6 @@
|
||||
package net.minecraftforge.server.timings;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* ForgeTimings aggregates timings data collected by {@link TimeTracker} for an Object
|
||||
|
||||
@@ -27,8 +27,8 @@ import java.util.concurrent.TimeUnit;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
|
||||
/**
|
||||
* A class to assist in the collection of data to measure the update times of ticking objects {currently Tile Entities and Entities}
|
||||
@@ -41,7 +41,7 @@ public class TimeTracker<T>
|
||||
/**
|
||||
* A tracker for timing tile entity update
|
||||
*/
|
||||
public static final TimeTracker<TileEntity> TILE_ENTITY_UPDATE = new TimeTracker<>();
|
||||
public static final TimeTracker<BlockEntity> BLOCK_ENTITY_UPDATE = new TimeTracker<>();
|
||||
/**
|
||||
* A tracker for timing entity updates
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user