-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into envinitwithdata
- Loading branch information
Showing
54 changed files
with
1,118 additions
and
883 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
85 changes: 85 additions & 0 deletions
85
Common/src/main/java/at/petrak/hexcasting/api/advancements/MinMaxLongs.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,85 @@ | ||
package at.petrak.hexcasting.api.advancements; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.mojang.brigadier.StringReader; | ||
import com.mojang.brigadier.exceptions.BuiltInExceptionProvider; | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException; | ||
import net.minecraft.advancements.critereon.MinMaxBounds; | ||
import net.minecraft.util.GsonHelper; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Objects; | ||
import java.util.function.Function; | ||
|
||
public class MinMaxLongs extends MinMaxBounds<Long> { | ||
public static final MinMaxLongs ANY = new MinMaxLongs(null, null); | ||
@Nullable | ||
private final Long minSq; | ||
@Nullable | ||
private final Long maxSq; | ||
|
||
private static MinMaxLongs create(StringReader reader, @Nullable Long min, @Nullable Long max) throws CommandSyntaxException { | ||
if (min != null && max != null && min > max) { | ||
throw ERROR_SWAPPED.createWithContext(reader); | ||
} else { | ||
return new MinMaxLongs(min, max); | ||
} | ||
} | ||
|
||
@Nullable | ||
private static Long squareOpt(@Nullable Long l) { | ||
return l == null ? null : l * l; | ||
} | ||
|
||
private MinMaxLongs(@Nullable Long min, @Nullable Long max) { | ||
super(min, max); | ||
this.minSq = squareOpt(min); | ||
this.maxSq = squareOpt(max); | ||
} | ||
|
||
public static MinMaxLongs exactly(long l) { | ||
return new MinMaxLongs(l, l); | ||
} | ||
|
||
public static MinMaxLongs between(long min, long max) { | ||
return new MinMaxLongs(min, max); | ||
} | ||
|
||
public static MinMaxLongs atLeast(long min) { | ||
return new MinMaxLongs(min, null); | ||
} | ||
|
||
public static MinMaxLongs atMost(long max) { | ||
return new MinMaxLongs(null, max); | ||
} | ||
|
||
public boolean matches(long l) { | ||
if (this.min != null && this.min > l) { | ||
return false; | ||
} else { | ||
return this.max == null || this.max >= l; | ||
} | ||
} | ||
|
||
public boolean matchesSqr(long l) { | ||
if (this.minSq != null && this.minSq > l) { | ||
return false; | ||
} else { | ||
return this.maxSq == null || this.maxSq >= l; | ||
} | ||
} | ||
|
||
public static MinMaxLongs fromJson(@Nullable JsonElement json) { | ||
return fromJson(json, ANY, GsonHelper::convertToLong, MinMaxLongs::new); | ||
} | ||
|
||
public static MinMaxLongs fromReader(StringReader reader) throws CommandSyntaxException { | ||
return fromReader(reader, (l) -> l); | ||
} | ||
|
||
public static MinMaxLongs fromReader(StringReader reader, Function<Long, Long> map) throws CommandSyntaxException { | ||
BuiltInExceptionProvider builtInExceptions = CommandSyntaxException.BUILT_IN_EXCEPTIONS; | ||
Objects.requireNonNull(builtInExceptions); | ||
return fromReader(reader, MinMaxLongs::create, Long::parseLong, builtInExceptions::readerInvalidInt, map); | ||
} | ||
} |
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
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
Oops, something went wrong.