Skip to content

Commit

Permalink
Update for 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jsorrell committed Jul 25, 2024
1 parent d72a10f commit 151f940
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 311 deletions.
14 changes: 7 additions & 7 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ mod_version=4.4.2
java_version=17
# Fabric Properties
# see https://fabricmc.net/develop/
minecraft_version=1.20.1
compatible_minecraft_versions=>=1.20 <=1.20.1
minecraft_version=1.20.2
compatible_minecraft_versions=1.20.2
loader_version=0.15.11
# Fabric Api
fabric_version=0.92.2+1.20.1
fabric_version=0.91.6+1.20.2
# see https://maven.parchmentmc.org/org/parchmentmc/data
parchment_mappings=1.20.1:2023.09.03
parchment_mappings=1.20.2:2023.12.10
# see https://masa.dy.fi/maven/carpet/fabric-carpet/
carpet_core_version=1.20-1.4.112+v230608
carpet_core_version=1.20.2-1.4.119+v230928
# see https://linkie.shedaniel.me/dependencies
cloth_config_version=11.1.118
modmenu_version=7.2.2
cloth_config_version=12.0.119
modmenu_version=8.0.1
Original file line number Diff line number Diff line change
@@ -1,54 +1,53 @@
package com.jsorrell.carpetskyadditions.advancements.criterion;

import com.google.gson.JsonObject;
import com.jsorrell.carpetskyadditions.util.SkyAdditionsResourceLocation;
import java.util.Optional;
import net.minecraft.advancements.critereon.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.animal.allay.Allay;
import net.minecraft.world.entity.monster.Vex;
import net.minecraft.world.level.storage.loot.LootContext;

