From 5656d9f26fdcb44a7644b9bd036bdbf42b72d841 Mon Sep 17 00:00:00 2001 From: Anselm Brehme Date: Fri, 24 Nov 2023 23:22:20 +0100 Subject: [PATCH] fix triggers triggers are now in registry --- .../criterion/SpongeDummyTrigger.java | 5 +- .../criterion/SpongeScoreTrigger.java | 5 +- .../loader/VanillaRegistryLoader.java | 13 ----- .../advancements/CriteriaTriggersMixin.java | 47 +++++++++++++++++++ src/mixins/resources/mixins.sponge.core.json | 3 +- 5 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 src/mixins/java/org/spongepowered/common/mixin/core/advancements/CriteriaTriggersMixin.java diff --git a/src/main/java/org/spongepowered/common/advancement/criterion/SpongeDummyTrigger.java b/src/main/java/org/spongepowered/common/advancement/criterion/SpongeDummyTrigger.java index e947fc9d784..e0b3c99b2c0 100644 --- a/src/main/java/org/spongepowered/common/advancement/criterion/SpongeDummyTrigger.java +++ b/src/main/java/org/spongepowered/common/advancement/criterion/SpongeDummyTrigger.java @@ -29,14 +29,15 @@ import net.minecraft.advancements.critereon.ContextAwarePredicate; import net.minecraft.advancements.critereon.EntityPredicate; import net.minecraft.advancements.critereon.SimpleCriterionTrigger; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.ExtraCodecs; -import org.spongepowered.common.accessor.advancements.CriteriaTriggersAccessor; import java.util.Optional; public final class SpongeDummyTrigger extends SimpleCriterionTrigger { - public static final SpongeDummyTrigger DUMMY_TRIGGER = CriteriaTriggersAccessor.invoker$register("sponge:dummy", new SpongeDummyTrigger()); + public static final SpongeDummyTrigger DUMMY_TRIGGER = Registry.register(BuiltInRegistries.TRIGGER_TYPES, "sponge:dummy", new SpongeDummyTrigger()); private SpongeDummyTrigger() { } diff --git a/src/main/java/org/spongepowered/common/advancement/criterion/SpongeScoreTrigger.java b/src/main/java/org/spongepowered/common/advancement/criterion/SpongeScoreTrigger.java index 30236c13f2f..8a79c34bc8b 100644 --- a/src/main/java/org/spongepowered/common/advancement/criterion/SpongeScoreTrigger.java +++ b/src/main/java/org/spongepowered/common/advancement/criterion/SpongeScoreTrigger.java @@ -29,14 +29,15 @@ import net.minecraft.advancements.critereon.ContextAwarePredicate; import net.minecraft.advancements.critereon.EntityPredicate; import net.minecraft.advancements.critereon.SimpleCriterionTrigger; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.util.ExtraCodecs; -import org.spongepowered.common.accessor.advancements.CriteriaTriggersAccessor; import java.util.Optional; public final class SpongeScoreTrigger extends SimpleCriterionTrigger { - public static final SpongeScoreTrigger SCORE_TRIGGER = CriteriaTriggersAccessor.invoker$register("sponge:score", new SpongeScoreTrigger()); + public static final SpongeScoreTrigger SCORE_TRIGGER = Registry.register(BuiltInRegistries.TRIGGER_TYPES, "sponge:score", new SpongeScoreTrigger()); private SpongeScoreTrigger() { diff --git a/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java b/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java index 8acfb7a7cfb..88556bb16b5 100644 --- a/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java +++ b/src/main/java/org/spongepowered/common/registry/loader/VanillaRegistryLoader.java @@ -26,8 +26,6 @@ import com.google.common.base.CaseFormat; import net.minecraft.advancements.AdvancementType; -import net.minecraft.advancements.CriteriaTriggers; -import net.minecraft.advancements.CriterionTrigger; import net.minecraft.core.FrontAndTop; import net.minecraft.core.MappedRegistry; import net.minecraft.resources.ResourceLocation; @@ -93,7 +91,6 @@ import net.minecraft.world.scores.criteria.ObjectiveCriteria; import net.minecraft.world.ticks.TickPriority; import org.spongepowered.api.ResourceKey; -import org.spongepowered.api.advancement.criteria.trigger.Trigger; import org.spongepowered.api.item.FireworkShape; import org.spongepowered.api.item.FireworkShapes; import org.spongepowered.api.registry.Registry; @@ -101,13 +98,10 @@ import org.spongepowered.api.registry.RegistryTypes; import org.spongepowered.api.scoreboard.criteria.Criteria; import org.spongepowered.api.scoreboard.criteria.Criterion; -import org.spongepowered.common.accessor.advancements.CriteriaTriggersAccessor; import org.spongepowered.common.accessor.world.entity.animal.MushroomCow_MushroomTypeAccessor; import org.spongepowered.common.accessor.world.entity.boss.enderdragon.phases.EnderDragonPhaseAccessor; import org.spongepowered.common.accessor.world.item.ArmorMaterialsAccessor; import org.spongepowered.common.accessor.world.level.GameRulesAccessor; -import org.spongepowered.common.advancement.criterion.SpongeDummyTrigger; -import org.spongepowered.common.advancement.criterion.SpongeScoreTrigger; import org.spongepowered.common.registry.RegistryLoader; import org.spongepowered.common.registry.SpongeRegistryHolder; @@ -147,8 +141,6 @@ private void loadInstanceRegistries() { map.put(EnderDragonPhase.HOVERING, "hover"); }, phase -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, ((EnderDragonPhaseAccessor) phase).accessor$name())); this.holder.createRegistry(RegistryTypes.FIREWORK_SHAPE, VanillaRegistryLoader.fireworkShape()); - this.holder.createRegistry(RegistryTypes.TRIGGER, VanillaRegistryLoader.trigger(), true, - (k, trigger) -> CriteriaTriggersAccessor.invoker$register(k.location().toString(), (CriterionTrigger) trigger)); this.knownName(RegistryTypes.GAME_RULE, GameRulesAccessor.accessor$GAME_RULE_TYPES().keySet(), rule -> CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, rule.getId())); } @@ -272,11 +264,6 @@ private static RegistryLoader fireworkShape() { }); } - private static RegistryLoader> trigger() { - final var loadMe1 = SpongeDummyTrigger.DUMMY_TRIGGER; // register sponge trigger - final var loadMe2 = SpongeScoreTrigger.SCORE_TRIGGER; // register sponge trigger - return RegistryLoader.of(l -> CriteriaTriggers.all().forEach(trigger -> l.add(((ResourceKey) (Object) CriteriaTriggers.getId(trigger)), (Trigger) trigger))); - } // The following methods are named for clarity above. diff --git a/src/mixins/java/org/spongepowered/common/mixin/core/advancements/CriteriaTriggersMixin.java b/src/mixins/java/org/spongepowered/common/mixin/core/advancements/CriteriaTriggersMixin.java new file mode 100644 index 00000000000..044b4832a6e --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/core/advancements/CriteriaTriggersMixin.java @@ -0,0 +1,47 @@ +/* + * This file is part of Sponge, licensed under the MIT License (MIT). + * + * Copyright (c) SpongePowered + * Copyright (c) contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.spongepowered.common.mixin.core.advancements; + +import net.minecraft.advancements.CriteriaTriggers; +import net.minecraft.advancements.CriterionTrigger; +import net.minecraft.core.Registry; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.common.advancement.criterion.SpongeDummyTrigger; +import org.spongepowered.common.advancement.criterion.SpongeScoreTrigger; + + +@Mixin(CriteriaTriggers.class) +public abstract class CriteriaTriggersMixin { + + @Inject(method = "bootstrap", at = @At("HEAD")) + private static void onBootstrap(final Registry> $$0, final CallbackInfoReturnable> cir) + { + final var loadMe1 = SpongeDummyTrigger.DUMMY_TRIGGER; // register sponge trigger + final var loadMe2 = SpongeScoreTrigger.SCORE_TRIGGER; // register sponge trigger + } +} diff --git a/src/mixins/resources/mixins.sponge.core.json b/src/mixins/resources/mixins.sponge.core.json index 4525b2bf3aa..cf1c4235481 100644 --- a/src/mixins/resources/mixins.sponge.core.json +++ b/src/mixins/resources/mixins.sponge.core.json @@ -241,7 +241,8 @@ "world.scores.ScoreMixin", "world.ticks.LevelTicksMixin", "world.ticks.ScheduledTickMixin", - "world.item.crafting.SmithingTransformRecipeMixin" + "world.item.crafting.SmithingTransformRecipeMixin", + "advancements.CriteriaTriggersMixin" ], "client": [ "client.MinecraftMixin",