Fix range arguments
This commit is contained in:
@@ -21,31 +21,33 @@ public class RangeArgument<T extends Number> implements IDeserializableArgument
|
|||||||
|
|
||||||
public void setExact(@Nullable T value)
|
public void setExact(@Nullable T value)
|
||||||
{
|
{
|
||||||
this.min = Optional.of(value);
|
this.min = Optional.ofNullable(value);
|
||||||
this.max = Optional.of(value);
|
this.max = Optional.ofNullable(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRange(@Nullable T min, @Nullable T max)
|
public void setRange(@Nullable T min, @Nullable T max)
|
||||||
{
|
{
|
||||||
this.min = Optional.of(min);
|
this.min = Optional.ofNullable(min);
|
||||||
this.max = Optional.of(max);
|
this.max = Optional.ofNullable(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMin(@Nullable T min)
|
public void setMin(@Nullable T min)
|
||||||
{
|
{
|
||||||
this.min = Optional.of(min);
|
this.min = Optional.ofNullable(min);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMax(@Nullable T max)
|
public void setMax(@Nullable T max)
|
||||||
{
|
{
|
||||||
this.max = Optional.of(max);
|
this.max = Optional.ofNullable(max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public T getMin()
|
public T getMin()
|
||||||
{
|
{
|
||||||
return this.min.orElse(null);
|
return this.min.orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public T getMax()
|
public T getMax()
|
||||||
{
|
{
|
||||||
return this.max.orElse(null);
|
return this.max.orElse(null);
|
||||||
@@ -71,12 +73,12 @@ public class RangeArgument<T extends Number> implements IDeserializableArgument
|
|||||||
@Nullable
|
@Nullable
|
||||||
public String serialize()
|
public String serialize()
|
||||||
{
|
{
|
||||||
return Util.serializeBounds(this.min, this.max);
|
return Util.serializeBounds(this.getMin(), this.getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDefault()
|
public boolean isDefault()
|
||||||
{
|
{
|
||||||
return this.min == null && this.max == null;
|
return this.min.isEmpty() && this.max.isEmpty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package exopandora.worldhandler.builder.argument;
|
package exopandora.worldhandler.builder.argument;
|
||||||
|
|
||||||
|
import java.util.AbstractMap.SimpleEntry;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -23,7 +25,7 @@ public class TargetArgument implements IArgument
|
|||||||
@Nullable
|
@Nullable
|
||||||
private String selectorType;
|
private String selectorType;
|
||||||
private NegatableCriterion<String> name = new NegatableCriterion<String>();
|
private NegatableCriterion<String> name = new NegatableCriterion<String>();
|
||||||
private MinMaxBounds.Doubles distance = MinMaxBounds.Doubles.ANY;
|
private DoubleMinMaxBounds distance = DoubleMinMaxBounds.ANY;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Double x;
|
private Double x;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -47,7 +49,7 @@ public class TargetArgument implements IArgument
|
|||||||
private Map<ResourceLocation, Boolean> advancements;
|
private Map<ResourceLocation, Boolean> advancements;
|
||||||
private List<NegatableCriterion<ResourceLocation>> predicates;
|
private List<NegatableCriterion<ResourceLocation>> predicates;
|
||||||
private NegatableCriterion<String> team = new NegatableCriterion<String>();
|
private NegatableCriterion<String> team = new NegatableCriterion<String>();
|
||||||
private Map<String, MinMaxBounds.Ints> scores;
|
private Map<String, IntMinMaxBounds> scores;
|
||||||
@Nullable
|
@Nullable
|
||||||
private NegatableCriterion<Gamemode> gamemode = new NegatableCriterion<Gamemode>();
|
private NegatableCriterion<Gamemode> gamemode = new NegatableCriterion<Gamemode>();
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -86,26 +88,22 @@ public class TargetArgument implements IArgument
|
|||||||
|
|
||||||
public void setDistance(@Nullable Double distance)
|
public void setDistance(@Nullable Double distance)
|
||||||
{
|
{
|
||||||
this.distance = MinMaxBounds.Doubles.exactly(distance);
|
this.distance = new DoubleMinMaxBounds(distance, distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDistance(@Nullable Double min, @Nullable Double max)
|
public void setDistance(@Nullable Double min, @Nullable Double max)
|
||||||
{
|
{
|
||||||
this.distance = MinMaxBounds.Doubles.between(min, max);
|
this.distance = new DoubleMinMaxBounds(min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDistanceMin(@Nullable Double min)
|
public void setDistanceMin(@Nullable Double min)
|
||||||
{
|
{
|
||||||
this.distance = this.distance.max()
|
this.distance = new DoubleMinMaxBounds(min, this.distance.getMax());
|
||||||
.map(max -> MinMaxBounds.Doubles.between(min, max))
|
|
||||||
.orElseGet(() -> MinMaxBounds.Doubles.exactly(min));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDistanceMax(@Nullable Double max)
|
public void setDistanceMax(@Nullable Double max)
|
||||||
{
|
{
|
||||||
this.distance = this.distance.min()
|
this.distance = new DoubleMinMaxBounds(this.distance.getMin(), max);
|
||||||
.map(min -> MinMaxBounds.Doubles.between(min, max))
|
|
||||||
.orElseGet(() -> MinMaxBounds.Doubles.exactly(max));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setX(@Nullable Double x)
|
public void setX(@Nullable Double x)
|
||||||
@@ -282,48 +280,40 @@ public class TargetArgument implements IArgument
|
|||||||
{
|
{
|
||||||
if(this.scores == null)
|
if(this.scores == null)
|
||||||
{
|
{
|
||||||
this.scores = new HashMap<String, MinMaxBounds.Ints>();
|
this.scores = new HashMap<String, IntMinMaxBounds>();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scores.put(score, MinMaxBounds.Ints.exactly(value));
|
this.scores.put(score, IntMinMaxBounds.exactly(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(String score, @Nullable Integer min, @Nullable Integer max)
|
public void setScore(String score, @Nullable Integer min, @Nullable Integer max)
|
||||||
{
|
{
|
||||||
if(this.scores == null)
|
if(this.scores == null)
|
||||||
{
|
{
|
||||||
this.scores = new HashMap<String, MinMaxBounds.Ints>();
|
this.scores = new HashMap<String, IntMinMaxBounds>();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scores.put(score, MinMaxBounds.Ints.between(min, max));
|
this.scores.put(score, new IntMinMaxBounds(min, max));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScoreMin(String score, @Nullable Integer min)
|
public void setScoreMin(String score, @Nullable Integer min)
|
||||||
{
|
{
|
||||||
if(this.scores == null)
|
if(this.scores == null)
|
||||||
{
|
{
|
||||||
this.scores = new HashMap<String, MinMaxBounds.Ints>();
|
this.scores = new HashMap<String, IntMinMaxBounds>();
|
||||||
}
|
}
|
||||||
|
|
||||||
MinMaxBounds.Ints bounds = this.scores.getOrDefault(score, MinMaxBounds.Ints.ANY).max()
|
this.scores.put(score, new IntMinMaxBounds(min, this.scores.getOrDefault(score, IntMinMaxBounds.ANY).getMax()));
|
||||||
.map(max -> MinMaxBounds.Ints.between(min, max))
|
|
||||||
.orElseGet(() -> MinMaxBounds.Ints.exactly(min));
|
|
||||||
|
|
||||||
this.scores.put(score, bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScoreMax(String score, @Nullable Integer max)
|
public void setScoreMax(String score, @Nullable Integer max)
|
||||||
{
|
{
|
||||||
if(this.scores == null)
|
if(this.scores == null)
|
||||||
{
|
{
|
||||||
this.scores = new HashMap<String, MinMaxBounds.Ints>();
|
this.scores = new HashMap<String, IntMinMaxBounds>();
|
||||||
}
|
}
|
||||||
|
|
||||||
MinMaxBounds.Ints bounds = this.scores.getOrDefault(score, MinMaxBounds.Ints.ANY).min()
|
this.scores.put(score, new IntMinMaxBounds(this.scores.getOrDefault(score, IntMinMaxBounds.ANY).getMin(), max));
|
||||||
.map(min -> MinMaxBounds.Ints.between(min, max))
|
|
||||||
.orElseGet(() -> MinMaxBounds.Ints.exactly(max));
|
|
||||||
|
|
||||||
this.scores.put(score, bounds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGamemode(@Nullable Gamemode gamemode)
|
public void setGamemode(@Nullable Gamemode gamemode)
|
||||||
@@ -366,7 +356,7 @@ public class TargetArgument implements IArgument
|
|||||||
|
|
||||||
public MinMaxBounds.Doubles getDistance()
|
public MinMaxBounds.Doubles getDistance()
|
||||||
{
|
{
|
||||||
return this.distance;
|
return this.distance.toMinMaxBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -457,7 +447,9 @@ public class TargetArgument implements IArgument
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Map<String, MinMaxBounds.Ints> getScores()
|
public Map<String, MinMaxBounds.Ints> getScores()
|
||||||
{
|
{
|
||||||
return this.scores;
|
return this.scores.entrySet().stream()
|
||||||
|
.map(entry -> new SimpleEntry<String, MinMaxBounds.Ints>(entry.getKey(), entry.getValue().toMinMaxBounds()))
|
||||||
|
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public NegatableCriterion<Gamemode> getGamemode()
|
public NegatableCriterion<Gamemode> getGamemode()
|
||||||
@@ -488,7 +480,7 @@ public class TargetArgument implements IArgument
|
|||||||
List<String> criteria = new ArrayList<String>();
|
List<String> criteria = new ArrayList<String>();
|
||||||
|
|
||||||
this.append("name", this.name, criteria, TargetArgument::serializeNegatableCriterion);
|
this.append("name", this.name, criteria, TargetArgument::serializeNegatableCriterion);
|
||||||
this.append("distance", this.distance, criteria, TargetArgument::serializeMinMaxBounds);
|
this.append("distance", this.distance, criteria, TargetArgument::serializeDoubleMinMaxBounds);
|
||||||
this.append("x", this.x, criteria);
|
this.append("x", this.x, criteria);
|
||||||
this.append("y", this.y, criteria);
|
this.append("y", this.y, criteria);
|
||||||
this.append("z", this.z, criteria);
|
this.append("z", this.z, criteria);
|
||||||
@@ -504,7 +496,7 @@ public class TargetArgument implements IArgument
|
|||||||
this.appendMap("advancements", this.advancements, criteria, ResourceLocation::toString, b -> b.toString());
|
this.appendMap("advancements", this.advancements, criteria, ResourceLocation::toString, b -> b.toString());
|
||||||
this.appendList("predicate", this.predicates, criteria, TargetArgument::serializeNegatableCriterion);
|
this.appendList("predicate", this.predicates, criteria, TargetArgument::serializeNegatableCriterion);
|
||||||
this.append("team", this.team, criteria, TargetArgument::serializeNegatableCriterion);
|
this.append("team", this.team, criteria, TargetArgument::serializeNegatableCriterion);
|
||||||
this.appendMap("scores", this.scores, criteria, String::toString, TargetArgument::serializeMinMaxBounds);
|
this.appendMap("scores", this.scores, criteria, String::toString, TargetArgument::serializeIntMinMaxBounds);
|
||||||
this.append("gamemode", this.gamemode, criteria, TargetArgument::serializeNegatableCriterion);
|
this.append("gamemode", this.gamemode, criteria, TargetArgument::serializeNegatableCriterion);
|
||||||
this.append("sort", this.sort, criteria);
|
this.append("sort", this.sort, criteria);
|
||||||
|
|
||||||
@@ -561,9 +553,15 @@ public class TargetArgument implements IArgument
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static String serializeMinMaxBounds(MinMaxBounds<?> bounds)
|
private static String serializeDoubleMinMaxBounds(DoubleMinMaxBounds bounds)
|
||||||
{
|
{
|
||||||
return Util.serializeBounds(bounds.min(), bounds.max());
|
return Util.serializeBounds(bounds.getMin(), bounds.getMax());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String serializeIntMinMaxBounds(IntMinMaxBounds bounds)
|
||||||
|
{
|
||||||
|
return Util.serializeBounds(bounds.getMin(), bounds.getMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -596,6 +594,73 @@ public class TargetArgument implements IArgument
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class DoubleMinMaxBounds
|
||||||
|
{
|
||||||
|
public static final DoubleMinMaxBounds ANY = new DoubleMinMaxBounds(null, null);
|
||||||
|
|
||||||
|
private final Double min;
|
||||||
|
private final Double max;
|
||||||
|
|
||||||
|
public DoubleMinMaxBounds(Double min, Double max)
|
||||||
|
{
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinMaxBounds.Doubles toMinMaxBounds()
|
||||||
|
{
|
||||||
|
return new MinMaxBounds.Doubles(Optional.ofNullable(this.min), Optional.ofNullable(this.max));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Double getMin()
|
||||||
|
{
|
||||||
|
return this.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Double getMax()
|
||||||
|
{
|
||||||
|
return this.max;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class IntMinMaxBounds
|
||||||
|
{
|
||||||
|
public static final IntMinMaxBounds ANY = new IntMinMaxBounds(null, null);
|
||||||
|
|
||||||
|
private final Integer min;
|
||||||
|
private final Integer max;
|
||||||
|
|
||||||
|
public IntMinMaxBounds(Integer min, Integer max)
|
||||||
|
{
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MinMaxBounds.Ints toMinMaxBounds()
|
||||||
|
{
|
||||||
|
return new MinMaxBounds.Ints(Optional.ofNullable(this.min), Optional.ofNullable(this.max));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getMin()
|
||||||
|
{
|
||||||
|
return this.min;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Integer getMax()
|
||||||
|
{
|
||||||
|
return this.max;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IntMinMaxBounds exactly(@Nullable Integer value)
|
||||||
|
{
|
||||||
|
return new IntMinMaxBounds(value, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class NegatableCriterion<T>
|
public static class NegatableCriterion<T>
|
||||||
{
|
{
|
||||||
private T criterion;
|
private T criterion;
|
||||||
@@ -661,4 +726,4 @@ public class TargetArgument implements IArgument
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,9 @@
|
|||||||
package exopandora.worldhandler.util;
|
package exopandora.worldhandler.util;
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class Util
|
public class Util
|
||||||
{
|
{
|
||||||
@Nullable
|
|
||||||
public static <T extends Number, S extends Number> String serializeBounds(Optional<T> minBound, Optional<S> maxBound)
|
|
||||||
{
|
|
||||||
return serializeBounds(minBound.orElse(null), maxBound.orElse(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static String serializeBounds(@Nullable Number minBound, @Nullable Number maxBound)
|
public static String serializeBounds(@Nullable Number minBound, @Nullable Number maxBound)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ public net.minecraft.server.MinecraftServer f_129744_ # storageSource
|
|||||||
public net.minecraft.client.gui.screens.OptionsScreen m_96244_(Lnet/minecraft/server/packs/repository/PackRepository;)V # updatePackList
|
public net.minecraft.client.gui.screens.OptionsScreen m_96244_(Lnet/minecraft/server/packs/repository/PackRepository;)V # updatePackList
|
||||||
public net.minecraft.commands.arguments.EntityAnchorArgument$Anchor f_90367_ # name
|
public net.minecraft.commands.arguments.EntityAnchorArgument$Anchor f_90367_ # name
|
||||||
public net.minecraft.commands.arguments.coordinates.LocalCoordinates m_119908_(Lcom/mojang/brigadier/StringReader;I)D # readDouble
|
public net.minecraft.commands.arguments.coordinates.LocalCoordinates m_119908_(Lcom/mojang/brigadier/StringReader;I)D # readDouble
|
||||||
|
public net.minecraft.advancements.critereon.MinMaxBounds$Doubles <init>(Ljava/util/Optional;Ljava/util/Optional;)V # constructor
|
||||||
|
public net.minecraft.advancements.critereon.MinMaxBounds$Ints <init>(Ljava/util/Optional;Ljava/util/Optional;)V # constructor
|
||||||
public net.minecraft.network.chat.MutableComponent <init>(Lnet/minecraft/network/chat/ComponentContents;Ljava/util/List;Lnet/minecraft/network/chat/Style;)V # constructor
|
public net.minecraft.network.chat.MutableComponent <init>(Lnet/minecraft/network/chat/ComponentContents;Ljava/util/List;Lnet/minecraft/network/chat/Style;)V # constructor
|
||||||
public net.minecraft.commands.arguments.item.ItemParser f_120991_ # ERROR_NO_TAGS_ALLOWED
|
public net.minecraft.commands.arguments.item.ItemParser f_120991_ # ERROR_NO_TAGS_ALLOWED
|
||||||
public net.minecraft.world.level.storage.PrimaryLevelData f_78443_ # settings
|
public net.minecraft.world.level.storage.PrimaryLevelData f_78443_ # settings
|
||||||
|
|||||||
Reference in New Issue
Block a user