2025-11-24 22:52:51 +03:00

99 lines
4.6 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.mojang.brigadier.Message
* com.mojang.brigadier.StringReader
* com.mojang.brigadier.arguments.ArgumentType
* com.mojang.brigadier.context.CommandContext
* com.mojang.brigadier.exceptions.CommandSyntaxException
* com.mojang.brigadier.exceptions.SimpleCommandExceptionType
* com.mojang.brigadier.suggestion.Suggestions
* com.mojang.brigadier.suggestion.SuggestionsBuilder
*/
package net.minecraft.commands.arguments.coordinates;
import com.mojang.brigadier.Message;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraft.commands.SharedSuggestionProvider;
import net.minecraft.commands.arguments.coordinates.Coordinates;
import net.minecraft.commands.arguments.coordinates.LocalCoordinates;
import net.minecraft.commands.arguments.coordinates.WorldCoordinates;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.Level;
public class BlockPosArgument
implements ArgumentType<Coordinates> {
private static final Collection<String> EXAMPLES = Arrays.asList("0 0 0", "~ ~ ~", "^ ^ ^", "^1 ^ ^-5", "~0.5 ~1 ~-5");
public static final SimpleCommandExceptionType ERROR_NOT_LOADED = new SimpleCommandExceptionType((Message)Component.translatable("argument.pos.unloaded"));
public static final SimpleCommandExceptionType ERROR_OUT_OF_WORLD = new SimpleCommandExceptionType((Message)Component.translatable("argument.pos.outofworld"));
public static final SimpleCommandExceptionType ERROR_OUT_OF_BOUNDS = new SimpleCommandExceptionType((Message)Component.translatable("argument.pos.outofbounds"));
public static BlockPosArgument blockPos() {
return new BlockPosArgument();
}
public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
ServerLevel level = ((CommandSourceStack)context.getSource()).getLevel();
return BlockPosArgument.getLoadedBlockPos(context, level, name);
}
public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, ServerLevel level, String name) throws CommandSyntaxException {
BlockPos pos = BlockPosArgument.getBlockPos(context, name);
if (!level.hasChunkAt(pos)) {
throw ERROR_NOT_LOADED.create();
}
if (!level.isInWorldBounds(pos)) {
throw ERROR_OUT_OF_WORLD.create();
}
return pos;
}
public static BlockPos getBlockPos(CommandContext<CommandSourceStack> context, String name) {
return ((Coordinates)context.getArgument(name, Coordinates.class)).getBlockPos((CommandSourceStack)context.getSource());
}
public static BlockPos getSpawnablePos(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
BlockPos pos = BlockPosArgument.getBlockPos(context, name);
if (!Level.isInSpawnableBounds(pos)) {
throw ERROR_OUT_OF_BOUNDS.create();
}
return pos;
}
public Coordinates parse(StringReader reader) throws CommandSyntaxException {
if (reader.canRead() && reader.peek() == '^') {
return LocalCoordinates.parse(reader);
}
return WorldCoordinates.parseInt(reader);
}
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
if (context.getSource() instanceof SharedSuggestionProvider) {
String remainder = builder.getRemaining();
Collection<SharedSuggestionProvider.TextCoordinates> suggestedCoordinates = !remainder.isEmpty() && remainder.charAt(0) == '^' ? Collections.singleton(SharedSuggestionProvider.TextCoordinates.DEFAULT_LOCAL) : ((SharedSuggestionProvider)context.getSource()).getRelevantCoordinates();
return SharedSuggestionProvider.suggestCoordinates(remainder, suggestedCoordinates, builder, Commands.createValidator(this::parse));
}
return Suggestions.empty();
}
public Collection<String> getExamples() {
return EXAMPLES;
}
}