From f607c47bb4f97d2151f9bcc00083faf2ee97ffe9 Mon Sep 17 00:00:00 2001 From: Waterpicker Date: Fri, 8 Oct 2021 23:42:44 -0500 Subject: [PATCH] updated hole_in_the_sky advancement to have 8 range. --- .../dimdoors/datagen/AdvancementTab.java | 2 +- .../block/entity/RiftBlockEntity.java | 5 +++- .../criteria/RiftTrackedCriterion.java | 25 ++++++++++++++++--- .../dimdoors/hole_in_the_sky.json | 7 ++++-- 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/datagen/java/org/dimdev/dimdoors/datagen/AdvancementTab.java b/src/datagen/java/org/dimdev/dimdoors/datagen/AdvancementTab.java index 39ac3a19..620fa47e 100644 --- a/src/datagen/java/org/dimdev/dimdoors/datagen/AdvancementTab.java +++ b/src/datagen/java/org/dimdev/dimdoors/datagen/AdvancementTab.java @@ -70,7 +70,7 @@ public class AdvancementTab implements Consumer> { .build(advancementConsumer, "dimdoors:dimdoors/string_theory"); Advancement holeInTheSky = Advancement.Task.create() .display(makeDisplay(ModItems.RIFT_CONFIGURATION_TOOL, "hole_in_the_sky")) - .criterion("encounter_rift", new RiftTrackedCriterion.Conditions(EntityPredicate.Extended.EMPTY)) + .criterion("encounter_rift", new RiftTrackedCriterion.Conditions(EntityPredicate.Extended.EMPTY, NumberRange.FloatRange.atMost(8.0))) .parent(root) .build(advancementConsumer, "dimdoors:dimdoors/hole_in_the_sky"); Advancement darkOstiology = Advancement.Task.create() diff --git a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java index 392b5452..3a577903 100644 --- a/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java +++ b/src/main/java/org/dimdev/dimdoors/block/entity/RiftBlockEntity.java @@ -3,6 +3,7 @@ package org.dimdev.dimdoors.block.entity; import java.util.Objects; import net.minecraft.block.Block; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.math.EulerAngle; import net.minecraft.util.math.Vec3d; import org.apache.logging.log4j.LogManager; @@ -114,7 +115,9 @@ public abstract class RiftBlockEntity extends BlockEntity implements BlockEntity @Override public NbtCompound toInitialChunkDataNbt() { - PlayerLookup.tracking(this).forEach(ModCriteria.RIFT_TRACKED::trigger); + for (ServerPlayerEntity serverPlayerEntity : PlayerLookup.tracking(this)) { + ModCriteria.RIFT_TRACKED.trigger(serverPlayerEntity, this.getPos()); + } return super.toInitialChunkDataNbt(); } diff --git a/src/main/java/org/dimdev/dimdoors/criteria/RiftTrackedCriterion.java b/src/main/java/org/dimdev/dimdoors/criteria/RiftTrackedCriterion.java index a86cc128..12730253 100644 --- a/src/main/java/org/dimdev/dimdoors/criteria/RiftTrackedCriterion.java +++ b/src/main/java/org/dimdev/dimdoors/criteria/RiftTrackedCriterion.java @@ -4,21 +4,26 @@ import com.google.gson.JsonObject; import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterionConditions; +import net.minecraft.predicate.NumberRange; import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer; +import net.minecraft.predicate.entity.AdvancementEntityPredicateSerializer; import net.minecraft.predicate.entity.EntityPredicate; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; public class RiftTrackedCriterion extends AbstractCriterion { public static final Identifier ID = new Identifier("dimdoors", "rift_tracked"); @Override protected Conditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) { - return new Conditions(playerPredicate); + NumberRange.FloatRange distancePredicate = NumberRange.FloatRange.fromJson(obj.get("distance")); + return new Conditions(playerPredicate, distancePredicate); } - public void trigger(ServerPlayerEntity player) { - this.trigger(player, t -> true); + public void trigger(ServerPlayerEntity player, BlockPos riftPos) { + this.trigger(player, t -> t.matches(player, new Vec3d(riftPos.getX() + 0.5, riftPos.getY() + 0.5, riftPos.getZ() + 0.5))); } @Override @@ -27,8 +32,20 @@ public class RiftTrackedCriterion extends AbstractCriterion