From 66ac1ea70b7d749db96ee274f646f8a3e4e46c93 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:53:29 +0300 Subject: Clean up decompiled code --- .../argumenttypes/ClientBlockPosArgumentType.java | 46 ++++++++-------------- 1 file changed, 16 insertions(+), 30 deletions(-) (limited to 'src/main/java/de/hysky') diff --git a/src/main/java/de/hysky/skyblocker/utils/command/argumenttypes/ClientBlockPosArgumentType.java b/src/main/java/de/hysky/skyblocker/utils/command/argumenttypes/ClientBlockPosArgumentType.java index 484606ec..1257c1e4 100644 --- a/src/main/java/de/hysky/skyblocker/utils/command/argumenttypes/ClientBlockPosArgumentType.java +++ b/src/main/java/de/hysky/skyblocker/utils/command/argumenttypes/ClientBlockPosArgumentType.java @@ -4,46 +4,39 @@ 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 net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.client.world.ClientWorld; import net.minecraft.command.CommandSource; +import net.minecraft.command.argument.BlockPosArgumentType; import net.minecraft.server.command.CommandManager; -import net.minecraft.text.Text; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.concurrent.CompletableFuture; -public class ClientBlockPosArgumentType implements ArgumentType { - private static final Collection EXAMPLES = Arrays.asList("0 0 0", "~ ~ ~", "^ ^ ^", "^1 ^ ^-5", "~0.5 ~1 ~-5"); - public static final SimpleCommandExceptionType UNLOADED_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("argument.pos.unloaded")); - public static final SimpleCommandExceptionType OUT_OF_WORLD_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("argument.pos.outofworld")); - public static final SimpleCommandExceptionType OUT_OF_BOUNDS_EXCEPTION = new SimpleCommandExceptionType(Text.translatable("argument.pos.outofbounds")); +import static net.minecraft.command.argument.BlockPosArgumentType.*; +// Uses the static fields of BlockPosArgumentType to not create the same field twice +public class ClientBlockPosArgumentType implements ArgumentType { public static ClientBlockPosArgumentType blockPos() { return new ClientBlockPosArgumentType(); } public static BlockPos getLoadedBlockPos(CommandContext context, String name) throws CommandSyntaxException { - ClientWorld clientWorld = context.getSource().getWorld(); - return getLoadedBlockPos(context, clientWorld, name); + return getLoadedBlockPos(context, context.getSource().getWorld(), name); } public static BlockPos getLoadedBlockPos(CommandContext context, ClientWorld world, String name) throws CommandSyntaxException { BlockPos blockPos = getBlockPos(context, name); - if (!world.isChunkLoaded(blockPos)) { - throw UNLOADED_EXCEPTION.create(); - } else if (!world.isInBuildLimit(blockPos)) { - throw OUT_OF_WORLD_EXCEPTION.create(); - } else { - return blockPos; - } + if (!world.isChunkLoaded(blockPos)) throw UNLOADED_EXCEPTION.create(); + if (!world.isInBuildLimit(blockPos)) throw OUT_OF_WORLD_EXCEPTION.create(); + + return blockPos; + } public static BlockPos getBlockPos(CommandContext context, String name) { @@ -65,23 +58,16 @@ public class ClientBlockPosArgumentType implements ArgumentType CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { - if (!(context.getSource() instanceof CommandSource)) { - return Suggestions.empty(); - } else { - String string = builder.getRemaining(); - Collection collection; - if (!string.isEmpty() && string.charAt(0) == '^') { - collection = Collections.singleton(CommandSource.RelativePosition.ZERO_LOCAL); - } else { - collection = ((CommandSource)context.getSource()).getBlockPositionSuggestions(); - } + if (!(context.getSource() instanceof CommandSource commandSource)) return Suggestions.empty(); - return CommandSource.suggestPositions(string, collection, builder, CommandManager.getCommandValidator(this::parse)); - } + String string = builder.getRemaining(); + Collection collection = !string.isEmpty() && string.charAt(0) == '^' ? Collections.singleton(CommandSource.RelativePosition.ZERO_LOCAL) : commandSource.getBlockPositionSuggestions(); + + return CommandSource.suggestPositions(string, collection, builder, CommandManager.getCommandValidator(this::parse)); } @Override public Collection getExamples() { - return EXAMPLES; + return BlockPosArgumentType.EXAMPLES; } } -- cgit