Skip to content

Commit

Permalink
Add starting_life and life int ranges to portalcubed:energy_pellet su…
Browse files Browse the repository at this point in the history
…b-predicate
  • Loading branch information
Gaming32 committed Jul 21, 2023
1 parent 3babbdf commit 205defd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@
import org.jetbrains.annotations.Nullable;

public class EnergyPelletPredicate implements EntitySubPredicate {
private final MinMaxBounds.Ints startingLife;
private final MinMaxBounds.Ints life;
private final MinMaxBounds.Ints bounces;
private final EntityPredicate thrower;

public EnergyPelletPredicate(MinMaxBounds.Ints bounces, EntityPredicate thrower) {
public EnergyPelletPredicate(MinMaxBounds.Ints startingLife, MinMaxBounds.Ints life, MinMaxBounds.Ints bounces, EntityPredicate thrower) {
this.startingLife = startingLife;
this.life = life;
this.bounces = bounces;
this.thrower = thrower;
}

public static EnergyPelletPredicate fromJson(JsonObject json) {
return new EnergyPelletPredicate(
MinMaxBounds.Ints.fromJson(json.get("starting_life")),
MinMaxBounds.Ints.fromJson(json.get("life")),
MinMaxBounds.Ints.fromJson(json.get("bounces")),
EntityPredicate.fromJson(json.get("thrower"))
);
Expand All @@ -32,6 +38,12 @@ public boolean matches(Entity entity, ServerLevel level, @Nullable Vec3 pos) {
if (!(entity instanceof EnergyPellet energyPellet)) {
return false;
}
if (!startingLife.matches(energyPellet.getStartingLife())) {
return false;
}
if (!life.matches(energyPellet.getLife())) {
return false;
}
if (!bounces.matches(energyPellet.getBounces())) {
return false;
}
Expand All @@ -46,6 +58,12 @@ public boolean matches(Entity entity, ServerLevel level, @Nullable Vec3 pos) {
@Override
public JsonObject serializeCustomData() {
final JsonObject result = new JsonObject();
if (!startingLife.isAny()) {
result.add("starting_life", bounces.serializeToJson());
}
if (!life.isAny()) {
result.add("life", bounces.serializeToJson());
}
if (!bounces.isAny()) {
result.add("bounces", bounces.serializeToJson());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,15 @@ protected void defineSynchedData() {

@Override
protected void readAdditionalSaveData(CompoundTag nbt) {
setStartingLife(nbt.getInt("StartingLife"));
setLife(nbt.getInt("Life"));
bounces = nbt.getInt("Bounces");
thrower = nbt.getUUID("Thrower");
}

@Override
protected void addAdditionalSaveData(CompoundTag nbt) {
nbt.putInt("StartingLife", getStartingLife());
nbt.putInt("Life", getLife());
nbt.putInt("Bounces", bounces);
nbt.putUUID("Thrower", thrower);
Expand Down

0 comments on commit 205defd

Please sign in to comment.