Skip to content

Commit

Permalink
Update BookOpenTrigger codec
Browse files Browse the repository at this point in the history
  • Loading branch information
Minecraftschurli committed Jul 1, 2024
1 parent a0c689f commit 14fda7f
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.advancements.critereon.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.ExtraCodecs;

import vazkii.patchouli.api.PatchouliAPI;

Expand Down Expand Up @@ -39,10 +38,10 @@ public void trigger(@NotNull ServerPlayer player, @NotNull ResourceLocation book
public record TriggerInstance(Optional<ContextAwarePredicate> player, ResourceLocation book, Optional<ResourceLocation> entry, MinMaxBounds.Ints page) implements SimpleInstance {

public static Codec<BookOpenTrigger.TriggerInstance> CODEC = RecordCodecBuilder.create(instance -> instance.group(
ExtraCodecs.strictOptionalField(EntityPredicate.ADVANCEMENT_CODEC, "player").forGetter(TriggerInstance::player),
EntityPredicate.ADVANCEMENT_CODEC.optionalFieldOf("player").forGetter(TriggerInstance::player),
ResourceLocation.CODEC.fieldOf("book").forGetter(TriggerInstance::book),
ExtraCodecs.strictOptionalField(ResourceLocation.CODEC, "entry").forGetter(TriggerInstance::entry),
ExtraCodecs.strictOptionalField(MinMaxBounds.Ints.CODEC, "page", MinMaxBounds.Ints.ANY).forGetter(TriggerInstance::page)
ResourceLocation.CODEC.optionalFieldOf("entry").forGetter(TriggerInstance::entry),
MinMaxBounds.Ints.CODEC.optionalFieldOf("page", MinMaxBounds.Ints.ANY).forGetter(TriggerInstance::page)
).apply(instance, TriggerInstance::new));

public boolean matches(@NotNull ResourceLocation book, @Nullable ResourceLocation entry, int page) {
Expand Down

0 comments on commit 14fda7f

Please sign in to comment.