Skip to content

Commit

Permalink
Fix simple advancement criteria not working
Browse files Browse the repository at this point in the history
Signed-off-by: Noaaan <[email protected]>
  • Loading branch information
Noaaan committed Mar 12, 2024
1 parent 1e958b1 commit 3eb5c7b
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 40 deletions.
3 changes: 2 additions & 1 deletion src/main/java/nourl/mythicmetals/MythicMetals.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public TypedActionResult<ItemStack> 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);
}
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/nourl/mythicmetals/misc/SimpleCriteria.java
Original file line number Diff line number Diff line change
@@ -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<SimpleCriteria.Conditions> {

// FIXME - Broken at the moment
public SimpleCriteria() {
}

Expand All @@ -19,21 +19,13 @@ public void trigger(ServerPlayerEntity entity) {

@Override
public Codec<Conditions> getConditionsCodec() {
return null;
return Conditions.CODEC;
}

public static class Conditions implements AbstractCriterion.Conditions {
public Conditions() {
}
public record Conditions(Optional<LootContextPredicate> player) implements AbstractCriterion.Conditions {

@Override
public void validate(LootContextPredicateValidator validator) {
AbstractCriterion.Conditions.super.validate(validator);
}

@Override
public Optional<LootContextPredicate> player() {
return Optional.empty();
}
public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player)
).apply(instance, Conditions::new));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/main/java/nourl/mythicmetals/registry/RegisterCriteria.java
Original file line number Diff line number Diff line change
@@ -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<Criterion<?>> {
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<Criterion<?>> getTargetFieldType() {
return ((Class<Criterion<?>>) (Object) Criterion.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
}
},
"blast_mining_activated": {
"trigger": "mythicmetals:used_blast_mining",
"conditions": {}
"trigger": "mythicmetals:used_blast_mining"
}
},
"requirements": [
Expand Down

0 comments on commit 3eb5c7b

Please sign in to comment.