-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This takes two predicates: + `launcher` is a location predicate with the position of the Faith Plate. + `force` is a distance predicate with the XYZ values specified in the Faith Plate GUI.
- Loading branch information
Showing
4 changed files
with
78 additions
and
2 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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/fusionflux/portalcubed/advancements/triggers/FlingTrigger.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,65 @@ | ||
package com.fusionflux.portalcubed.advancements.triggers; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.critereon.*; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import static com.fusionflux.portalcubed.PortalCubed.id; | ||
|
||
public class FlingTrigger extends SimpleCriterionTrigger<FlingTrigger.TriggerInstance> { | ||
public static final ResourceLocation ID = id("fling"); | ||
|
||
@NotNull | ||
@Override | ||
public ResourceLocation getId() { | ||
return ID; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected TriggerInstance createInstance(JsonObject json, ContextAwarePredicate predicate, DeserializationContext deserializationContext) { | ||
return new TriggerInstance( | ||
predicate, | ||
LocationPredicate.fromJson(json.get("launcher")), | ||
DistancePredicate.fromJson(json.get("force")) | ||
); | ||
} | ||
|
||
public void trigger(ServerPlayer player, BlockPos launcherPos, Vec3 launcherForce) { | ||
trigger(player, conditions -> conditions.matches(player.serverLevel(), launcherPos, launcherForce)); | ||
} | ||
|
||
public static class TriggerInstance extends AbstractCriterionTriggerInstance { | ||
private final LocationPredicate launcher; | ||
private final DistancePredicate force; | ||
|
||
public TriggerInstance(ContextAwarePredicate player, LocationPredicate launcher, DistancePredicate force) { | ||
super(ID, player); | ||
this.launcher = launcher; | ||
this.force = force; | ||
} | ||
|
||
public boolean matches(ServerLevel level, BlockPos launcherPos, Vec3 launcherForce) { | ||
return launcher.matches(level, launcherPos.getX() + 0.5, launcherPos.getY() + 0.5, launcherPos.getZ() + 0.5) && | ||
force.matches(0, 0, 0, launcherForce.x, launcherForce.y, launcherForce.z); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public JsonObject serializeToJson(SerializationContext context) { | ||
final JsonObject result = super.serializeToJson(context); | ||
if (launcher != LocationPredicate.ANY) { | ||
result.add("launcher", launcher.serializeToJson()); | ||
} | ||
if (force != DistancePredicate.ANY) { | ||
result.add("force", force.serializeToJson()); | ||
} | ||
return result; | ||
} | ||
} | ||
} |
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