-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
41 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
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
15 changes: 13 additions & 2 deletions
15
src/main/java/eu/pb4/predicate/api/MinecraftPredicate.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
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
40 changes: 40 additions & 0 deletions
40
src/main/java/eu/pb4/predicate/impl/predicates/generic/SimplePredicate.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,40 @@ | ||
package eu.pb4.predicate.impl.predicates.generic; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import eu.pb4.predicate.api.AbstractPredicate; | ||
import eu.pb4.predicate.api.MinecraftPredicate; | ||
import eu.pb4.predicate.api.PredicateContext; | ||
import eu.pb4.predicate.api.PredicateResult; | ||
import net.minecraft.util.Identifier; | ||
import org.apache.commons.lang3.mutable.MutableObject; | ||
|
||
import java.util.function.Function; | ||
import java.util.function.Predicate; | ||
|
||
public final class SimplePredicate extends AbstractPredicate { | ||
public static final MinecraftPredicate HAS_PLAYER = new SimplePredicate(new Identifier("has_player"), PredicateContext::hasPlayer); | ||
public static final MinecraftPredicate HAS_ENTITY = new SimplePredicate(new Identifier("has_entity"), PredicateContext::hasEntity); | ||
public static final MinecraftPredicate HAS_WORLD = new SimplePredicate(new Identifier("has_world"), PredicateContext::hasWorld); | ||
public static final MinecraftPredicate HAS_GAME_PROFILE = new SimplePredicate(new Identifier("has_game_profile"), PredicateContext::hasGameProfile); | ||
|
||
private final Function<PredicateContext, PredicateResult<?>> function; | ||
|
||
public SimplePredicate(Identifier identifier, Predicate<PredicateContext> function) { | ||
this(identifier, (x) -> PredicateResult.ofBoolean(function.test(x)), new MutableObject<>()); | ||
} | ||
|
||
public SimplePredicate(Identifier identifier, Function<PredicateContext, PredicateResult<?>> function) { | ||
this(identifier, function, new MutableObject<>()); | ||
} | ||
|
||
private SimplePredicate(Identifier identifier, Function<PredicateContext, PredicateResult<?>> function, MutableObject<SimplePredicate> self) { | ||
super(identifier, MapCodec.unit(self::getValue)); | ||
this.function = function; | ||
} | ||
|
||
@Override | ||
public PredicateResult<?> test(PredicateContext context) { | ||
return function.apply(context); | ||
} | ||
|
||
} |
Oops, something went wrong.