mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 12:42:26 +00:00
Initial port to 1.18
Co-authored-by: David Quintana <[email protected]> Co-authored-by: SizableShrimp <[email protected]>
This commit is contained in:
1 parent
be0a6819ac
commit
40a174310d
538 files changed
+3322
-9030
No files matched your search
@@ -1,100 +0,0 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.server.command;
|
||||
|
||||
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;
|
||||
import com.mojang.brigadier.context.ParsedCommandNode;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.tree.ArgumentCommandNode;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/** @deprecated For removal in 1.18, superseded by {@code /execute in <dim> run tp <targets>} */
|
||||
@Deprecated(forRemoval = true, since = "1.17.1")
|
||||
public class CommandSetDimension
|
||||
{
|
||||
private static final SimpleCommandExceptionType NO_ENTITIES = new SimpleCommandExceptionType(new TranslatableComponent("commands.forge.setdim.invalid.entity"));
|
||||
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.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<CommandSourceStack> ctx, Collection<? extends Entity> entities, ServerLevel dim, BlockPos pos) throws CommandSyntaxException
|
||||
{
|
||||
entities.removeIf(e -> !canEntityTeleport(e));
|
||||
if (entities.isEmpty())
|
||||
throw NO_ENTITIES.create();
|
||||
|
||||
String cmdTarget = "@s";
|
||||
String posTarget = "~ ~ ~";
|
||||
for (ParsedCommandNode<CommandSourceStack> parsed : ctx.getNodes())
|
||||
{
|
||||
if (parsed.getNode() instanceof ArgumentCommandNode)
|
||||
{
|
||||
if ("targets".equals(parsed.getNode().getName()))
|
||||
{
|
||||
cmdTarget = parsed.getRange().get(ctx.getInput());
|
||||
}
|
||||
else if ("pos".equals(parsed.getNode().getName()))
|
||||
{
|
||||
posTarget = parsed.getRange().get(ctx.getInput());
|
||||
}
|
||||
}
|
||||
}
|
||||
final String dimName = dim.dimension().location().toString();
|
||||
final String finalCmdTarget = cmdTarget;
|
||||
final String finalPosTarget = posTarget;
|
||||
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;
|
||||
}
|
||||
|
||||
private static boolean canEntityTeleport(Entity entity)
|
||||
{
|
||||
// use vanilla portal logic from BlockPortal#onEntityCollision
|
||||
return !entity.isPassenger() && !entity.isVehicle() && entity.canChangeDimensions();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -36,7 +36,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||
|
||||
public class CommandDimensions
|
||||
class DimensionsCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
+1
-1
@@ -49,7 +49,7 @@ import net.minecraftforge.registries.ForgeRegistries;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
class CommandEntity
|
||||
class EntityCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
@@ -29,13 +29,12 @@ public class ForgeCommand
|
||||
{
|
||||
dispatcher.register(
|
||||
LiteralArgumentBuilder.<CommandSourceStack>literal("forge")
|
||||
.then(CommandTps.register())
|
||||
.then(CommandTrack.register())
|
||||
.then(CommandEntity.register())
|
||||
.then(CommandGenerate.register())
|
||||
.then(CommandDimensions.register())
|
||||
.then(CommandSetDimension.register())
|
||||
.then(CommandModList.register())
|
||||
.then(TPSCommand.register())
|
||||
.then(TrackCommand.register())
|
||||
.then(EntityCommand.register())
|
||||
.then(GenerateCommand.register())
|
||||
.then(DimensionsCommand.register())
|
||||
.then(ModListCommand.register())
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -32,7 +32,7 @@ import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraftforge.common.WorldWorkerManager;
|
||||
|
||||
class CommandGenerate
|
||||
class GenerateCommand
|
||||
{
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
+1
-1
@@ -26,7 +26,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.fml.ModList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CommandModList {
|
||||
class ModListCommand {
|
||||
static ArgumentBuilder<CommandSourceStack, ?> register()
|
||||
{
|
||||
return Commands.literal("mods")
|
||||
+1
-1
@@ -30,7 +30,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
class CommandTps
|
||||
class TPSCommand
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMATTER = new DecimalFormat("########0.000");
|
||||
private static final long[] UNLOADED = new long[] {0};
|
||||
@@ -26,8 +26,8 @@ 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;
|
||||
import net.minecraftforge.network.ConnectionType;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class TextComponentHelper
|
||||
{
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraftforge.server.timings.ForgeTimings;
|
||||
import net.minecraftforge.server.timings.TimeTracker;
|
||||
|
||||
class CommandTrack
|
||||
class TrackCommand
|
||||
{
|
||||
private static final DecimalFormat TIME_FORMAT = new DecimalFormat("#####0.00");
|
||||
|
||||
Reference in new issue
Block a user