-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ok now i can crack it, gotta figure out how to
- Loading branch information
Showing
9 changed files
with
344 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...main/java/net/earthcomputer/clientcommands/command/arguments/PredicatedRangeArgument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package net.earthcomputer.clientcommands.command.arguments; | ||
|
||
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.Dynamic2CommandExceptionType; | ||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; | ||
import net.minecraft.advancements.critereon.MinMaxBounds; | ||
import net.minecraft.network.chat.Component; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface PredicatedRangeArgument<T extends MinMaxBounds<?>> extends ArgumentType<T> { | ||
Dynamic2CommandExceptionType INTEGER_VALUE_TOO_LOW = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("argument.integer.low", a, b)); | ||
Dynamic2CommandExceptionType INTEGER_VALUE_TOO_HIGH = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("argument.integer.low", a, b)); | ||
Dynamic2CommandExceptionType FLOAT_VALUE_TOO_LOW = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("argument.float.low", a, b)); | ||
Dynamic2CommandExceptionType FLOAT_VALUE_TOO_HIGH = new Dynamic2CommandExceptionType((a, b) -> Component.translatable("argument.float.low", a, b)); | ||
|
||
static Ints intRange(@Nullable Integer min, @Nullable Integer max) { | ||
return new Ints(min, max); | ||
} | ||
|
||
static Floats floatRange(@Nullable Double min, @Nullable Double max) { | ||
return new Floats(min, max); | ||
} | ||
|
||
class Ints implements PredicatedRangeArgument<MinMaxBounds.Ints> { | ||
@Nullable | ||
private final Integer min; | ||
@Nullable | ||
private final Integer max; | ||
|
||
public Ints(@Nullable Integer min, @Nullable Integer max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public static MinMaxBounds.Ints getRangeArgument(final CommandContext<FabricClientCommandSource> context, final String name) { | ||
return context.getArgument(name, MinMaxBounds.Ints.class); | ||
} | ||
|
||
@Override | ||
public MinMaxBounds.Ints parse(StringReader reader) throws CommandSyntaxException { | ||
MinMaxBounds.Ints range = MinMaxBounds.Ints.fromReader(reader); | ||
if (min != null && (range.min().isEmpty() || range.min().get() < min)) { | ||
throw INTEGER_VALUE_TOO_LOW.create(min, range.min().orElse(Integer.MIN_VALUE)); | ||
} | ||
if (max != null && (range.max().isEmpty() || range.max().get() > max)) { | ||
throw INTEGER_VALUE_TOO_HIGH.create(max, range.max().orElse(Integer.MAX_VALUE)); | ||
} | ||
return range; | ||
} | ||
} | ||
|
||
class Floats implements PredicatedRangeArgument<MinMaxBounds.Doubles> { | ||
@Nullable | ||
private final Double min; | ||
@Nullable | ||
private final Double max; | ||
|
||
public Floats(@Nullable Double min, @Nullable Double max) { | ||
this.min = min; | ||
this.max = max; | ||
} | ||
|
||
public static MinMaxBounds.Doubles getRangeArgument(final CommandContext<FabricClientCommandSource> context, final String name) { | ||
return context.getArgument(name, MinMaxBounds.Doubles.class); | ||
} | ||
|
||
@Override | ||
public MinMaxBounds.Doubles parse(StringReader reader) throws CommandSyntaxException { | ||
MinMaxBounds.Doubles range = MinMaxBounds.Doubles.fromReader(reader); | ||
if (min != null && (range.min().isEmpty() || range.min().get() < min)) { | ||
throw FLOAT_VALUE_TOO_LOW.create(min, range.min().orElse(-Double.MAX_VALUE)); | ||
} | ||
if (max != null && (range.max().isEmpty() || range.max().get() < max)) { | ||
throw FLOAT_VALUE_TOO_HIGH.create(max, range.max().orElse(Double.MAX_VALUE)); | ||
} | ||
return range; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.