diff --git a/gradle.properties b/gradle.properties index fc320ce6..eb2b8296 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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 diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.java index efac0ab5..aecb4bb5 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/AllayVexTrigger.java @@ -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 { - static final ResourceLocation ID = new SkyAdditionsResourceLocation("allay_vex"); - - @Override - public ResourceLocation getId() { - return ID; - } - +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class AllayVexTrigger extends SimpleCriterionTrigger { 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 player, DeserializationContext context) { + Optional vexPredicate = EntityPredicate.fromJson(json, "vex", context); + Optional 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 vex; + private final Optional allay; - public Conditions(ContextAwarePredicate player, ContextAwarePredicate vex, ContextAwarePredicate allay) { - super(ID, player); + public TriggerInstance( + Optional player, + Optional vex, + Optional 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; } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.java index e4f411a5..2cf3705b 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/ConvertSpiderTrigger.java @@ -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 { - static final ResourceLocation ID = new SkyAdditionsResourceLocation("convert_spider"); - - @Override - public ResourceLocation getId() { - return ID; - } - +@SuppressWarnings("OptionalUsedAsFieldOrParameterType") +public class ConvertSpiderTrigger extends SimpleCriterionTrigger { 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 player, DeserializationContext context) { + Optional spiderPredicate = EntityPredicate.fromJson(json, "spider", context); + Optional 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 spider; + private final Optional caveSpider; - public Conditions( - ContextAwarePredicate player, ContextAwarePredicate spider, ContextAwarePredicate caveSpider) { - super(ID, player); + public TriggerInstance( + Optional player, + Optional spider, + Optional 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; } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.java index 1aaa2d05..a7d8f420 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsCriteriaTriggers.java @@ -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 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() {} } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsEntityPredicate.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsEntityPredicate.java index 735dd90b..4e178fe0 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsEntityPredicate.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsEntityPredicate.java @@ -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 location, Optional steppingOnLocation) { + public static final Codec 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; - } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsLocationPredicate.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsLocationPredicate.java index 04d19560..02eb0d90 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsLocationPredicate.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/criterion/SkyAdditionsLocationPredicate.java @@ -1,15 +1,15 @@ package com.jsorrell.carpetskyadditions.advancements.criterion; -import com.google.gson.JsonElement; -import com.google.gson.JsonNull; -import com.google.gson.JsonObject; import com.jsorrell.carpetskyadditions.helpers.CoralSpreader; import com.jsorrell.carpetskyadditions.helpers.SmallDripleafSpreader; import com.jsorrell.carpetskyadditions.util.SkyAdditionsResourceLocation; import com.jsorrell.carpetskyadditions.util.SkyAdditionsText; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import java.util.Arrays; import java.util.List; import java.util.Map; +import java.util.Optional; import net.minecraft.ChatFormatting; import net.minecraft.advancements.critereon.*; import net.minecraft.core.BlockPos; @@ -17,7 +17,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.BlockTags; -import net.minecraft.util.GsonHelper; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Rotation; @@ -27,25 +27,22 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; import net.minecraft.world.phys.AABB; -public class SkyAdditionsLocationPredicate { - public static final SkyAdditionsLocationPredicate ANY = - new SkyAdditionsLocationPredicate(null, null, MinMaxBounds.Doubles.ANY, null); - - private final MinMaxBounds.Doubles coralSuitability; - private final Boolean coralConvertible; - private final Boolean desertPyramidCheck; - private final Boolean smallDripleafCanSpread; - - public SkyAdditionsLocationPredicate( - Boolean desertPyramidCheck, - Boolean coralConvertible, - MinMaxBounds.Doubles coralSuitability, - Boolean smallDripleafCanSpread) { - this.desertPyramidCheck = desertPyramidCheck; - this.coralConvertible = coralConvertible; - this.coralSuitability = coralSuitability; - this.smallDripleafCanSpread = smallDripleafCanSpread; - } +public record SkyAdditionsLocationPredicate( + Optional desertPyramidCheck, + Optional coralConvertible, + Optional coralSuitability, + Optional smallDripleafCanSpread) { + public static final Codec CODEC = + RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.strictOptionalField(Codec.BOOL, "is_desert_pyramid_blue_terracotta") + .forGetter(SkyAdditionsLocationPredicate::desertPyramidCheck), + ExtraCodecs.strictOptionalField(Codec.BOOL, "coral_convertible") + .forGetter(SkyAdditionsLocationPredicate::coralConvertible), + ExtraCodecs.strictOptionalField(MinMaxBounds.Doubles.CODEC, "coral_suitability") + .forGetter(SkyAdditionsLocationPredicate::coralSuitability), + ExtraCodecs.strictOptionalField(Codec.BOOL, "small_dripleaf_spreadable") + .forGetter(SkyAdditionsLocationPredicate::smallDripleafCanSpread)) + .apply(instance, SkyAdditionsLocationPredicate::new)); private boolean doDesertPyramidCheck(ServerLevel level, BlockPos blueTerracottaPos, boolean sendDebugMessage) { StructureTemplate template = level.getServer() @@ -118,69 +115,31 @@ private boolean doDesertPyramidCheck(ServerLevel level, BlockPos blueTerracottaP public boolean matches(ServerLevel level, double x, double y, double z) { BlockPos blockPos = BlockPos.containing(x, y, z); - if (desertPyramidCheck != null) { - if (doDesertPyramidCheck(level, blockPos, desertPyramidCheck) != desertPyramidCheck) { + if (desertPyramidCheck.isPresent()) { + if (doDesertPyramidCheck(level, blockPos, desertPyramidCheck.get()) != desertPyramidCheck.get()) { return false; } } - if (coralConvertible != null) { - if (CoralSpreader.isConvertible(level, blockPos) != coralConvertible) { + if (coralConvertible.isPresent()) { + if (CoralSpreader.isConvertible(level, blockPos) != coralConvertible.get()) { return false; } } - if (!coralSuitability.matches(CoralSpreader.calculateCoralSuitability(level, blockPos))) { - return false; + if (coralSuitability.isPresent()) { + if (!coralSuitability.get().matches(CoralSpreader.calculateCoralSuitability(level, blockPos))) { + return false; + } } - if (smallDripleafCanSpread != null) { + if (smallDripleafCanSpread.isPresent()) { if (SmallDripleafSpreader.canSpreadFrom(level.getBlockState(blockPos), level, blockPos) - != smallDripleafCanSpread) { + != smallDripleafCanSpread.get()) { return false; } } return true; } - - public JsonElement serializeToJson() { - if (this == ANY) return JsonNull.INSTANCE; - - JsonObject jsonObject = new JsonObject(); - if (desertPyramidCheck != null) { - jsonObject.addProperty("is_desert_pyramid_blue_terracotta", desertPyramidCheck); - } - if (coralConvertible != null) { - jsonObject.addProperty("coral_convertible", desertPyramidCheck); - } - if (!coralSuitability.isAny()) { - jsonObject.add("coral_suitability", coralSuitability.serializeToJson()); - } - if (smallDripleafCanSpread != null) { - jsonObject.addProperty("small_dripleaf_spreadable", smallDripleafCanSpread); - } - return jsonObject; - } - - public static SkyAdditionsLocationPredicate fromJson(JsonElement json) { - if (json == null || json.isJsonNull()) return ANY; - - JsonObject jsonObject = GsonHelper.convertToJsonObject(json, "location"); - Boolean desertPyramidCheck = null; - if (jsonObject.has("is_desert_pyramid_blue_terracotta")) { - desertPyramidCheck = GsonHelper.getAsBoolean(jsonObject, "is_desert_pyramid_blue_terracotta"); - } - Boolean coralConvertible = null; - if (jsonObject.has("coral_convertible")) { - coralConvertible = GsonHelper.getAsBoolean(jsonObject, "coral_convertible"); - } - MinMaxBounds.Doubles coralSuitability = MinMaxBounds.Doubles.fromJson(jsonObject.get("coral_suitability")); - Boolean smallDripleafCanSpread = null; - if (jsonObject.has("small_dripleaf_spreadable")) { - smallDripleafCanSpread = GsonHelper.getAsBoolean(jsonObject, "small_dripleaf_spreadable"); - } - return new SkyAdditionsLocationPredicate( - desertPyramidCheck, coralConvertible, coralSuitability, smallDripleafCanSpread); - } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLocationCheck.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLocationCheck.java index e03decae..4a76abe1 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLocationCheck.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLocationCheck.java @@ -1,25 +1,31 @@ package com.jsorrell.carpetskyadditions.advancements.predicates; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; import com.jsorrell.carpetskyadditions.advancements.criterion.SkyAdditionsLocationPredicate; +import com.mojang.serialization.Codec; +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import java.util.Optional; import net.minecraft.core.BlockPos; -import net.minecraft.util.GsonHelper; +import net.minecraft.core.Vec3i; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; import net.minecraft.world.phys.Vec3; -public class SkyAdditionsLocationCheck implements LootItemCondition { - final SkyAdditionsLocationPredicate predicate; - final BlockPos offset; - - SkyAdditionsLocationCheck(SkyAdditionsLocationPredicate locationPredicate, BlockPos offset) { - this.predicate = locationPredicate; - this.offset = offset; - } +public record SkyAdditionsLocationCheck(Optional predicate, BlockPos offset) + implements LootItemCondition { + private static final MapCodec OFFSET_CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + ExtraCodecs.strictOptionalField(Codec.INT, "offsetX", 0).forGetter(Vec3i::getX), + ExtraCodecs.strictOptionalField(Codec.INT, "offsetY", 0).forGetter(Vec3i::getY), + ExtraCodecs.strictOptionalField(Codec.INT, "offsetZ", 0).forGetter(Vec3i::getZ)) + .apply(instance, BlockPos::new)); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.strictOptionalField(SkyAdditionsLocationPredicate.CODEC, "predicate") + .forGetter(SkyAdditionsLocationCheck::predicate), + OFFSET_CODEC.forGetter(SkyAdditionsLocationCheck::offset)) + .apply(instance, SkyAdditionsLocationCheck::new)); @Override public LootItemConditionType getType() { @@ -29,45 +35,13 @@ public LootItemConditionType getType() { public boolean test(LootContext lootContext) { Vec3 origin = lootContext.getParamOrNull(LootContextParams.ORIGIN); return origin != null - && predicate.matches( - lootContext.getLevel(), - origin.x() + offset.getX(), - origin.y() + offset.getY(), - origin.z() + offset.getZ()); - } - - public static Builder checkLocation(SkyAdditionsLocationPredicate locationPredicate) { - return () -> new SkyAdditionsLocationCheck(locationPredicate, BlockPos.ZERO); - } - - public static class Serializer - implements net.minecraft.world.level.storage.loot.Serializer { - public void serialize( - JsonObject jsonObject, - SkyAdditionsLocationCheck locationCheck, - JsonSerializationContext jsonSerializationContext) { - jsonObject.add("predicate", locationCheck.predicate.serializeToJson()); - if (locationCheck.offset.getX() != 0) { - jsonObject.addProperty("offsetX", locationCheck.offset.getX()); - } - - if (locationCheck.offset.getY() != 0) { - jsonObject.addProperty("offsetY", locationCheck.offset.getY()); - } - - if (locationCheck.offset.getZ() != 0) { - jsonObject.addProperty("offsetZ", locationCheck.offset.getZ()); - } - } - - public SkyAdditionsLocationCheck deserialize( - JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) { - SkyAdditionsLocationPredicate locationPredicate = - SkyAdditionsLocationPredicate.fromJson(jsonObject.get("predicate")); - int i = GsonHelper.getAsInt(jsonObject, "offsetX", 0); - int j = GsonHelper.getAsInt(jsonObject, "offsetY", 0); - int k = GsonHelper.getAsInt(jsonObject, "offsetZ", 0); - return new SkyAdditionsLocationCheck(locationPredicate, new BlockPos(i, j, k)); - } + && (predicate.isEmpty() + || predicate + .get() + .matches( + lootContext.getLevel(), + origin.x() + offset.getX(), + origin.y() + offset.getY(), + origin.z() + offset.getZ())); } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemConditions.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemConditions.java index 0e47137c..ceec6f2d 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemConditions.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemConditions.java @@ -1,24 +1,23 @@ package com.jsorrell.carpetskyadditions.advancements.predicates; import com.jsorrell.carpetskyadditions.util.SkyAdditionsResourceLocation; +import com.mojang.serialization.Codec; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.world.level.storage.loot.Serializer; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; public class SkyAdditionsLootItemConditions { public static final LootItemConditionType LOCATION_CHECK = - register("location_check", new SkyAdditionsLocationCheck.Serializer()); + register("location_check", SkyAdditionsLocationCheck.CODEC); public static final LootItemConditionType ENTITY_PROPERTIES = - register("entity_properties", new SkyAdditionsLootItemEntityPropertyCondition.Serializer()); + register("entity_properties", SkyAdditionsLootItemEntityPropertyCondition.CODEC); - private static LootItemConditionType register( - String registryName, Serializer serializer) { + private static LootItemConditionType register(String registryName, Codec codec) { return Registry.register( BuiltInRegistries.LOOT_CONDITION_TYPE, new SkyAdditionsResourceLocation(registryName), - new LootItemConditionType(serializer)); + new LootItemConditionType(codec)); } public static void bootstrap() {} diff --git a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemEntityPropertyCondition.java b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemEntityPropertyCondition.java index 009959d3..962f202c 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemEntityPropertyCondition.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/advancements/predicates/SkyAdditionsLootItemEntityPropertyCondition.java @@ -1,12 +1,12 @@ package com.jsorrell.carpetskyadditions.advancements.predicates; import com.google.common.collect.ImmutableSet; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; import com.jsorrell.carpetskyadditions.advancements.criterion.SkyAdditionsEntityPredicate; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import java.util.Optional; import java.util.Set; -import net.minecraft.util.GsonHelper; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.parameters.LootContextParam; @@ -15,15 +15,17 @@ import net.minecraft.world.level.storage.loot.predicates.LootItemConditionType; import net.minecraft.world.phys.Vec3; -public class SkyAdditionsLootItemEntityPropertyCondition implements LootItemCondition { - final SkyAdditionsEntityPredicate predicate; - final LootContext.EntityTarget entityTarget; - - SkyAdditionsLootItemEntityPropertyCondition( - SkyAdditionsEntityPredicate entityPredicate, LootContext.EntityTarget entityTarget) { - this.predicate = entityPredicate; - this.entityTarget = entityTarget; - } +public record SkyAdditionsLootItemEntityPropertyCondition( + Optional predicate, LootContext.EntityTarget entityTarget) + implements LootItemCondition { + public static final Codec CODEC = + RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.strictOptionalField(SkyAdditionsEntityPredicate.CODEC, "predicate") + .forGetter(SkyAdditionsLootItemEntityPropertyCondition::predicate), + LootContext.EntityTarget.CODEC + .fieldOf("entity") + .forGetter(SkyAdditionsLootItemEntityPropertyCondition::entityTarget)) + .apply(instance, SkyAdditionsLootItemEntityPropertyCondition::new)); @Override public LootItemConditionType getType() { @@ -38,31 +40,10 @@ public Set> getReferencedContextParams() { public boolean test(LootContext lootContext) { Entity entity = lootContext.getParamOrNull(entityTarget.getParam()); Vec3 origin = lootContext.getParamOrNull(LootContextParams.ORIGIN); - return predicate.matches(lootContext.getLevel(), origin, entity); + return predicate.isEmpty() || predicate.get().matches(lootContext.getLevel(), origin, entity); } public static Builder hasProperties(LootContext.EntityTarget target, SkyAdditionsEntityPredicate predicate) { - return () -> new SkyAdditionsLootItemEntityPropertyCondition(predicate, target); - } - - public static class Serializer - implements net.minecraft.world.level.storage.loot.Serializer { - public void serialize( - JsonObject jsonObject, - SkyAdditionsLootItemEntityPropertyCondition lootItemEntityPropertyCondition, - JsonSerializationContext jsonSerializationContext) { - jsonObject.add("predicate", lootItemEntityPropertyCondition.predicate.serializeToJson()); - jsonObject.add("entity", jsonSerializationContext.serialize(lootItemEntityPropertyCondition.entityTarget)); - } - - public SkyAdditionsLootItemEntityPropertyCondition deserialize( - JsonObject jsonObject, JsonDeserializationContext jsonDeserializationContext) { - SkyAdditionsEntityPredicate entityPredicate = - SkyAdditionsEntityPredicate.fromJson(jsonObject.get("predicate")); - return new SkyAdditionsLootItemEntityPropertyCondition( - entityPredicate, - GsonHelper.getAsObject( - jsonObject, "entity", jsonDeserializationContext, LootContext.EntityTarget.class)); - } + return () -> new SkyAdditionsLootItemEntityPropertyCondition(Optional.of(predicate), target); } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/helpers/WanderingTraderHelper.java b/src/main/java/com/jsorrell/carpetskyadditions/helpers/WanderingTraderHelper.java index df2f506f..455e38bd 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/helpers/WanderingTraderHelper.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/helpers/WanderingTraderHelper.java @@ -29,7 +29,7 @@ public static Int2ObjectMap getTrades() { if (SkyAdditionsSettings.lavaFromWanderingTrader) { tier2Trades.add( - new VillagerTrades.ItemsAndEmeraldsToItems(Items.BUCKET, 1, 16, Items.LAVA_BUCKET, 1, 1, 1)); + new VillagerTrades.ItemsAndEmeraldsToItems(Items.BUCKET, 1, 16, Items.LAVA_BUCKET, 1, 1, 1, 0.05f)); } return new Int2ObjectOpenHashMap<>(ImmutableMap.of( diff --git a/src/main/java/com/jsorrell/carpetskyadditions/mixin/CamelMixin.java b/src/main/java/com/jsorrell/carpetskyadditions/mixin/CamelMixin.java index 1a4f1845..216a7a2e 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/mixin/CamelMixin.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/mixin/CamelMixin.java @@ -9,26 +9,20 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EntityType; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.animal.camel.Camel; import net.minecraft.world.entity.animal.camel.CamelAi; import net.minecraft.world.entity.animal.horse.AbstractHorse; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.minecraft.world.phys.Vec3; +import org.joml.Vector3f; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.*; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Camel.class) public abstract class CamelMixin extends AbstractHorse implements CamelInterface { - @Shadow - public abstract LivingEntity getControllingPassenger(); - protected CamelMixin(EntityType entityType, Level level) { super(entityType, level); } @@ -98,27 +92,13 @@ private Dynamic getBlankBrainDynamic() { } // This only works with the mod on the client side - @Redirect(method = "positionRider", at = @At(value = "NEW", args = "class=net/minecraft/world/phys/Vec3")) - protected Vec3 moveTraderForward(double x, double y, double z) { - if (isTraderCamel()) { - return new Vec3(x, y, z + 0.09); - } - return new Vec3(x, y, z); - } - - // This only works with the mod on the client side - @Inject( - method = "positionRider", - at = - @At( - value = "INVOKE", - target = - "Lnet/minecraft/world/entity/animal/camel/Camel;clampRotation(Lnet/minecraft/world/entity/Entity;)V"), - cancellable = true) - protected void fixTraderRotation(Entity passenger, MoveFunction callback, CallbackInfo ci) { + @Redirect( + method = "getPassengerAttachmentPoint", + at = @At(value = "NEW", target = "(FFF)Lorg/joml/Vector3f;", remap = false)) + protected Vector3f moveTraderForward(float x, float y, float z) { if (isTraderCamel()) { - getControllingPassenger().yBodyRot = yBodyRot; - ci.cancel(); + return new Vector3f(x, y - 0.45f, z + 0.09f); } + return new Vector3f(x, y, z); } } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/mixin/CriteriaTriggersAccessor.java b/src/main/java/com/jsorrell/carpetskyadditions/mixin/CriteriaTriggersAccessor.java new file mode 100644 index 00000000..3081ba1e --- /dev/null +++ b/src/main/java/com/jsorrell/carpetskyadditions/mixin/CriteriaTriggersAccessor.java @@ -0,0 +1,16 @@ +package com.jsorrell.carpetskyadditions.mixin; + +import com.google.common.collect.BiMap; +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.advancements.CriterionTrigger; +import net.minecraft.resources.ResourceLocation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(CriteriaTriggers.class) +public interface CriteriaTriggersAccessor { + @Accessor("CRITERIA") + static BiMap> getCriteria() { + throw new AssertionError(); + } +} diff --git a/src/main/java/com/jsorrell/carpetskyadditions/mixin/DispensePotionBehaviorMixin.java b/src/main/java/com/jsorrell/carpetskyadditions/mixin/DispensePotionBehaviorMixin.java index e9b57287..549169ef 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/mixin/DispensePotionBehaviorMixin.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/mixin/DispensePotionBehaviorMixin.java @@ -3,8 +3,8 @@ import com.jsorrell.carpetskyadditions.helpers.DeepslateConversionHelper; import com.jsorrell.carpetskyadditions.settings.SkyAdditionsSettings; import net.minecraft.core.BlockPos; -import net.minecraft.core.BlockSource; import net.minecraft.core.Direction; +import net.minecraft.core.dispenser.BlockSource; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; @@ -22,9 +22,9 @@ private void addDeepslateConversionBehavior( BlockSource pointer, ItemStack stack, CallbackInfoReturnable cir) { if (SkyAdditionsSettings.doRenewableDeepslate) { if (PotionUtils.getPotion(stack) == DeepslateConversionHelper.CONVERSION_POTION) { - ServerLevel level = pointer.getLevel(); - BlockPos dispenserPos = pointer.getPos(); - Direction dispenserFacing = pointer.getBlockState().getValue(DispenserBlock.FACING); + ServerLevel level = pointer.level(); + BlockPos dispenserPos = pointer.pos(); + Direction dispenserFacing = pointer.state().getValue(DispenserBlock.FACING); BlockPos targetPos = dispenserPos.relative(dispenserFacing); if (DeepslateConversionHelper.convertDeepslateWithBottle(level, targetPos, dispenserPos)) { cir.setReturnValue(new ItemStack(Items.GLASS_BOTTLE)); diff --git a/src/main/java/com/jsorrell/carpetskyadditions/mixin/SaplingBlockMixin.java b/src/main/java/com/jsorrell/carpetskyadditions/mixin/SaplingBlockMixin.java index bd96dd41..72f213d6 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/mixin/SaplingBlockMixin.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/mixin/SaplingBlockMixin.java @@ -11,6 +11,7 @@ import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -23,11 +24,13 @@ public SaplingBlockMixin(BlockBehaviour.Properties settings) { super(settings); } + @Unique private boolean saplingIsOnSand(BlockGetter level, BlockPos pos) { BlockState underBlock = level.getBlockState(pos.below()); return underBlock.is(BlockTags.SAND); } + @Unique @SuppressWarnings("ConstantConditions") private boolean isPropagule() { return (BushBlock) this instanceof MangrovePropaguleBlock; @@ -52,7 +55,7 @@ private void killIfOnSand( @Inject(method = "isValidBonemealTarget", at = @At("HEAD"), cancellable = true) private void stopBonemealingOnSand( - LevelReader level, BlockPos pos, BlockState state, boolean isClient, CallbackInfoReturnable cir) { + LevelReader level, BlockPos pos, BlockState state, CallbackInfoReturnable cir) { if (SkyAdditionsSettings.saplingsDieOnSand && saplingIsOnSand(level, pos)) { cir.setReturnValue(false); } diff --git a/src/main/java/com/jsorrell/carpetskyadditions/mixin/WanderingTraderMixin.java b/src/main/java/com/jsorrell/carpetskyadditions/mixin/WanderingTraderMixin.java index cf5e51f6..bb46bab2 100644 --- a/src/main/java/com/jsorrell/carpetskyadditions/mixin/WanderingTraderMixin.java +++ b/src/main/java/com/jsorrell/carpetskyadditions/mixin/WanderingTraderMixin.java @@ -57,12 +57,6 @@ private Int2ObjectMap getTrades() { return WanderingTraderHelper.getTrades(); } - @Override - // This only works with the mod on the client side - public double getMyRidingOffset() { - return TraderCamelHelper.isMountedTrader(asTrader()) ? -0.45 : super.getMyRidingOffset(); - } - @Override public void remove(RemovalReason reason) { Camel traderCamel = TraderCamelHelper.getTraderCamel(asTrader()); diff --git a/src/main/resources/carpetskyadditions.mixins.json b/src/main/resources/carpetskyadditions.mixins.json index 42860849..e15ae7d5 100644 --- a/src/main/resources/carpetskyadditions.mixins.json +++ b/src/main/resources/carpetskyadditions.mixins.json @@ -7,9 +7,11 @@ "AreaEffectCloudMixin", "BaseCoralMixin", "BaseCoralWallFanBlockMixin", + "BlocksMixin", "CamelMixin", "ChunkGeneratorAccessor", - "BlocksMixin", + "CriteriaTriggersAccessor", + "DataFixersMixin", "DispensePotionBehaviorMixin", "DolphinMixin", "DrownedMixin", @@ -32,7 +34,6 @@ "RamTargetMixin", "RemoveBlockGoalMixin", "SaplingBlockMixin", - "DataFixersMixin", "SchemaV2551Mixin", "SchemaV2832Mixin", "ServerPropertiesHandlerMixin", diff --git a/src/main/resources/resourcepacks/skyblock/pack.mcmeta b/src/main/resources/resourcepacks/skyblock/pack.mcmeta index 560467cc..7b36ffed 100644 --- a/src/main/resources/resourcepacks/skyblock/pack.mcmeta +++ b/src/main/resources/resourcepacks/skyblock/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 15, + "pack_format": 18, "description": "Accompanying datapack to the Carpet Sky Additions mod" } } diff --git a/src/main/resources/resourcepacks/skyblock_acacia/pack.mcmeta b/src/main/resources/resourcepacks/skyblock_acacia/pack.mcmeta index 2855766a..d159efb8 100644 --- a/src/main/resources/resourcepacks/skyblock_acacia/pack.mcmeta +++ b/src/main/resources/resourcepacks/skyblock_acacia/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 15, + "pack_format": 18, "description": "Acacia start - Also enable SkyBlock datapack" } } diff --git a/translations-pack/pack.mcmeta b/translations-pack/pack.mcmeta index 1804e1ca..53e5e2cf 100644 --- a/translations-pack/pack.mcmeta +++ b/translations-pack/pack.mcmeta @@ -1,6 +1,6 @@ { "pack": { - "pack_format": 15, + "pack_format": 18, "description": "Translations for the accompanying datapack to the Carpet Sky Additions mod" } }