updated hole_in_the_sky advancement to have 8 range.

This commit is contained in:
Waterpicker 2021-10-08 23:42:44 -05:00
parent d6534a694d
commit f607c47bb4
4 changed files with 31 additions and 8 deletions

View file

@ -70,7 +70,7 @@ public class AdvancementTab implements Consumer<Consumer<Advancement>> {
.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()

View file

@ -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();
}

View file

@ -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<RiftTrackedCriterion.Conditions> {
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<RiftTrackedCriterion
}
public static class Conditions extends AbstractCriterionConditions {
public Conditions(EntityPredicate.Extended playerPredicate) {
private NumberRange.FloatRange distance;
public Conditions(EntityPredicate.Extended playerPredicate, NumberRange.FloatRange distance) {
super(ID, playerPredicate);
this.distance = distance;
}
public boolean matches(ServerPlayerEntity player, Vec3d pos) {
return this.distance.testSqrt(player.getPos().squaredDistanceTo(pos));
}
public JsonObject toJson(AdvancementEntityPredicateSerializer predicateSerializer) {
JsonObject jsonObject = super.toJson(predicateSerializer);
jsonObject.add("distance", this.distance.toJson());
return jsonObject;
}
}
}

View file

@ -1,4 +1,3 @@
{
"parent": "dimdoors:dimdoors/root",
"display": {
"icon": {
@ -20,7 +19,11 @@
"criteria": {
"encounter_rift": {
"trigger": "dimdoors:rift_tracked",
"conditions": {}
"conditions": {
"distance": {
"max": 8.0
}
}
}
},
"requirements": [