-
Notifications
You must be signed in to change notification settings - Fork 91
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
19 changed files
with
203 additions
and
311 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
49 changes: 24 additions & 25 deletions
49
src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.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
49 changes: 23 additions & 26 deletions
49
...ain/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.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
21 changes: 16 additions & 5 deletions
21
.../com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package com.jsorrell.carpetskyadditions.advancements.criterion; | ||
|
||
import com.jsorrell.carpetskyadditions.mixin.CriteriaTriggersAccessor; | ||
import com.jsorrell.carpetskyadditions.util.SkyAdditionsResourceLocation; | ||
import net.minecraft.advancements.CriteriaTriggers; | ||
import net.minecraft.advancements.CriterionTrigger; | ||
import net.minecraft.advancements.critereon.PlayerTrigger; | ||
import net.minecraft.resources.ResourceLocation; | ||
|
||
public class SkyAdditionsCriteriaTriggers { | ||
public static final PlayerTrigger GENERATE_GEODE = | ||
CriteriaTriggers.register(new PlayerTrigger(new SkyAdditionsResourceLocation("generate_geode"))); | ||
public static final ConvertSpiderTrigger CONVERT_SPIDER = CriteriaTriggers.register(new ConvertSpiderTrigger()); | ||
public static final AllayVexTrigger ALLAY_VEX = CriteriaTriggers.register(new AllayVexTrigger()); | ||
public static final PlayerTrigger GENERATE_GEODE = register("generate_geode", new PlayerTrigger()); | ||
public static final ConvertSpiderTrigger CONVERT_SPIDER = register("convert_spider", new ConvertSpiderTrigger()); | ||
public static final AllayVexTrigger ALLAY_VEX = register("allay_vex", new AllayVexTrigger()); | ||
|
||
private static <T extends CriterionTrigger<?>> T register(String name, T trigger) { | ||
ResourceLocation resourceLocation = new SkyAdditionsResourceLocation(name); | ||
|
||
if (CriteriaTriggersAccessor.getCriteria().putIfAbsent(resourceLocation, trigger) != null) { | ||
throw new IllegalArgumentException("Duplicate criterion id " + resourceLocation); | ||
} else { | ||
return trigger; | ||
} | ||
} | ||
|
||
public static void bootstrap() {} | ||
} |
56 changes: 17 additions & 39 deletions
56
...a/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsEntityPredicate.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 |
---|---|---|
@@ -1,57 +1,35 @@ | ||
package com.jsorrell.carpetskyadditions.advancements.criterion; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonNull; | ||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import java.util.Optional; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.util.GsonHelper; | ||
import net.minecraft.util.ExtraCodecs; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.phys.Vec3; | ||
|
||
public class SkyAdditionsEntityPredicate { | ||
public static final SkyAdditionsEntityPredicate ANY = | ||
new SkyAdditionsEntityPredicate(SkyAdditionsLocationPredicate.ANY, SkyAdditionsLocationPredicate.ANY); | ||
private final SkyAdditionsLocationPredicate location; | ||
private final SkyAdditionsLocationPredicate steppingOnLocation; | ||
|
||
private SkyAdditionsEntityPredicate( | ||
SkyAdditionsLocationPredicate location, SkyAdditionsLocationPredicate steppingOnLocation) { | ||
this.location = location; | ||
this.steppingOnLocation = steppingOnLocation; | ||
} | ||
public record SkyAdditionsEntityPredicate( | ||
Optional<SkyAdditionsLocationPredicate> location, Optional<SkyAdditionsLocationPredicate> steppingOnLocation) { | ||
public static final Codec<SkyAdditionsEntityPredicate> CODEC = | ||
ExtraCodecs.recursive(codec -> RecordCodecBuilder.create(instance -> instance.group( | ||
ExtraCodecs.strictOptionalField(SkyAdditionsLocationPredicate.CODEC, "location") | ||
.forGetter(SkyAdditionsEntityPredicate::location), | ||
ExtraCodecs.strictOptionalField(SkyAdditionsLocationPredicate.CODEC, "stepping_on") | ||
.forGetter(SkyAdditionsEntityPredicate::steppingOnLocation)) | ||
.apply(instance, SkyAdditionsEntityPredicate::new))); | ||
|
||
public boolean matches(ServerLevel level, Vec3 position, Entity entity) { | ||
if (this == ANY) return true; | ||
if (entity == null) return false; | ||
|
||
if (!location.matches(level, entity.getX(), entity.getY(), entity.getZ())) return false; | ||
if (location.isPresent() && !location.get().matches(level, entity.getX(), entity.getY(), entity.getZ())) | ||
return false; | ||
|
||
if (steppingOnLocation != SkyAdditionsLocationPredicate.ANY) { | ||
if (steppingOnLocation.isPresent()) { | ||
Vec3 stepPos = Vec3.atCenterOf(entity.getOnPos()); | ||
if (!steppingOnLocation.matches(level, stepPos.x(), stepPos.y(), stepPos.z())) { | ||
if (!steppingOnLocation.get().matches(level, stepPos.x(), stepPos.y(), stepPos.z())) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static SkyAdditionsEntityPredicate fromJson(JsonElement json) { | ||
if (json == null || json.isJsonNull()) return ANY; | ||
|
||
JsonObject jsonObject = GsonHelper.convertToJsonObject(json, "entity"); | ||
SkyAdditionsLocationPredicate locationPredicate = | ||
SkyAdditionsLocationPredicate.fromJson(jsonObject.get("location")); | ||
SkyAdditionsLocationPredicate locationPredicate2 = | ||
SkyAdditionsLocationPredicate.fromJson(jsonObject.get("stepping_on")); | ||
return new SkyAdditionsEntityPredicate(locationPredicate, locationPredicate2); | ||
} | ||
|
||
public JsonElement serializeToJson() { | ||
if (this == ANY) return JsonNull.INSTANCE; | ||
|
||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.add("location", location.serializeToJson()); | ||
jsonObject.add("stepping_on", steppingOnLocation.serializeToJson()); | ||
return jsonObject; | ||
} | ||
} |
Oops, something went wrong.