-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
random properties now also allow ranges with the format <high>-<low> …
…instead of only <low>-<high> *(OptiFine parity)*
- Loading branch information
Showing
5 changed files
with
64 additions
and
23 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
37 changes: 37 additions & 0 deletions
37
...ures/property_reading/properties/generic_properties/LongRangeFromStringArrayProperty.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,37 @@ | ||
package traben.entity_texture_features.features.property_reading.properties.generic_properties; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
public abstract class LongRangeFromStringArrayProperty extends NumberRangeFromStringArrayProperty<Long> { | ||
|
||
|
||
protected LongRangeFromStringArrayProperty(String string) throws RandomPropertyException { | ||
super(string); | ||
} | ||
|
||
|
||
@Override | ||
protected @Nullable RangeTester<Long> getRangeTesterFromString(String possibleRange) { | ||
try { | ||
if (possibleRange.matches("(\\d+|-\\d+)-(\\d+|-\\d+)")) { | ||
String[] str = possibleRange.split("(?<!^|-)-"); | ||
long left = Long.parseLong(str[0].replaceAll("[^0-9-]", "")); | ||
long right = Long.parseLong(str[1].replaceAll("[^0-9-]", "")); | ||
if(left == right){ | ||
return (value) -> value == left; | ||
} else if (right > left) { | ||
return (value) -> value >= left && value <= right; | ||
} else { | ||
return (value) -> value >= right && value <= left; | ||
} | ||
} else { | ||
long single = Long.parseLong(possibleRange.replaceAll("[^0-9-]", "")); | ||
return (value) -> value == single; | ||
} | ||
} catch (Exception ignored) { | ||
} | ||
return null; | ||
} | ||
|
||
|
||
} |
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