diff --git a/src/main/java/nourl/mythicmetals/MythicMetals.java b/src/main/java/nourl/mythicmetals/MythicMetals.java index 3cc351fe..7c748b72 100644 --- a/src/main/java/nourl/mythicmetals/MythicMetals.java +++ b/src/main/java/nourl/mythicmetals/MythicMetals.java @@ -7,6 +7,7 @@ import io.wispforest.owo.itemgroup.OwoItemGroup; import io.wispforest.owo.itemgroup.gui.ItemGroupButton; import io.wispforest.owo.registration.reflect.FieldRegistrationHandler; +import io.wispforest.owo.registration.reflect.SimpleFieldProcessingSubject; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; import net.fabricmc.fabric.api.registry.FuelRegistry; @@ -97,7 +98,7 @@ public void onInitialize() { RegisterLootConditions.init(); MythicStatusEffects.init(); RegisterRecipeSerializers.init(); - RegisterCriteria.init(); + FieldRegistrationHandler.processSimple(RegisterCriteria.class, false); BlockBreaker.initHammerTime(); MythicLootOps.init(); TradeOfferHelper.registerVillagerOffers(VillagerProfession.CLERIC, 5, factories -> { diff --git a/src/main/java/nourl/mythicmetals/item/tools/BanglumPick.java b/src/main/java/nourl/mythicmetals/item/tools/BanglumPick.java index 29f89955..0ec5dee5 100644 --- a/src/main/java/nourl/mythicmetals/item/tools/BanglumPick.java +++ b/src/main/java/nourl/mythicmetals/item/tools/BanglumPick.java @@ -54,7 +54,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { MythicParticleSystem.EXPLOSION_TRAIL.spawn(world, Vec3d.of(pos), Vec3d.of(pos2)); WorldOps.playSound(world, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS); - RegisterCriteria.BLAST_MINING.trigger((ServerPlayerEntity) player); + RegisterCriteria.USED_BLAST_MINING.trigger((ServerPlayerEntity) player); player.getItemCooldownManager().set(this, 100); return ActionResult.SUCCESS; } diff --git a/src/main/java/nourl/mythicmetals/item/tools/BanglumShovel.java b/src/main/java/nourl/mythicmetals/item/tools/BanglumShovel.java index 08f6e321..0b8f762d 100644 --- a/src/main/java/nourl/mythicmetals/item/tools/BanglumShovel.java +++ b/src/main/java/nourl/mythicmetals/item/tools/BanglumShovel.java @@ -52,7 +52,7 @@ public ActionResult useOnBlock(ItemUsageContext context) { MythicParticleSystem.EXPLOSION_TRAIL.spawn(world, Vec3d.of(pos), Vec3d.of(pos2)); WorldOps.playSound(world, pos, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.PLAYERS); - RegisterCriteria.BLAST_MINING.trigger((ServerPlayerEntity) player); + RegisterCriteria.USED_BLAST_MINING.trigger((ServerPlayerEntity) player); player.getItemCooldownManager().set(this, 100); return ActionResult.SUCCESS; } diff --git a/src/main/java/nourl/mythicmetals/item/tools/CarmotStaff.java b/src/main/java/nourl/mythicmetals/item/tools/CarmotStaff.java index 5311986c..67a46a60 100644 --- a/src/main/java/nourl/mythicmetals/item/tools/CarmotStaff.java +++ b/src/main/java/nourl/mythicmetals/item/tools/CarmotStaff.java @@ -363,7 +363,7 @@ public TypedActionResult use(World world, PlayerEntity user, Hand han user.getItemCooldownManager().set(stack.getItem(), 5000); stack.put(STORED_BLOCK, MythicBlocks.MIDAS_GOLD.getStorageBlock()); if (!world.isClient()) { - RegisterCriteria.ENCHANTED_MIDAS_IN_STAFF.trigger(((ServerPlayerEntity) user)); + RegisterCriteria.USE_ENCHANTED_MIDAS_IN_CARMOT_STAFF.trigger(((ServerPlayerEntity) user)); } return TypedActionResult.success(stack); } diff --git a/src/main/java/nourl/mythicmetals/misc/SimpleCriteria.java b/src/main/java/nourl/mythicmetals/misc/SimpleCriteria.java index fe49aec4..092a7b69 100644 --- a/src/main/java/nourl/mythicmetals/misc/SimpleCriteria.java +++ b/src/main/java/nourl/mythicmetals/misc/SimpleCriteria.java @@ -1,15 +1,15 @@ package nourl.mythicmetals.misc; import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.advancement.criterion.AbstractCriterion; -import net.minecraft.predicate.entity.LootContextPredicate; -import net.minecraft.predicate.entity.LootContextPredicateValidator; +import net.minecraft.predicate.entity.*; import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.dynamic.Codecs; import java.util.Optional; public class SimpleCriteria extends AbstractCriterion { - // FIXME - Broken at the moment public SimpleCriteria() { } @@ -19,21 +19,13 @@ public void trigger(ServerPlayerEntity entity) { @Override public Codec getConditionsCodec() { - return null; + return Conditions.CODEC; } - public static class Conditions implements AbstractCriterion.Conditions { - public Conditions() { - } + public record Conditions(Optional player) implements AbstractCriterion.Conditions { - @Override - public void validate(LootContextPredicateValidator validator) { - AbstractCriterion.Conditions.super.validate(validator); - } - - @Override - public Optional player() { - return Optional.empty(); - } + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player) + ).apply(instance, Conditions::new)); } } diff --git a/src/main/java/nourl/mythicmetals/mixin/LivingEntityMixin.java b/src/main/java/nourl/mythicmetals/mixin/LivingEntityMixin.java index 0b6ea117..653b2bfc 100644 --- a/src/main/java/nourl/mythicmetals/mixin/LivingEntityMixin.java +++ b/src/main/java/nourl/mythicmetals/mixin/LivingEntityMixin.java @@ -251,7 +251,7 @@ public LivingEntityMixin(EntityType type, World world) { if (!getWorld().isClient() && effect.getEffectType().equals(MythicStatusEffects.COMBUSTION) && this.isPlayer()) { if (source instanceof AreaEffectCloudEntity cloudEntity && ((WasSpawnedFromCreeper) cloudEntity).mythicmetals$isSpawnedFromCreeper()) { //noinspection ConstantConditions - RegisterCriteria.RECIEVED_COMBUSTION_FROM_CREEPER.trigger(((ServerPlayerEntity) (Object) this)); + RegisterCriteria.RECEIVED_COMBUSTION_FROM_CREEPER.trigger(((ServerPlayerEntity) (Object) this)); } } } diff --git a/src/main/java/nourl/mythicmetals/registry/RegisterCriteria.java b/src/main/java/nourl/mythicmetals/registry/RegisterCriteria.java index 7262d7f7..30bd0953 100644 --- a/src/main/java/nourl/mythicmetals/registry/RegisterCriteria.java +++ b/src/main/java/nourl/mythicmetals/registry/RegisterCriteria.java @@ -1,21 +1,26 @@ package nourl.mythicmetals.registry; +import io.wispforest.owo.registration.reflect.SimpleFieldProcessingSubject; import net.minecraft.advancement.criterion.Criteria; +import net.minecraft.advancement.criterion.Criterion; import net.minecraft.util.Identifier; +import nourl.mythicmetals.MythicMetals; import nourl.mythicmetals.misc.RegistryHelper; import nourl.mythicmetals.misc.SimpleCriteria; +import java.lang.reflect.Field; -public class RegisterCriteria { - public static final Identifier USED_BLAST_MINING_ID = RegistryHelper.id("used_blast_mining"); - public static final Identifier ENCHANTED_MIDAS_IN_STAFF_ID = RegistryHelper.id("use_enchanted_midas_in_carmot_staff"); - public static final Identifier RECIEVED_COMBUSTION_FROM_CREEPER_ID = RegistryHelper.id("recieved_combustion_from_creeper"); - public static final SimpleCriteria BLAST_MINING = new SimpleCriteria(); - public static final SimpleCriteria ENCHANTED_MIDAS_IN_STAFF = new SimpleCriteria(); - public static final SimpleCriteria RECIEVED_COMBUSTION_FROM_CREEPER = new SimpleCriteria(); +public class RegisterCriteria implements SimpleFieldProcessingSubject> { + public static final SimpleCriteria USED_BLAST_MINING = new SimpleCriteria(); + public static final SimpleCriteria USE_ENCHANTED_MIDAS_IN_CARMOT_STAFF = new SimpleCriteria(); + public static final SimpleCriteria RECEIVED_COMBUSTION_FROM_CREEPER = new SimpleCriteria(); - public static void init() { - Criteria.register(USED_BLAST_MINING_ID.getPath(), BLAST_MINING); - Criteria.register(ENCHANTED_MIDAS_IN_STAFF_ID.getPath(), ENCHANTED_MIDAS_IN_STAFF); - Criteria.register(RECIEVED_COMBUSTION_FROM_CREEPER_ID.getPath(), RECIEVED_COMBUSTION_FROM_CREEPER); + @Override + public void processField(Criterion value, String name, Field field) { + Criteria.register(MythicMetals.MOD_ID + ":" + name, value); + } + + @Override + public Class> getTargetFieldType() { + return ((Class>) (Object) Criterion.class); } } diff --git a/src/main/resources/data/mythicmetals/advancements/enchanted_midas_gold_block_in_staff.json b/src/main/resources/data/mythicmetals/advancements/enchanted_midas_gold_block_in_staff.json index add04211..dbbc6ee5 100644 --- a/src/main/resources/data/mythicmetals/advancements/enchanted_midas_gold_block_in_staff.json +++ b/src/main/resources/data/mythicmetals/advancements/enchanted_midas_gold_block_in_staff.json @@ -18,11 +18,15 @@ }, "criteria": { "kinda_expensive_luck_potion_truly_mmo_moment": { - "trigger": "mythicmetals:use_enchanted_midas_in_carmot_staff", - "conditions": {} + "trigger": "mythicmetals:use_enchanted_midas_in_carmot_staff" } }, + "requirements": [ + [ + "kinda_expensive_luck_potion_truly_mmo_moment" + ] + ], "rewards": { - "experience": 15 + "experience": 50 } } \ No newline at end of file diff --git a/src/main/resources/data/mythicmetals/advancements/intentional_combusting_mechanics.json b/src/main/resources/data/mythicmetals/advancements/intentional_combusting_mechanics.json index ecf9c27c..6b44d369 100644 --- a/src/main/resources/data/mythicmetals/advancements/intentional_combusting_mechanics.json +++ b/src/main/resources/data/mythicmetals/advancements/intentional_combusting_mechanics.json @@ -17,8 +17,12 @@ }, "criteria": { "get_too_close_to_the_aww_man": { - "trigger": "mythicmetals:recieved_combustion_from_creeper", - "conditions": {} + "trigger": "mythicmetals:received_combustion_from_creeper" } - } + }, + "requirements": [ + [ + "get_too_close_to_the_aww_man" + ] + ] } \ No newline at end of file diff --git a/src/main/resources/data/mythicmetals/advancements/legendary_banglum.json b/src/main/resources/data/mythicmetals/advancements/legendary_banglum.json index 98da8076..8c1ceec6 100644 --- a/src/main/resources/data/mythicmetals/advancements/legendary_banglum.json +++ b/src/main/resources/data/mythicmetals/advancements/legendary_banglum.json @@ -30,8 +30,7 @@ } }, "blast_mining_activated": { - "trigger": "mythicmetals:used_blast_mining", - "conditions": {} + "trigger": "mythicmetals:used_blast_mining" } }, "requirements": [