public class AllayVexTrigger extends SimpleCriterionTrigger<AllayVexTrigger.Conditions> {
static final ResourceLocation ID = new SkyAdditionsResourceLocation("allay_vex");

@Override
public ResourceLocation getId() {
return ID;
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class AllayVexTrigger extends SimpleCriterionTrigger<AllayVexTrigger.TriggerInstance> {
public void trigger(ServerPlayer player, Vex vex, Allay allay) {
LootContext vexLootContext = EntityPredicate.createContext(player, vex);
LootContext allayLootContext = EntityPredicate.createContext(player, allay);
trigger(player, conditions -> conditions.matches(vexLootContext, allayLootContext));
trigger(player, triggerInstance -> triggerInstance.matches(vexLootContext, allayLootContext));
}

@Override
public Conditions createInstance(JsonObject json, ContextAwarePredicate player, DeserializationContext context) {
ContextAwarePredicate vexPredicate = EntityPredicate.fromJson(json, "vex", context);
ContextAwarePredicate allayPredicate = EntityPredicate.fromJson(json, "allay", context);
return new Conditions(player, vexPredicate, allayPredicate);
public TriggerInstance createInstance(
JsonObject json, Optional<ContextAwarePredicate> player, DeserializationContext context) {
Optional<ContextAwarePredicate> vexPredicate = EntityPredicate.fromJson(json, "vex", context);
Optional<ContextAwarePredicate> allayPredicate = EntityPredicate.fromJson(json, "allay", context);
return new TriggerInstance(player, vexPredicate, allayPredicate);
}

public static class Conditions extends AbstractCriterionTriggerInstance {
private final ContextAwarePredicate vex;
private final ContextAwarePredicate allay;
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
private final Optional<ContextAwarePredicate> vex;
private final Optional<ContextAwarePredicate> allay;

public Conditions(ContextAwarePredicate player, ContextAwarePredicate vex, ContextAwarePredicate allay) {
super(ID, player);
public TriggerInstance(
Optional<ContextAwarePredicate> player,
Optional<ContextAwarePredicate> vex,
Optional<ContextAwarePredicate> allay) {
super(player);
this.vex = vex;
this.allay = allay;
}

public boolean matches(LootContext vexContext, LootContext allayContext) {
return vex.matches(vexContext) && allay.matches(allayContext);
return (vex.isEmpty() || vex.get().matches(vexContext))
&& (allay.isEmpty() || allay.get().matches(allayContext));
}

@Override
public JsonObject serializeToJson(SerializationContext context) {
JsonObject jsonObject = super.serializeToJson(context);
jsonObject.add("vex", vex.toJson(context));
jsonObject.add("allay", allay.toJson(context));
public JsonObject serializeToJson() {
JsonObject jsonObject = super.serializeToJson();

vex.ifPresent(v -> jsonObject.add("vex", v.toJson()));
allay.ifPresent(a -> jsonObject.add("allay", a.toJson()));
return jsonObject;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,55 +1,52 @@
package com.jsorrell.carpetskyadditions.advancements.criterion;

import com.google.gson.JsonObject;
import com.jsorrell.carpetskyadditions.util.SkyAdditionsResourceLocation;
import java.util.Optional;
import net.minecraft.advancements.critereon.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.monster.CaveSpider;
import net.minecraft.world.entity.monster.Spider;
import net.minecraft.world.level.storage.loot.LootContext;

public class ConvertSpiderTrigger extends SimpleCriterionTrigger<ConvertSpiderTrigger.Conditions> {
static final ResourceLocation ID = new SkyAdditionsResourceLocation("convert_spider");

@Override
public ResourceLocation getId() {
return ID;
}

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public class ConvertSpiderTrigger extends SimpleCriterionTrigger<ConvertSpiderTrigger.TriggerInstance> {
public void trigger(ServerPlayer player, Spider spider, CaveSpider caveSpider) {
LootContext spiderLootContext = EntityPredicate.createContext(player, spider);
LootContext caveSpiderLootContext = EntityPredicate.createContext(player, caveSpider);
trigger(player, conditions -> conditions.matches(spiderLootContext, caveSpiderLootContext));
trigger(player, triggerInstance -> triggerInstance.matches(spiderLootContext, caveSpiderLootContext));
}

@Override
public Conditions createInstance(JsonObject json, ContextAwarePredicate player, DeserializationContext context) {
ContextAwarePredicate spiderPredicate = EntityPredicate.fromJson(json, "spider", context);
ContextAwarePredicate caveSpiderPredicate = EntityPredicate.fromJson(json, "cave_spider", context);
return new Conditions(player, spiderPredicate, caveSpiderPredicate);
public TriggerInstance createInstance(
JsonObject json, Optional<ContextAwarePredicate> player, DeserializationContext context) {
Optional<ContextAwarePredicate> spiderPredicate = EntityPredicate.fromJson(json, "spider", context);
Optional<ContextAwarePredicate> caveSpiderPredicate = EntityPredicate.fromJson(json, "cave_spider", context);
return new TriggerInstance(player, spiderPredicate, caveSpiderPredicate);
}

public static class Conditions extends AbstractCriterionTriggerInstance {
private final ContextAwarePredicate spider;
private final ContextAwarePredicate caveSpider;
public static class TriggerInstance extends AbstractCriterionTriggerInstance {
private final Optional<ContextAwarePredicate> spider;
private final Optional<ContextAwarePredicate> caveSpider;

public Conditions(
ContextAwarePredicate player, ContextAwarePredicate spider, ContextAwarePredicate caveSpider) {
super(ID, player);
public TriggerInstance(
Optional<ContextAwarePredicate> player,
Optional<ContextAwarePredicate> spider,
Optional<ContextAwarePredicate> caveSpider) {
super(player);
this.spider = spider;
this.caveSpider = caveSpider;
}

public boolean matches(LootContext spiderContext, LootContext caveSpiderContext) {
return spider.matches(spiderContext) && caveSpider.matches(caveSpiderContext);
return (spider.isEmpty() || spider.get().matches(spiderContext))
&& (caveSpider.isEmpty() || caveSpider.get().matches(caveSpiderContext));
}

@Override
public JsonObject serializeToJson(SerializationContext context) {
JsonObject jsonObject = super.serializeToJson(context);
jsonObject.add("spider", spider.toJson(context));
jsonObject.add("cave_spider", caveSpider.toJson(context));
public JsonObject serializeToJson() {
JsonObject jsonObject = super.serializeToJson();
spider.ifPresent(s -> jsonObject.add("spider", s.toJson()));
caveSpider.ifPresent(cs -> jsonObject.add("cave_spider", cs.toJson()));
return jsonObject;
}
}
Expand Down
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() {}
}
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;
}
}
Loading

0 comments on commit 151f940

Please sign in to comment.