-
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.
- Loading branch information
Showing
16 changed files
with
250 additions
and
20 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fusionflux/portalcubed/advancements/PortalCubedAdvancements.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,13 @@ | ||
package com.fusionflux.portalcubed.advancements; | ||
|
||
import com.fusionflux.portalcubed.advancements.conditions.PortalCubedConditions; | ||
import com.fusionflux.portalcubed.advancements.predicates.PortalCubedPredicates; | ||
import com.fusionflux.portalcubed.advancements.triggers.PortalCubedTriggers; | ||
|
||
public class PortalCubedAdvancements { | ||
public static void register() { | ||
PortalCubedConditions.register(); | ||
PortalCubedPredicates.register(); | ||
PortalCubedTriggers.register(); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...rtalcubed/predicates/FunnelCondition.java → ...ancements/conditions/FunnelCondition.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
2 changes: 1 addition & 1 deletion
2
...bed/predicates/PortalCubedConditions.java → ...nts/conditions/PortalCubedConditions.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
63 changes: 63 additions & 0 deletions
63
src/main/java/com/fusionflux/portalcubed/advancements/predicates/EnergyPelletPredicate.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,63 @@ | ||
package com.fusionflux.portalcubed.advancements.predicates; | ||
|
||
import com.fusionflux.portalcubed.entity.EnergyPellet; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.critereon.EntityPredicate; | ||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
import net.minecraft.advancements.critereon.MinMaxBounds; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class EnergyPelletPredicate implements EntitySubPredicate { | ||
private final MinMaxBounds.Ints bounces; | ||
private final EntityPredicate thrower; | ||
|
||
public EnergyPelletPredicate(MinMaxBounds.Ints bounces, EntityPredicate thrower) { | ||
this.bounces = bounces; | ||
this.thrower = thrower; | ||
} | ||
|
||
public static EnergyPelletPredicate fromJson(JsonObject json) { | ||
return new EnergyPelletPredicate( | ||
MinMaxBounds.Ints.fromJson(json.get("bounces")), | ||
EntityPredicate.fromJson(json.get("thrower")) | ||
); | ||
} | ||
|
||
@Override | ||
public boolean matches(Entity entity, ServerLevel level, @Nullable Vec3 pos) { | ||
if (!(entity instanceof EnergyPellet energyPellet)) { | ||
return false; | ||
} | ||
if (!bounces.matches(energyPellet.getBounces())) { | ||
return false; | ||
} | ||
//noinspection RedundantIfStatement | ||
if (!thrower.matches(level, pos, energyPellet.getThrower())) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public JsonObject serializeCustomData() { | ||
final JsonObject result = new JsonObject(); | ||
if (!bounces.isAny()) { | ||
result.add("bounces", bounces.serializeToJson()); | ||
} | ||
if (thrower != EntityPredicate.ANY) { | ||
result.add("thrower", thrower.serializeToJson()); | ||
} | ||
return result; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Type type() { | ||
return PortalCubedPredicates.ENERGY_PELLET; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/fusionflux/portalcubed/advancements/predicates/PortalCubedPredicates.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,11 @@ | ||
package com.fusionflux.portalcubed.advancements.predicates; | ||
|
||
import net.minecraft.advancements.critereon.EntitySubPredicate; | ||
|
||
public class PortalCubedPredicates { | ||
public static final EntitySubPredicate.Type ENERGY_PELLET = EnergyPelletPredicate::fromJson; | ||
|
||
public static void register() { | ||
EntitySubPredicate.Types.TYPES.put("portalcubed:energy_pellet", ENERGY_PELLET); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/com/fusionflux/portalcubed/advancements/triggers/BounceTrigger.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,54 @@ | ||
package com.fusionflux.portalcubed.advancements.triggers; | ||
|
||
import com.fusionflux.portalcubed.entity.EnergyPellet; | ||
import com.google.gson.JsonObject; | ||
import net.minecraft.advancements.critereon.*; | ||
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 org.jetbrains.annotations.Nullable; | ||
|
||
import static com.fusionflux.portalcubed.PortalCubed.id; | ||
|
||
public class BounceTrigger extends SimpleCriterionTrigger<BounceTrigger.TriggerInstance> { | ||
public static final ResourceLocation ID = id("bounce"); | ||
|
||
@NotNull | ||
@Override | ||
public ResourceLocation getId() { | ||
return ID; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
protected TriggerInstance createInstance(JsonObject json, ContextAwarePredicate predicate, DeserializationContext deserializationContext) { | ||
return new TriggerInstance(predicate, EntityPredicate.fromJson(json.get("pellet"))); | ||
} | ||
|
||
public void trigger(ServerPlayer player, EnergyPellet pellet) { | ||
trigger(player, conditions -> conditions.matches(player.serverLevel(), player.position(), pellet)); | ||
} | ||
|
||
public static class TriggerInstance extends AbstractCriterionTriggerInstance { | ||
private final EntityPredicate pellet; | ||
|
||
public TriggerInstance(ContextAwarePredicate player, EntityPredicate pellet) { | ||
super(ID, player); | ||
this.pellet = pellet; | ||
} | ||
|
||
public boolean matches(ServerLevel level, @Nullable Vec3 position, EnergyPellet pellet) { | ||
return this.pellet.matches(level, position, pellet); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public JsonObject serializeToJson(SerializationContext context) { | ||
final JsonObject result = super.serializeToJson(context); | ||
result.add("pellet", pellet.serializeToJson()); | ||
return result; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/fusionflux/portalcubed/advancements/triggers/PortalCubedTriggers.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,11 @@ | ||
package com.fusionflux.portalcubed.advancements.triggers; | ||
|
||
import net.minecraft.advancements.CriteriaTriggers; | ||
|
||
public class PortalCubedTriggers { | ||
public static final BounceTrigger BOUNCE = new BounceTrigger(); | ||
|
||
public static void register() { | ||
CriteriaTriggers.register(BOUNCE); | ||
} | ||
} |
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
6 changes: 3 additions & 3 deletions
6
src/main/java/com/fusionflux/portalcubed/client/render/entity/EnergyPelletRenderer.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
Oops, something went wrong.