-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
20 changed files
with
269 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# From https://github.com/jitpack/jitpack.io/issues/4506#issuecomment-864562270 | ||
before_install: | ||
- source "$HOME/.sdkman/bin/sdkman-init.sh" | ||
- sdk update | ||
- sdk install java 17.0.1-tem | ||
- sdk use java 17.0.1-tem |
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
39 changes: 26 additions & 13 deletions
39
src/main/java/fr/firstmegagame4/env/json/api/rule/CoordEnvJsonRule.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 |
---|---|---|
@@ -1,35 +1,48 @@ | ||
package fr.firstmegagame4.env.json.api.rule; | ||
|
||
import net.minecraft.util.StringIdentifiable; | ||
import fr.firstmegagame4.env.json.impl.rule.CoordEnvJsonRuleImpl; | ||
|
||
import java.util.function.BiFunction; | ||
|
||
public interface CoordEnvJsonRule extends EnvJsonRule { | ||
|
||
Coord coord(); | ||
|
||
Comparator comparator(); | ||
|
||
int value(); | ||
|
||
enum Coord { | ||
X, | ||
Y, | ||
Z | ||
} | ||
|
||
enum Comparator implements StringIdentifiable { | ||
INFERIOR("<"), | ||
INFERIOR_FLAT_EQUALS("<="), | ||
FLAT_EQUALS("=="), | ||
SUPERIOR_FLAT_EQUALS(">="), | ||
SUPERIOR(">"); | ||
enum Comparator { | ||
INFERIOR((provided, constant) -> provided < constant, "<"), | ||
INFERIOR_FLAT_EQUALS((provided, constant) -> provided <= constant, "<=", "=<"), | ||
FLAT_EQUALS(Integer::equals, "=="), | ||
SUPERIOR_FLAT_EQUALS((provided, constant) -> provided >= constant, ">=", "=>"), | ||
SUPERIOR((provided, constant) -> provided > constant, ">"); | ||
|
||
private final BiFunction<Integer, Integer, Boolean> operation; | ||
private final String[] representations; | ||
|
||
private final String representation; | ||
Comparator(BiFunction<Integer, Integer, Boolean> operation, String... representations) { | ||
this.operation = operation; | ||
this.representations = representations; | ||
} | ||
|
||
public static Comparator fromString(String string) { | ||
return CoordEnvJsonRuleImpl.comparatorFromString(string); | ||
} | ||
|
||
Comparator(String representation) { | ||
this.representation = representation; | ||
public BiFunction<Integer, Integer, Boolean> operation() { | ||
return this.operation; | ||
} | ||
|
||
@Override | ||
public String asString() { | ||
return this.representation; | ||
public String[] representations() { | ||
return this.representations; | ||
} | ||
} | ||
} |
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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/fr/firstmegagame4/env/json/impl/rule/CoordEnvJsonRuleImpl.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,61 @@ | ||
package fr.firstmegagame4.env.json.impl.rule; | ||
|
||
import fr.firstmegagame4.env.json.api.EnvJsonVisitor; | ||
import fr.firstmegagame4.env.json.api.rule.CoordEnvJsonRule; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.util.Arrays; | ||
|
||
@ApiStatus.Internal | ||
public class CoordEnvJsonRuleImpl extends EnvJsonRuleImpl implements CoordEnvJsonRule { | ||
|
||
private final Coord coord; | ||
private final Comparator comparator; | ||
private final int value; | ||
|
||
public CoordEnvJsonRuleImpl(Coord coord, Comparator comparator, int value) { | ||
super( | ||
switch (coord) { | ||
case X -> Type.X_COORD; | ||
case Y -> Type.Y_COORD; | ||
case Z -> Type.Z_COORD; | ||
} | ||
); | ||
this.coord = coord; | ||
this.comparator = comparator; | ||
this.value = value; | ||
} | ||
|
||
public static Comparator comparatorFromString(String string) { | ||
for (Comparator comparator : Comparator.values()) { | ||
if (Arrays.stream(comparator.representations()).toList().contains(string)) { | ||
return comparator; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public Coord coord() { | ||
return this.coord; | ||
} | ||
|
||
@Override | ||
public Comparator comparator() { | ||
return this.comparator; | ||
} | ||
|
||
@Override | ||
public int value() { | ||
return this.value; | ||
} | ||
|
||
@Override | ||
public boolean apply(EnvJsonVisitor visitor) { | ||
return switch (this.coord) { | ||
case X -> visitor.applyXCoord(i -> this.comparator.operation().apply(i, this.value)); | ||
case Y -> visitor.applyYCoord(i -> this.comparator.operation().apply(i, this.value)); | ||
case Z -> visitor.applyZCoord(i -> this.comparator.operation().apply(i, this.value)); | ||
}; | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
src/main/java/fr/firstmegagame4/env/json/impl/rule/EnvJsonRuleImpl.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
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.