From fa3e0d53fc103fb3e1f6a2eb0052741437a3e316 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Fri, 28 Mar 2025 04:25:19 +0300 Subject: [PATCH 01/12] delete Keys.APPLICABLE_POTION_EFFECTS --- SpongeAPI | 2 +- .../common/data/provider/item/stack/ItemStackData.java | 1 - .../src/main/java/org/spongepowered/test/data/DataTest.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index cb1550649db..5b7dab89e89 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit cb1550649db77878cfc511dfa7c48ae76cf4c164 +Subproject commit 5b7dab89e89b5f6532c77afc76262fe574f6b3c6 diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index 31fa397b85f..173537c7340 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -102,7 +102,6 @@ public static void register(final DataProviderRegistrator registrator) { // TODO DataComponents.OMINOUS_BOTTLE_AMPLIFIER 1.21 // TODO rework applicable potion effects to consume effects - final var applicablePotionEffects = Keys.APPLICABLE_POTION_EFFECTS; ConsumeEffect newPotionEffects = new ApplyStatusEffectsConsumeEffect(List.of()); ConsumeEffect teleportRand = new TeleportRandomlyConsumeEffect(5); ConsumeEffect removeStatusEffects = new RemoveStatusEffectsConsumeEffect(HolderSet.empty()); diff --git a/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java index 8a2fa01995b..be7a3bb5f18 100644 --- a/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/data/DataTest.java @@ -239,7 +239,6 @@ public void testData(final ServerPlayer player) { PotionEffect.builder().potionType(PotionEffectTypes.RESISTANCE).amplifier(0).ambient(false).duration(Ticks.of(6000)).build(), PotionEffect.builder().potionType(PotionEffectTypes.FIRE_RESISTANCE).amplifier(0).ambient(false).duration(Ticks.of(6000)).build(), PotionEffect.builder().potionType(PotionEffectTypes.ABSORPTION).amplifier(3).ambient(false).duration(Ticks.of(2400)).build()); - this.checkGetWeightedData(goldenApple, Keys.APPLICABLE_POTION_EFFECTS, notchAppleEffects); this.checkOfferListData(goldenApple, Keys.APPLIED_ENCHANTMENTS, Arrays.asList(Enchantment.of(EnchantmentTypes.SHARPNESS, 5))); this.checkOfferListData(goldenApple, Keys.APPLIED_ENCHANTMENTS, Arrays.asList(Enchantment.of(EnchantmentTypes.PROTECTION, 4))); From 07a4dc70b38871890421f1e75d2f5bc4d7516696 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Fri, 28 Mar 2025 04:34:48 +0300 Subject: [PATCH 02/12] make PotionEffectType Taggable --- SpongeAPI | 2 +- .../world/effect/MobEffectMixin_API.java | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/SpongeAPI b/SpongeAPI index 5b7dab89e89..32a354bf270 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 5b7dab89e89b5f6532c77afc76262fe574f6b3c6 +Subproject commit 32a354bf270dbbae19d8eb69d79aef16e5b45474 diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java index 11c63c2219c..f28400cd18c 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java @@ -25,15 +25,25 @@ package org.spongepowered.common.mixin.api.minecraft.world.effect; import net.kyori.adventure.text.Component; +import net.minecraft.core.Holder; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.Registries; +import net.minecraft.tags.TagKey; import net.minecraft.world.effect.MobEffect; import org.spongepowered.api.effect.potion.PotionEffectType; +import org.spongepowered.api.registry.DefaultedRegistryType; +import org.spongepowered.api.registry.RegistryTypes; +import org.spongepowered.api.tag.Tag; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface.Remap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.adventure.SpongeAdventure; +import java.util.Collection; + @Mixin(MobEffect.class) @Implements(@Interface(iface = PotionEffectType.class, prefix = "potionEffectType$", remap = Remap.NONE)) public abstract class MobEffectMixin_API implements PotionEffectType { @@ -51,4 +61,21 @@ public abstract class MobEffectMixin_API implements PotionEffectType { public Component asComponent() { return SpongeAdventure.asAdventure(this.shadow$getDisplayName()); } + + @Override + public DefaultedRegistryType registryType() { + return RegistryTypes.POTION_EFFECT_TYPE; + } + + @Override + public Collection> tags() { + return this.registryType().get().tags().filter(this::is).toList(); + } + + @Override + public boolean is(final Tag tag) { + final Registry registry = SpongeCommon.vanillaRegistry(Registries.MOB_EFFECT); + final Holder.Reference holder = registry.createIntrusiveHolder((MobEffect) (Object) this); + return holder.is(((TagKey) (Object) tag)); + } } From 4beaf1dd78191596898d85beb23acb88abe0e6ba Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Fri, 28 Mar 2025 16:01:37 +0300 Subject: [PATCH 03/12] Implement ConsumeEffects --- SpongeAPI | 2 +- .../generator/item/ItemRegistries.java | 7 ++ .../provider/item/stack/ItemStackData.java | 24 ++-- .../item/SpongeConsumeEffectFactory.java | 93 ++++++++++++++ .../registry/SpongeFactoryProvider.java | 3 + ...lyStatusEffectsConsumeEffectMixin_API.java | 56 +++++++++ ...llStatusEffectsConsumeEffectMixin_API.java | 33 +++++ .../ConsumeEffectMixin_API.java | 59 +++++++++ .../ConsumeEffect_TypeMixin_API.java | 33 +++++ .../PlaySoundConsumeEffectMixin_API.java | 45 +++++++ ...veStatusEffectsConsumeEffectMixin_API.java | 49 ++++++++ ...eleportRandomlyConsumeEffectMixin_API.java | 42 +++++++ src/mixins/resources/mixins.sponge.api.json | 7 ++ .../test/data/ConsumableDataTest.java | 117 ++++++++++++++++++ .../META-INF/sponge_plugins.json | 6 + 15 files changed, 560 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java create mode 100644 src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java create mode 100644 testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java diff --git a/SpongeAPI b/SpongeAPI index 32a354bf270..c0b74b5a4ae 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 32a354bf270dbbae19d8eb69d79aef16e5b45474 +Subproject commit c0b74b5a4aee6bdc5a535dc9c75b4fa5189e929a diff --git a/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java b/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java index 63366a3e4c3..2213ba49c23 100644 --- a/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java +++ b/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java @@ -111,6 +111,13 @@ public static List itemRegistries(final Context context) { $ -> true, RegistryScope.SERVER ), + new RegistryEntriesGenerator<>( + "data.type", + "ConsumeEffectTypes", + "CONSUME_EFFECT_TYPE", + context.relativeClass("data.type", "ConsumeEffectType"), + Registries.CONSUME_EFFECT_TYPE + ), new EnumEntriesValidator<>( "entity.display", "ItemDisplayTypes", diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index 173537c7340..14b165058ac 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -25,12 +25,11 @@ package org.spongepowered.common.data.provider.item.stack; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; -import net.minecraft.core.Holder; -import net.minecraft.core.HolderSet; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvents; import net.minecraft.tags.DamageTypeTags; import net.minecraft.util.StringUtil; import net.minecraft.util.Unit; @@ -49,12 +48,7 @@ import net.minecraft.world.item.component.Unbreakable; import net.minecraft.world.item.component.UseCooldown; import net.minecraft.world.item.component.UseRemainder; -import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect; -import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; import net.minecraft.world.item.consume_effects.ConsumeEffect; -import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; -import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; -import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; import org.checkerframework.checker.nullness.qual.Nullable; import org.spongepowered.api.Platform; import org.spongepowered.api.ResourceKey; @@ -79,7 +73,7 @@ public final class ItemStackData { public static final FoodProperties DEFAULT_FOOD_PROPERTIES = new FoodProperties(0, 0, false); - public static final Consumable DEFAULT_CONSUMABLE_PROPERTIES = new Consumable(1.6F, ItemUseAnimation.EAT, null, true, List.of()); + public static final Consumable DEFAULT_CONSUMABLE_PROPERTIES = new Consumable(1.6F, ItemUseAnimation.EAT, SoundEvents.GENERIC_EAT, true, List.of()); private ItemStackData() { } @@ -101,13 +95,6 @@ public static void register(final DataProviderRegistrator registrator) { // TODO DataComponents.RECIPES - for Items.KNOWLEDGE_BOOK // TODO DataComponents.OMINOUS_BOTTLE_AMPLIFIER 1.21 - // TODO rework applicable potion effects to consume effects - ConsumeEffect newPotionEffects = new ApplyStatusEffectsConsumeEffect(List.of()); - ConsumeEffect teleportRand = new TeleportRandomlyConsumeEffect(5); - ConsumeEffect removeStatusEffects = new RemoveStatusEffectsConsumeEffect(HolderSet.empty()); - ConsumeEffect clearStatusEffects = new ClearAllStatusEffectsConsumeEffect(); - ConsumeEffect playSoundEffect = new PlaySoundConsumeEffect(Holder.direct(null)); - registrator .asMutable(ItemStack.class) .create(Keys.BURN_TIME) @@ -248,6 +235,13 @@ public static void register(final DataProviderRegistrator registrator) { }) .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, c -> new Consumable(v.ticks() / 20f, c.animation(), c.sound(), c.hasConsumeParticles(), c.onConsumeEffects()))) + .create(Keys.CONSUME_EFFECTS) + .get(h -> { + final var consumable = h.get(DataComponents.CONSUMABLE); + return consumable == null ? null : (List) (Object) consumable.onConsumeEffects(); + }) + .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, + c -> new Consumable(c.consumeSeconds(), c.animation(), c.sound(), c.hasConsumeParticles(), (List) (Object) v))) .create(Keys.FOOD_CONVERTS_TO) .get(h -> { final var remainder = h.get(DataComponents.USE_REMAINDER); diff --git a/src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java b/src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java new file mode 100644 index 00000000000..af69a323a45 --- /dev/null +++ b/src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java @@ -0,0 +1,93 @@ +/* + * 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.item; + +import net.minecraft.core.HolderSet; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.tags.TagKey; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect; +import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; +import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; +import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; +import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.effect.potion.PotionEffect; +import org.spongepowered.api.effect.potion.PotionEffectType; +import org.spongepowered.api.effect.sound.SoundType; +import org.spongepowered.api.tag.Tag; + +import java.util.List; +import java.util.Objects; +import java.util.Set; + +public class SpongeConsumeEffectFactory implements ConsumeEffect.Factory { + + @Override + public ConsumeEffect.ApplyEffects applyEffects(final double chance, final List effects) { + Objects.requireNonNull(effects, "effects"); + if (chance < 0 || chance > 1) { + throw new IllegalArgumentException("chance must be in range [0; 1]: " + chance); + } + return (ConsumeEffect.ApplyEffects) (Object) new ApplyStatusEffectsConsumeEffect((List) List.copyOf(effects), (float) chance); + } + + @Override + public ConsumeEffect.RemoveEffects removeEffects(final Set effectTypes) { + Objects.requireNonNull(effectTypes, "effectTypes"); + final var holderSet = HolderSet.direct( + effectType -> BuiltInRegistries.MOB_EFFECT.wrapAsHolder((MobEffect) effectType), + effectTypes); + return (ConsumeEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + } + + @Override + public ConsumeEffect.RemoveEffects removeEffects(final Tag effectTypeTag) { + Objects.requireNonNull(effectTypeTag, "effectTypeTag"); + final var tag = (TagKey) (Object) effectTypeTag; + final var holderSet = BuiltInRegistries.MOB_EFFECT.get(tag).map(hs -> (HolderSet) hs).orElse(HolderSet.empty()); + return (ConsumeEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + } + + @Override + public ConsumeEffect.ClearEffects clearEffects() { + return (ConsumeEffect.ClearEffects) (Object) ClearAllStatusEffectsConsumeEffect.INSTANCE; + } + + @Override + public ConsumeEffect.PlaySound playSound(final SoundType soundType) { + Objects.requireNonNull(soundType, "soundType"); + return (ConsumeEffect.PlaySound) (Object) new PlaySoundConsumeEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder((SoundEvent) (Object) soundType)); + } + + @Override + public ConsumeEffect.TeleportRandomly teleportRandomly(final double distance) { + if (distance <= 0) { + throw new IllegalArgumentException("distance must be positive: " + distance); + } + return (ConsumeEffect.TeleportRandomly) (Object) new TeleportRandomlyConsumeEffect((float) distance * 2); + } +} diff --git a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java index 8891c2041ad..7022b56db36 100644 --- a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java +++ b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java @@ -41,6 +41,7 @@ import org.spongepowered.api.command.registrar.tree.CommandTreeNode; import org.spongepowered.api.command.selector.Selector; import org.spongepowered.api.data.DataManipulator; +import org.spongepowered.api.data.type.ConsumeEffect; import org.spongepowered.api.data.type.ToolRule; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.effect.ForwardingViewer; @@ -124,6 +125,7 @@ import org.spongepowered.common.entity.effect.SpongeVanishState; import org.spongepowered.common.event.SpongeEventListenerRegistration; import org.spongepowered.common.event.tracking.BlockChangeFlagManager; +import org.spongepowered.common.item.SpongeConsumeEffectFactory; import org.spongepowered.common.item.SpongeItemStack; import org.spongepowered.common.item.SpongeItemStackSnapshot; import org.spongepowered.common.item.SpongeToolRuleFactory; @@ -282,6 +284,7 @@ public void registerDefaultFactories() { .registerFactory(NaturalSpawner.Factory.class, new SpongeNaturalSpawnerFactory()) .registerFactory(ScoreFormat.Factory.class, new SpongeScoreFormatFactory()) .registerFactory(ToolRule.Factory.class, new SpongeToolRuleFactory()) + .registerFactory(ConsumeEffect.Factory.class, new SpongeConsumeEffectFactory()) .registerFactory(PortalLogic.Factory.class, new SpongePortalLogicFactory()) .registerFactory(RecipeInput.Factory.class, new SpongeRecipeInputFactory()) .registerFactory(ArmorTrim.Factory.class, new SpongeArmorTrimFactory()) diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java new file mode 100644 index 00000000000..1a39f5b02e1 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java @@ -0,0 +1,56 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.world.effect.MobEffectInstance; +import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.effect.potion.PotionEffect; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Implements; +import org.spongepowered.asm.mixin.Interface; +import org.spongepowered.asm.mixin.Intrinsic; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.List; + +@Mixin(ApplyStatusEffectsConsumeEffect.class) +@Implements(@Interface(iface = ConsumeEffect.ApplyEffects.class, prefix = "consumeEffect$")) +public abstract class ApplyStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.ApplyEffects { + + @Shadow @Final private float probability; + @Shadow @Final private List effects; + + @Override + public double chance() { + return this.probability; + } + + @Intrinsic + public List consumeEffect$effects() { + return (List) this.effects; + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java new file mode 100644 index 00000000000..14928f4aa98 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java @@ -0,0 +1,33 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ClearAllStatusEffectsConsumeEffect.class) +public abstract class ClearAllStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.ClearEffects { +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java new file mode 100644 index 00000000000..18c1ade4cd6 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -0,0 +1,59 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.consume_effects.ConsumeEffect; +import net.minecraft.world.level.Level; +import org.spongepowered.api.data.type.ConsumeEffectType; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.item.inventory.ItemStackLike; +import org.spongepowered.api.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.common.item.util.ItemStackUtil; + +import java.util.Objects; + +@Mixin(ConsumeEffect.class) +public interface ConsumeEffectMixin_API extends org.spongepowered.api.data.type.ConsumeEffect { + + @Shadow ConsumeEffect.Type shadow$getType(); + @Shadow boolean shadow$apply(Level level, ItemStack itemStack, LivingEntity livingEntity); + + @Override + default ConsumeEffectType type() { + return (ConsumeEffectType) (Object) this.shadow$getType(); + } + + @Override + default boolean apply(final World world, final Living entity, final ItemStackLike stack) { + return this.shadow$apply( + (Level) Objects.requireNonNull(world, "world"), + ItemStackUtil.fromLikeToNative(stack).copy(), + (LivingEntity) Objects.requireNonNull(entity, "entity")); + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java new file mode 100644 index 00000000000..033281fd115 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java @@ -0,0 +1,33 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.world.item.consume_effects.ConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffectType; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(ConsumeEffect.Type.class) +public abstract class ConsumeEffect_TypeMixin_API implements ConsumeEffectType { +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java new file mode 100644 index 00000000000..b2321ecd3b4 --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java @@ -0,0 +1,45 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.core.Holder; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.effect.sound.SoundType; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(PlaySoundConsumeEffect.class) +public abstract class PlaySoundConsumeEffectMixin_API implements ConsumeEffect.PlaySound { + + @Shadow @Final private Holder sound; + + @Override + public SoundType soundType() { + return (SoundType) (Object) this.sound.value(); + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java new file mode 100644 index 00000000000..ee5f14f37ef --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java @@ -0,0 +1,49 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.core.Holder; +import net.minecraft.core.HolderSet; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.effect.potion.PotionEffectType; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Set; +import java.util.stream.Collectors; + +@Mixin(RemoveStatusEffectsConsumeEffect.class) +public abstract class RemoveStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.RemoveEffects { + + @Shadow @Final private HolderSet effects; + + @Override + public Set effectTypes() { + return this.effects.stream().map(Holder::value).map(PotionEffectType.class::cast).collect(Collectors.toSet()); + } +} diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java new file mode 100644 index 00000000000..dbe1ad5fc0f --- /dev/null +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java @@ -0,0 +1,42 @@ +/* + * 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.api.minecraft.world.item.consume_effects; + +import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(TeleportRandomlyConsumeEffect.class) +public abstract class TeleportRandomlyConsumeEffectMixin_API implements ConsumeEffect.TeleportRandomly { + + @Shadow @Final private float diameter; + + @Override + public double distance() { + return this.diameter / 2; + } +} diff --git a/src/mixins/resources/mixins.sponge.api.json b/src/mixins/resources/mixins.sponge.api.json index 639210f4640..250ef63239a 100644 --- a/src/mixins/resources/mixins.sponge.api.json +++ b/src/mixins/resources/mixins.sponge.api.json @@ -332,6 +332,13 @@ "minecraft.world.item.alchemy.PotionMixin_API", "minecraft.world.item.component.FireworkExplosionMixin_API", "minecraft.world.item.component.Tool_RuleMixin_API", + "minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffectMixin_API", + "minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffectMixin_API", + "minecraft.world.item.consume_effects.ConsumeEffect_TypeMixin_API", + "minecraft.world.item.consume_effects.ConsumeEffectMixin_API", + "minecraft.world.item.consume_effects.PlaySoundConsumeEffectMixin_API", + "minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffectMixin_API", + "minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffectMixin_API", "minecraft.world.item.crafting.AbstractCookingRecipeMixin_API", "minecraft.world.item.crafting.CraftingRecipeMixin_API", "minecraft.world.item.crafting.CustomRecipeMixin_API", diff --git a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java new file mode 100644 index 00000000000..6066a0ed0f7 --- /dev/null +++ b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java @@ -0,0 +1,117 @@ +/* + * 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.test.data; + +import com.google.inject.Inject; +import net.kyori.adventure.text.Component; +import org.spongepowered.api.command.Command; +import org.spongepowered.api.command.CommandResult; +import org.spongepowered.api.command.parameter.CommandContext; +import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.effect.potion.PotionEffect; +import org.spongepowered.api.effect.potion.PotionEffectTypes; +import org.spongepowered.api.effect.sound.SoundTypes; +import org.spongepowered.api.entity.living.player.server.ServerPlayer; +import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.lifecycle.RegisterCommandEvent; +import org.spongepowered.api.item.ItemTypes; +import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.util.Ticks; +import org.spongepowered.plugin.PluginContainer; +import org.spongepowered.plugin.builtin.jvm.Plugin; +import org.spongepowered.test.LoadableModule; + +@Plugin("consumabledata") +public class ConsumableDataTest implements LoadableModule { + + private final PluginContainer plugin; + + @Inject + public ConsumableDataTest(final PluginContainer plugin) { + this.plugin = plugin; + } + + @Override + public void enable(final CommandContext ctx) { + } + + @Listener + public void onRegisterCommand(final RegisterCommandEvent event) { + final Command.Builder builder = Command.builder(); + builder.addChild(Command.builder().executor(this::items).build(), "items"); + builder.addChild(Command.builder().executor(this::applyTeleport).build(), "applyteleport"); + builder.addChild(Command.builder().executor(this::applySound).build(), "applysound"); + event.register(this.plugin, builder.build(), "consumabledata"); + } + + private CommandResult items(final CommandContext commandContext) { + final ServerPlayer player = commandContext.cause().first(ServerPlayer.class).orElse(null); + if (player == null) { + return CommandResult.error(Component.text("Must be run ingame by a player")); + } + + final ItemStack stack1 = ItemStack.of(ItemTypes.BRICKS); + stack1.offer(Keys.CUSTOM_NAME, Component.text("Remove slowness, get speed & regeneration")); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.playSound(SoundTypes.BLOCK_ANVIL_BREAK)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.teleportRandomly(5)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.removeEffects(PotionEffectTypes.SLOWNESS)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.applyEffects( + PotionEffect.of(PotionEffectTypes.SPEED, 1, Ticks.of(20 * 30)), + PotionEffect.of(PotionEffectTypes.REGENERATION, 0, Ticks.of(20 * 30)) + )); + + final ItemStack stack2 = ItemStack.of(ItemTypes.CHORUS_FRUIT); + stack2.offer(Keys.CUSTOM_NAME, Component.text("Remove all effects, get slowness & haste with 50% chance")); + stack2.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.clearEffects()); + stack2.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.applyEffects(0.5, + PotionEffect.of(PotionEffectTypes.SLOWNESS, 1, Ticks.of(20 * 10)), + PotionEffect.of(PotionEffectTypes.HASTE, 0, Ticks.of(20 * 10)) + )); + + player.inventory().offer(stack1, stack2); + return CommandResult.success(); + } + + private CommandResult applyTeleport(final CommandContext commandContext) { + final ServerPlayer player = commandContext.cause().first(ServerPlayer.class).orElse(null); + if (player == null) { + return CommandResult.error(Component.text("Must be run ingame by a player")); + } + + ConsumeEffect.teleportRandomly(20).apply(player); + return CommandResult.success(); + } + + private CommandResult applySound(final CommandContext commandContext) { + final ServerPlayer player = commandContext.cause().first(ServerPlayer.class).orElse(null); + if (player == null) { + return CommandResult.error(Component.text("Must be run ingame by a player")); + } + + ConsumeEffect.playSound(SoundTypes.BLOCK_BELL_USE).apply(player); + return CommandResult.success(); + } +} diff --git a/testplugins/src/main/resource-templates/META-INF/sponge_plugins.json b/testplugins/src/main/resource-templates/META-INF/sponge_plugins.json index 8af3eb43009..9390048f78c 100644 --- a/testplugins/src/main/resource-templates/META-INF/sponge_plugins.json +++ b/testplugins/src/main/resource-templates/META-INF/sponge_plugins.json @@ -377,6 +377,12 @@ "name": "Decorated Pot Data", "entrypoint": "org.spongepowered.test.data.PotDataTest", "description": "Decorated Pot Data" + }, + { + "id": "consumabledata", + "name": "Consumable ItemStack Data", + "entrypoint": "org.spongepowered.test.data.ConsumableDataTest", + "description": "Consumable ItemStack Data" } ] } From 27695a954429999a14c32de6c3f0308ed368aaed Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 00:27:49 +0300 Subject: [PATCH 04/12] Implement Keys.DEATH_PROTECTION_EFFECTS --- SpongeAPI | 2 +- .../common/data/provider/item/stack/ItemStackData.java | 8 ++++++++ .../spongepowered/test/data/ConsumableDataTest.java | 10 +++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index c0b74b5a4ae..a0ef5e602d3 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit c0b74b5a4aee6bdc5a535dc9c75b4fa5189e929a +Subproject commit a0ef5e602d39d72ff4bf5a292e5e07effb0c50e5 diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index 14b165058ac..b70778e378d 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -43,6 +43,7 @@ import net.minecraft.world.item.component.Consumable; import net.minecraft.world.item.component.CustomModelData; import net.minecraft.world.item.component.DamageResistant; +import net.minecraft.world.item.component.DeathProtection; import net.minecraft.world.item.component.ItemContainerContents; import net.minecraft.world.item.component.ItemLore; import net.minecraft.world.item.component.Unbreakable; @@ -242,6 +243,13 @@ public static void register(final DataProviderRegistrator registrator) { }) .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, c -> new Consumable(c.consumeSeconds(), c.animation(), c.sound(), c.hasConsumeParticles(), (List) (Object) v))) + .create(Keys.DEATH_PROTECTION_EFFECTS) + .get(h -> { + final var deathProtection = h.get(DataComponents.DEATH_PROTECTION); + return deathProtection == null ? null : (List) (Object) deathProtection.deathEffects(); + }) + .set((h, v) -> h.set(DataComponents.DEATH_PROTECTION, new DeathProtection((List) (Object) v))) + .delete(h -> h.remove(DataComponents.DEATH_PROTECTION)) .create(Keys.FOOD_CONVERTS_TO) .get(h -> { final var remainder = h.get(DataComponents.USE_REMAINDER); diff --git a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java index 6066a0ed0f7..9fe89533aa3 100644 --- a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java @@ -91,7 +91,15 @@ private CommandResult items(final CommandContext commandContext) { PotionEffect.of(PotionEffectTypes.HASTE, 0, Ticks.of(20 * 10)) )); - player.inventory().offer(stack1, stack2); + final ItemStack stack3 = ItemStack.of(ItemTypes.TOTEM_OF_UNDYING); + stack3.offer(Keys.CUSTOM_NAME, Component.text("No death protection")); + stack3.remove(Keys.DEATH_PROTECTION_EFFECTS); + + final ItemStack stack4 = ItemStack.of(ItemTypes.ANVIL); + stack4.offer(Keys.CUSTOM_NAME, Component.text("Teleport on death")); + stack4.offerSingle(Keys.DEATH_PROTECTION_EFFECTS, ConsumeEffect.teleportRandomly(20)); + + player.inventory().offer(stack1, stack2, stack3, stack4); return CommandResult.success(); } From a0f4baa1a3963a46a7bbc3638fee63f266b02b41 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 00:30:34 +0300 Subject: [PATCH 05/12] Update SpongeAPI --- SpongeAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpongeAPI b/SpongeAPI index a0ef5e602d3..323011f742b 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit a0ef5e602d39d72ff4bf5a292e5e07effb0c50e5 +Subproject commit 323011f742b2cb77fe695d9a6b7d6b8cefcc25f8 From 5156a9b856c6cedaa68a652050d0606877bdb3e1 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 00:51:44 +0300 Subject: [PATCH 06/12] add ItemStackUtil#fromLikeToNativeCopy --- .../org/spongepowered/common/item/util/ItemStackUtil.java | 4 ++++ .../world/item/consume_effects/ConsumeEffectMixin_API.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java b/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java index b9b30d606d2..e9d91aa1786 100644 --- a/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java +++ b/src/main/java/org/spongepowered/common/item/util/ItemStackUtil.java @@ -167,6 +167,10 @@ public static net.minecraft.world.item.ItemStack fromLikeToNative(@Nullable Item return itemStack == null ? ItemStackUtil.emptyNative() : itemStack.isEmpty() ? ItemStackUtil.emptyNative() : ItemStackUtil.toNative(itemStack.asMutable()); } + public static net.minecraft.world.item.ItemStack fromLikeToNativeCopy(@Nullable ItemStackLike itemStack) { + return itemStack == null ? ItemStackUtil.emptyNative() : itemStack.isEmpty() ? ItemStackUtil.emptyNative() : ItemStackUtil.toNative(itemStack.asMutableCopy()); + } + public static ItemStack empty() { return ItemStackUtil.fromNative(net.minecraft.world.item.ItemStack.EMPTY); } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java index 18c1ade4cd6..3f938b8f2c4 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -53,7 +53,7 @@ default ConsumeEffectType type() { default boolean apply(final World world, final Living entity, final ItemStackLike stack) { return this.shadow$apply( (Level) Objects.requireNonNull(world, "world"), - ItemStackUtil.fromLikeToNative(stack).copy(), + ItemStackUtil.fromLikeToNativeCopy(stack), (LivingEntity) Objects.requireNonNull(entity, "entity")); } } From fad13c7c413d013b33c467bf46073fe7b622b083 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 05:09:08 +0300 Subject: [PATCH 07/12] rename ConsumeEffect -> ItemActionEffect --- SpongeAPI | 2 +- .../provider/item/stack/ItemStackData.java | 5 ++-- ...ava => SpongeItemActionEffectFactory.java} | 28 +++++++++---------- .../registry/SpongeFactoryProvider.java | 6 ++-- ...lyStatusEffectsConsumeEffectMixin_API.java | 6 ++-- ...llStatusEffectsConsumeEffectMixin_API.java | 4 +-- .../ConsumeEffectMixin_API.java | 9 +++--- .../ConsumeEffect_TypeMixin_API.java | 4 +-- .../PlaySoundConsumeEffectMixin_API.java | 4 +-- ...veStatusEffectsConsumeEffectMixin_API.java | 4 +-- ...eleportRandomlyConsumeEffectMixin_API.java | 4 +-- .../test/data/ConsumableDataTest.java | 20 ++++++------- 12 files changed, 49 insertions(+), 47 deletions(-) rename src/main/java/org/spongepowered/common/item/{SpongeConsumeEffectFactory.java => SpongeItemActionEffectFactory.java} (69%) diff --git a/SpongeAPI b/SpongeAPI index 323011f742b..b4ec15e3eea 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 323011f742b2cb77fe695d9a6b7d6b8cefcc25f8 +Subproject commit b4ec15e3eeabf9fbd658211c6d464612c6078915 diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index ff871cabe77..7fa061e5625 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -55,6 +55,7 @@ import org.spongepowered.api.ResourceKey; import org.spongepowered.api.data.DataTransactionResult; import org.spongepowered.api.data.Keys; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.item.ItemRarity; import org.spongepowered.api.item.ItemType; @@ -245,14 +246,14 @@ public static void register(final DataProviderRegistrator registrator) { .create(Keys.CONSUME_EFFECTS) .get(h -> { final var consumable = h.get(DataComponents.CONSUMABLE); - return consumable == null ? null : (List) (Object) consumable.onConsumeEffects(); + return consumable == null ? null : (List) (Object) consumable.onConsumeEffects(); }) .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, c -> new Consumable(c.consumeSeconds(), c.animation(), c.sound(), c.hasConsumeParticles(), (List) (Object) v))) .create(Keys.DEATH_PROTECTION_EFFECTS) .get(h -> { final var deathProtection = h.get(DataComponents.DEATH_PROTECTION); - return deathProtection == null ? null : (List) (Object) deathProtection.deathEffects(); + return deathProtection == null ? null : (List) (Object) deathProtection.deathEffects(); }) .set((h, v) -> h.set(DataComponents.DEATH_PROTECTION, new DeathProtection((List) (Object) v))) .delete(h -> h.remove(DataComponents.DEATH_PROTECTION)) diff --git a/src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java b/src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java similarity index 69% rename from src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java rename to src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java index af69a323a45..39d707bdb3c 100644 --- a/src/main/java/org/spongepowered/common/item/SpongeConsumeEffectFactory.java +++ b/src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java @@ -34,7 +34,7 @@ import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.api.effect.potion.PotionEffectType; import org.spongepowered.api.effect.sound.SoundType; @@ -44,50 +44,50 @@ import java.util.Objects; import java.util.Set; -public class SpongeConsumeEffectFactory implements ConsumeEffect.Factory { +public class SpongeItemActionEffectFactory implements ItemActionEffect.Factory { @Override - public ConsumeEffect.ApplyEffects applyEffects(final double chance, final List effects) { + public ItemActionEffect.ApplyEffects applyEffects(final double chance, final List effects) { Objects.requireNonNull(effects, "effects"); if (chance < 0 || chance > 1) { throw new IllegalArgumentException("chance must be in range [0; 1]: " + chance); } - return (ConsumeEffect.ApplyEffects) (Object) new ApplyStatusEffectsConsumeEffect((List) List.copyOf(effects), (float) chance); + return (ItemActionEffect.ApplyEffects) (Object) new ApplyStatusEffectsConsumeEffect((List) List.copyOf(effects), (float) chance); } @Override - public ConsumeEffect.RemoveEffects removeEffects(final Set effectTypes) { + public ItemActionEffect.RemoveEffects removeEffects(final Set effectTypes) { Objects.requireNonNull(effectTypes, "effectTypes"); final var holderSet = HolderSet.direct( effectType -> BuiltInRegistries.MOB_EFFECT.wrapAsHolder((MobEffect) effectType), effectTypes); - return (ConsumeEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + return (ItemActionEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); } @Override - public ConsumeEffect.RemoveEffects removeEffects(final Tag effectTypeTag) { + public ItemActionEffect.RemoveEffects removeEffects(final Tag effectTypeTag) { Objects.requireNonNull(effectTypeTag, "effectTypeTag"); final var tag = (TagKey) (Object) effectTypeTag; final var holderSet = BuiltInRegistries.MOB_EFFECT.get(tag).map(hs -> (HolderSet) hs).orElse(HolderSet.empty()); - return (ConsumeEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + return (ItemActionEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); } @Override - public ConsumeEffect.ClearEffects clearEffects() { - return (ConsumeEffect.ClearEffects) (Object) ClearAllStatusEffectsConsumeEffect.INSTANCE; + public ItemActionEffect.ClearEffects clearEffects() { + return (ItemActionEffect.ClearEffects) (Object) ClearAllStatusEffectsConsumeEffect.INSTANCE; } @Override - public ConsumeEffect.PlaySound playSound(final SoundType soundType) { + public ItemActionEffect.PlaySound playSound(final SoundType soundType) { Objects.requireNonNull(soundType, "soundType"); - return (ConsumeEffect.PlaySound) (Object) new PlaySoundConsumeEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder((SoundEvent) (Object) soundType)); + return (ItemActionEffect.PlaySound) (Object) new PlaySoundConsumeEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder((SoundEvent) (Object) soundType)); } @Override - public ConsumeEffect.TeleportRandomly teleportRandomly(final double distance) { + public ItemActionEffect.TeleportRandomly teleportRandomly(final double distance) { if (distance <= 0) { throw new IllegalArgumentException("distance must be positive: " + distance); } - return (ConsumeEffect.TeleportRandomly) (Object) new TeleportRandomlyConsumeEffect((float) distance * 2); + return (ItemActionEffect.TeleportRandomly) (Object) new TeleportRandomlyConsumeEffect((float) distance * 2); } } diff --git a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java index 7022b56db36..93956caf3f5 100644 --- a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java +++ b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java @@ -41,7 +41,7 @@ import org.spongepowered.api.command.registrar.tree.CommandTreeNode; import org.spongepowered.api.command.selector.Selector; import org.spongepowered.api.data.DataManipulator; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.data.type.ToolRule; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.effect.ForwardingViewer; @@ -125,7 +125,7 @@ import org.spongepowered.common.entity.effect.SpongeVanishState; import org.spongepowered.common.event.SpongeEventListenerRegistration; import org.spongepowered.common.event.tracking.BlockChangeFlagManager; -import org.spongepowered.common.item.SpongeConsumeEffectFactory; +import org.spongepowered.common.item.SpongeItemActionEffectFactory; import org.spongepowered.common.item.SpongeItemStack; import org.spongepowered.common.item.SpongeItemStackSnapshot; import org.spongepowered.common.item.SpongeToolRuleFactory; @@ -284,7 +284,7 @@ public void registerDefaultFactories() { .registerFactory(NaturalSpawner.Factory.class, new SpongeNaturalSpawnerFactory()) .registerFactory(ScoreFormat.Factory.class, new SpongeScoreFormatFactory()) .registerFactory(ToolRule.Factory.class, new SpongeToolRuleFactory()) - .registerFactory(ConsumeEffect.Factory.class, new SpongeConsumeEffectFactory()) + .registerFactory(ItemActionEffect.Factory.class, new SpongeItemActionEffectFactory()) .registerFactory(PortalLogic.Factory.class, new SpongePortalLogicFactory()) .registerFactory(RecipeInput.Factory.class, new SpongeRecipeInputFactory()) .registerFactory(ArmorTrim.Factory.class, new SpongeArmorTrimFactory()) diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java index 1a39f5b02e1..9ba0a97ec47 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java @@ -26,7 +26,7 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Implements; @@ -38,8 +38,8 @@ import java.util.List; @Mixin(ApplyStatusEffectsConsumeEffect.class) -@Implements(@Interface(iface = ConsumeEffect.ApplyEffects.class, prefix = "consumeEffect$")) -public abstract class ApplyStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.ApplyEffects { +@Implements(@Interface(iface = ItemActionEffect.ApplyEffects.class, prefix = "consumeEffect$")) +public abstract class ApplyStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.ApplyEffects { @Shadow @Final private float probability; @Shadow @Final private List effects; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java index 14928f4aa98..701ef70a508 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java @@ -25,9 +25,9 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.asm.mixin.Mixin; @Mixin(ClearAllStatusEffectsConsumeEffect.class) -public abstract class ClearAllStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.ClearEffects { +public abstract class ClearAllStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.ClearEffects { } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java index 3f938b8f2c4..eb8b43f1e31 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -28,7 +28,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.consume_effects.ConsumeEffect; import net.minecraft.world.level.Level; -import org.spongepowered.api.data.type.ConsumeEffectType; +import org.spongepowered.api.data.type.ItemActionEffectType; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.api.world.World; @@ -39,14 +40,14 @@ import java.util.Objects; @Mixin(ConsumeEffect.class) -public interface ConsumeEffectMixin_API extends org.spongepowered.api.data.type.ConsumeEffect { +public interface ConsumeEffectMixin_API extends ItemActionEffect { @Shadow ConsumeEffect.Type shadow$getType(); @Shadow boolean shadow$apply(Level level, ItemStack itemStack, LivingEntity livingEntity); @Override - default ConsumeEffectType type() { - return (ConsumeEffectType) (Object) this.shadow$getType(); + default ItemActionEffectType type() { + return (ItemActionEffectType) (Object) this.shadow$getType(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java index 033281fd115..bf5f75379fe 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java @@ -25,9 +25,9 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.ConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffectType; +import org.spongepowered.api.data.type.ItemActionEffectType; import org.spongepowered.asm.mixin.Mixin; @Mixin(ConsumeEffect.Type.class) -public abstract class ConsumeEffect_TypeMixin_API implements ConsumeEffectType { +public abstract class ConsumeEffect_TypeMixin_API implements ItemActionEffectType { } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java index b2321ecd3b4..e426c3e4c63 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java @@ -27,14 +27,14 @@ import net.minecraft.core.Holder; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.effect.sound.SoundType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(PlaySoundConsumeEffect.class) -public abstract class PlaySoundConsumeEffectMixin_API implements ConsumeEffect.PlaySound { +public abstract class PlaySoundConsumeEffectMixin_API implements ItemActionEffect.PlaySound { @Shadow @Final private Holder sound; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java index ee5f14f37ef..f620b12595d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java @@ -28,7 +28,7 @@ import net.minecraft.core.HolderSet; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.effect.potion.PotionEffectType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -38,7 +38,7 @@ import java.util.stream.Collectors; @Mixin(RemoveStatusEffectsConsumeEffect.class) -public abstract class RemoveStatusEffectsConsumeEffectMixin_API implements ConsumeEffect.RemoveEffects { +public abstract class RemoveStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.RemoveEffects { @Shadow @Final private HolderSet effects; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java index dbe1ad5fc0f..6a8dbd7b6ea 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java @@ -25,13 +25,13 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(TeleportRandomlyConsumeEffect.class) -public abstract class TeleportRandomlyConsumeEffectMixin_API implements ConsumeEffect.TeleportRandomly { +public abstract class TeleportRandomlyConsumeEffectMixin_API implements ItemActionEffect.TeleportRandomly { @Shadow @Final private float diameter; diff --git a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java index 9fe89533aa3..f14c7a36249 100644 --- a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java @@ -30,7 +30,7 @@ import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.parameter.CommandContext; import org.spongepowered.api.data.Keys; -import org.spongepowered.api.data.type.ConsumeEffect; +import org.spongepowered.api.data.type.ItemActionEffect; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.api.effect.potion.PotionEffectTypes; import org.spongepowered.api.effect.sound.SoundTypes; @@ -75,18 +75,18 @@ private CommandResult items(final CommandContext commandContext) { final ItemStack stack1 = ItemStack.of(ItemTypes.BRICKS); stack1.offer(Keys.CUSTOM_NAME, Component.text("Remove slowness, get speed & regeneration")); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.playSound(SoundTypes.BLOCK_ANVIL_BREAK)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.teleportRandomly(5)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.removeEffects(PotionEffectTypes.SLOWNESS)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.applyEffects( + stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.playSound(SoundTypes.BLOCK_ANVIL_BREAK)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.teleportRandomly(5)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.removeEffects(PotionEffectTypes.SLOWNESS)); + stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.applyEffects( PotionEffect.of(PotionEffectTypes.SPEED, 1, Ticks.of(20 * 30)), PotionEffect.of(PotionEffectTypes.REGENERATION, 0, Ticks.of(20 * 30)) )); final ItemStack stack2 = ItemStack.of(ItemTypes.CHORUS_FRUIT); stack2.offer(Keys.CUSTOM_NAME, Component.text("Remove all effects, get slowness & haste with 50% chance")); - stack2.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.clearEffects()); - stack2.offerSingle(Keys.CONSUME_EFFECTS, ConsumeEffect.applyEffects(0.5, + stack2.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.clearEffects()); + stack2.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.applyEffects(0.5, PotionEffect.of(PotionEffectTypes.SLOWNESS, 1, Ticks.of(20 * 10)), PotionEffect.of(PotionEffectTypes.HASTE, 0, Ticks.of(20 * 10)) )); @@ -97,7 +97,7 @@ private CommandResult items(final CommandContext commandContext) { final ItemStack stack4 = ItemStack.of(ItemTypes.ANVIL); stack4.offer(Keys.CUSTOM_NAME, Component.text("Teleport on death")); - stack4.offerSingle(Keys.DEATH_PROTECTION_EFFECTS, ConsumeEffect.teleportRandomly(20)); + stack4.offerSingle(Keys.DEATH_PROTECTION_EFFECTS, ItemActionEffect.teleportRandomly(20)); player.inventory().offer(stack1, stack2, stack3, stack4); return CommandResult.success(); @@ -109,7 +109,7 @@ private CommandResult applyTeleport(final CommandContext commandContext) { return CommandResult.error(Component.text("Must be run ingame by a player")); } - ConsumeEffect.teleportRandomly(20).apply(player); + ItemActionEffect.teleportRandomly(20).apply(player); return CommandResult.success(); } @@ -119,7 +119,7 @@ private CommandResult applySound(final CommandContext commandContext) { return CommandResult.error(Component.text("Must be run ingame by a player")); } - ConsumeEffect.playSound(SoundTypes.BLOCK_BELL_USE).apply(player); + ItemActionEffect.playSound(SoundTypes.BLOCK_BELL_USE).apply(player); return CommandResult.success(); } } From 99e8e6902571f83bf1a9b397c24073ab407d9049 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 05:13:03 +0300 Subject: [PATCH 08/12] remove world arg for ItemActionEffect#apply --- SpongeAPI | 2 +- .../world/item/consume_effects/ConsumeEffectMixin_API.java | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index b4ec15e3eea..24162feaf53 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit b4ec15e3eeabf9fbd658211c6d464612c6078915 +Subproject commit 24162feaf53a8b617b57ec3851e6cb62dbe7175d diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java index eb8b43f1e31..de001200790 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -51,10 +51,11 @@ default ItemActionEffectType type() { } @Override - default boolean apply(final World world, final Living entity, final ItemStackLike stack) { + default boolean apply(final Living entity, final ItemStackLike stack) { + Objects.requireNonNull(entity, "entity"); return this.shadow$apply( - (Level) Objects.requireNonNull(world, "world"), + (Level) entity.world(), ItemStackUtil.fromLikeToNativeCopy(stack), - (LivingEntity) Objects.requireNonNull(entity, "entity")); + (LivingEntity) entity); } } From 29ebb95e64f17265b4b2c163605b955ed38756d2 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 31 Mar 2025 05:24:25 +0300 Subject: [PATCH 09/12] Update SpongeAPI --- SpongeAPI | 2 +- .../world/item/consume_effects/ConsumeEffectMixin_API.java | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/SpongeAPI b/SpongeAPI index 495986e40c6..e0debb69677 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 495986e40c607e75e0717c641872fcbbd0a3ed11 +Subproject commit e0debb69677b4f60544bc4daa1e93c7bdd686b5c diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java index de001200790..4f8c93aff14 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -28,11 +28,10 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.consume_effects.ConsumeEffect; import net.minecraft.world.level.Level; -import org.spongepowered.api.data.type.ItemActionEffectType; import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemActionEffectType; import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.item.inventory.ItemStackLike; -import org.spongepowered.api.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.common.item.util.ItemStackUtil; From 430e9f8d31a54eb61c01ecc3bb5a17ad1dae710a Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 15 Sep 2025 19:35:40 +0300 Subject: [PATCH 10/12] rename to ItemAction --- SpongeAPI | 2 +- .../generator/item/ItemRegistries.java | 6 ++-- .../provider/item/stack/ItemStackData.java | 10 +++---- ...tory.java => SpongeItemActionFactory.java} | 28 +++++++++---------- .../registry/SpongeFactoryProvider.java | 6 ++-- ...lyStatusEffectsConsumeEffectMixin_API.java | 6 ++-- ...llStatusEffectsConsumeEffectMixin_API.java | 4 +-- .../ConsumeEffectMixin_API.java | 10 +++---- .../ConsumeEffect_TypeMixin_API.java | 4 +-- .../PlaySoundConsumeEffectMixin_API.java | 4 +-- ...veStatusEffectsConsumeEffectMixin_API.java | 4 +-- ...eleportRandomlyConsumeEffectMixin_API.java | 4 +-- .../test/data/ConsumableDataTest.java | 22 +++++++-------- 13 files changed, 55 insertions(+), 55 deletions(-) rename src/main/java/org/spongepowered/common/item/{SpongeItemActionEffectFactory.java => SpongeItemActionFactory.java} (69%) diff --git a/SpongeAPI b/SpongeAPI index e0debb69677..60cc9274b7e 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit e0debb69677b4f60544bc4daa1e93c7bdd686b5c +Subproject commit 60cc9274b7e7d14a9b54bafdfd243658bc13ee51 diff --git a/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java b/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java index 2213ba49c23..205a2cc1934 100644 --- a/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java +++ b/generator/src/main/java/org/spongepowered/vanilla/generator/item/ItemRegistries.java @@ -113,9 +113,9 @@ public static List itemRegistries(final Context context) { ), new RegistryEntriesGenerator<>( "data.type", - "ConsumeEffectTypes", - "CONSUME_EFFECT_TYPE", - context.relativeClass("data.type", "ConsumeEffectType"), + "ItemActionTypes", + "ITEM_ACTION_TYPE", + context.relativeClass("data.type", "ItemActionType"), Registries.CONSUME_EFFECT_TYPE ), new EnumEntriesValidator<>( diff --git a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java index 7fa061e5625..e79df261604 100644 --- a/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java +++ b/src/main/java/org/spongepowered/common/data/provider/item/stack/ItemStackData.java @@ -55,7 +55,7 @@ import org.spongepowered.api.ResourceKey; import org.spongepowered.api.data.DataTransactionResult; import org.spongepowered.api.data.Keys; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.item.ItemRarity; import org.spongepowered.api.item.ItemType; @@ -243,17 +243,17 @@ public static void register(final DataProviderRegistrator registrator) { }) .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, c -> new Consumable(v.ticks() / 20f, c.animation(), c.sound(), c.hasConsumeParticles(), c.onConsumeEffects()))) - .create(Keys.CONSUME_EFFECTS) + .create(Keys.CONSUME_ACTIONS) .get(h -> { final var consumable = h.get(DataComponents.CONSUMABLE); - return consumable == null ? null : (List) (Object) consumable.onConsumeEffects(); + return consumable == null ? null : (List) (Object) consumable.onConsumeEffects(); }) .set((h, v) -> h.update(DataComponents.CONSUMABLE, DEFAULT_CONSUMABLE_PROPERTIES, c -> new Consumable(c.consumeSeconds(), c.animation(), c.sound(), c.hasConsumeParticles(), (List) (Object) v))) - .create(Keys.DEATH_PROTECTION_EFFECTS) + .create(Keys.DEATH_PROTECTION_ACTIONS) .get(h -> { final var deathProtection = h.get(DataComponents.DEATH_PROTECTION); - return deathProtection == null ? null : (List) (Object) deathProtection.deathEffects(); + return deathProtection == null ? null : (List) (Object) deathProtection.deathEffects(); }) .set((h, v) -> h.set(DataComponents.DEATH_PROTECTION, new DeathProtection((List) (Object) v))) .delete(h -> h.remove(DataComponents.DEATH_PROTECTION)) diff --git a/src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java b/src/main/java/org/spongepowered/common/item/SpongeItemActionFactory.java similarity index 69% rename from src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java rename to src/main/java/org/spongepowered/common/item/SpongeItemActionFactory.java index 39d707bdb3c..ce8a0bcc56f 100644 --- a/src/main/java/org/spongepowered/common/item/SpongeItemActionEffectFactory.java +++ b/src/main/java/org/spongepowered/common/item/SpongeItemActionFactory.java @@ -34,7 +34,7 @@ import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.api.effect.potion.PotionEffectType; import org.spongepowered.api.effect.sound.SoundType; @@ -44,50 +44,50 @@ import java.util.Objects; import java.util.Set; -public class SpongeItemActionEffectFactory implements ItemActionEffect.Factory { +public class SpongeItemActionFactory implements ItemAction.Factory { @Override - public ItemActionEffect.ApplyEffects applyEffects(final double chance, final List effects) { + public ItemAction.ApplyEffects applyEffects(final double chance, final List effects) { Objects.requireNonNull(effects, "effects"); if (chance < 0 || chance > 1) { throw new IllegalArgumentException("chance must be in range [0; 1]: " + chance); } - return (ItemActionEffect.ApplyEffects) (Object) new ApplyStatusEffectsConsumeEffect((List) List.copyOf(effects), (float) chance); + return (ItemAction.ApplyEffects) (Object) new ApplyStatusEffectsConsumeEffect((List) List.copyOf(effects), (float) chance); } @Override - public ItemActionEffect.RemoveEffects removeEffects(final Set effectTypes) { + public ItemAction.RemoveEffects removeEffects(final Set effectTypes) { Objects.requireNonNull(effectTypes, "effectTypes"); final var holderSet = HolderSet.direct( effectType -> BuiltInRegistries.MOB_EFFECT.wrapAsHolder((MobEffect) effectType), effectTypes); - return (ItemActionEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + return (ItemAction.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); } @Override - public ItemActionEffect.RemoveEffects removeEffects(final Tag effectTypeTag) { + public ItemAction.RemoveEffects removeEffects(final Tag effectTypeTag) { Objects.requireNonNull(effectTypeTag, "effectTypeTag"); final var tag = (TagKey) (Object) effectTypeTag; final var holderSet = BuiltInRegistries.MOB_EFFECT.get(tag).map(hs -> (HolderSet) hs).orElse(HolderSet.empty()); - return (ItemActionEffect.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); + return (ItemAction.RemoveEffects) (Object) new RemoveStatusEffectsConsumeEffect(holderSet); } @Override - public ItemActionEffect.ClearEffects clearEffects() { - return (ItemActionEffect.ClearEffects) (Object) ClearAllStatusEffectsConsumeEffect.INSTANCE; + public ItemAction.ClearEffects clearEffects() { + return (ItemAction.ClearEffects) (Object) ClearAllStatusEffectsConsumeEffect.INSTANCE; } @Override - public ItemActionEffect.PlaySound playSound(final SoundType soundType) { + public ItemAction.PlaySound playSound(final SoundType soundType) { Objects.requireNonNull(soundType, "soundType"); - return (ItemActionEffect.PlaySound) (Object) new PlaySoundConsumeEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder((SoundEvent) (Object) soundType)); + return (ItemAction.PlaySound) (Object) new PlaySoundConsumeEffect(BuiltInRegistries.SOUND_EVENT.wrapAsHolder((SoundEvent) (Object) soundType)); } @Override - public ItemActionEffect.TeleportRandomly teleportRandomly(final double distance) { + public ItemAction.TeleportRandomly teleportRandomly(final double distance) { if (distance <= 0) { throw new IllegalArgumentException("distance must be positive: " + distance); } - return (ItemActionEffect.TeleportRandomly) (Object) new TeleportRandomlyConsumeEffect((float) distance * 2); + return (ItemAction.TeleportRandomly) (Object) new TeleportRandomlyConsumeEffect((float) distance * 2); } } diff --git a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java index 93956caf3f5..be85b8c32d7 100644 --- a/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java +++ b/src/main/java/org/spongepowered/common/registry/SpongeFactoryProvider.java @@ -41,7 +41,7 @@ import org.spongepowered.api.command.registrar.tree.CommandTreeNode; import org.spongepowered.api.command.selector.Selector; import org.spongepowered.api.data.DataManipulator; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.data.type.ToolRule; import org.spongepowered.api.data.value.Value; import org.spongepowered.api.effect.ForwardingViewer; @@ -125,7 +125,7 @@ import org.spongepowered.common.entity.effect.SpongeVanishState; import org.spongepowered.common.event.SpongeEventListenerRegistration; import org.spongepowered.common.event.tracking.BlockChangeFlagManager; -import org.spongepowered.common.item.SpongeItemActionEffectFactory; +import org.spongepowered.common.item.SpongeItemActionFactory; import org.spongepowered.common.item.SpongeItemStack; import org.spongepowered.common.item.SpongeItemStackSnapshot; import org.spongepowered.common.item.SpongeToolRuleFactory; @@ -284,7 +284,7 @@ public void registerDefaultFactories() { .registerFactory(NaturalSpawner.Factory.class, new SpongeNaturalSpawnerFactory()) .registerFactory(ScoreFormat.Factory.class, new SpongeScoreFormatFactory()) .registerFactory(ToolRule.Factory.class, new SpongeToolRuleFactory()) - .registerFactory(ItemActionEffect.Factory.class, new SpongeItemActionEffectFactory()) + .registerFactory(ItemAction.Factory.class, new SpongeItemActionFactory()) .registerFactory(PortalLogic.Factory.class, new SpongePortalLogicFactory()) .registerFactory(RecipeInput.Factory.class, new SpongeRecipeInputFactory()) .registerFactory(ArmorTrim.Factory.class, new SpongeArmorTrimFactory()) diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java index 9ba0a97ec47..1a2c5a5b2c4 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ApplyStatusEffectsConsumeEffectMixin_API.java @@ -26,7 +26,7 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.consume_effects.ApplyStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Implements; @@ -38,8 +38,8 @@ import java.util.List; @Mixin(ApplyStatusEffectsConsumeEffect.class) -@Implements(@Interface(iface = ItemActionEffect.ApplyEffects.class, prefix = "consumeEffect$")) -public abstract class ApplyStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.ApplyEffects { +@Implements(@Interface(iface = ItemAction.ApplyEffects.class, prefix = "consumeEffect$")) +public abstract class ApplyStatusEffectsConsumeEffectMixin_API implements ItemAction.ApplyEffects { @Shadow @Final private float probability; @Shadow @Final private List effects; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java index 701ef70a508..ffb15a2514d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ClearAllStatusEffectsConsumeEffectMixin_API.java @@ -25,9 +25,9 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.ClearAllStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.asm.mixin.Mixin; @Mixin(ClearAllStatusEffectsConsumeEffect.class) -public abstract class ClearAllStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.ClearEffects { +public abstract class ClearAllStatusEffectsConsumeEffectMixin_API implements ItemAction.ClearEffects { } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java index 4f8c93aff14..b6157338515 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffectMixin_API.java @@ -28,8 +28,8 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.consume_effects.ConsumeEffect; import net.minecraft.world.level.Level; -import org.spongepowered.api.data.type.ItemActionEffect; -import org.spongepowered.api.data.type.ItemActionEffectType; +import org.spongepowered.api.data.type.ItemAction; +import org.spongepowered.api.data.type.ItemActionType; import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.item.inventory.ItemStackLike; import org.spongepowered.asm.mixin.Mixin; @@ -39,14 +39,14 @@ import java.util.Objects; @Mixin(ConsumeEffect.class) -public interface ConsumeEffectMixin_API extends ItemActionEffect { +public interface ConsumeEffectMixin_API extends ItemAction { @Shadow ConsumeEffect.Type shadow$getType(); @Shadow boolean shadow$apply(Level level, ItemStack itemStack, LivingEntity livingEntity); @Override - default ItemActionEffectType type() { - return (ItemActionEffectType) (Object) this.shadow$getType(); + default ItemActionType type() { + return (ItemActionType) (Object) this.shadow$getType(); } @Override diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java index bf5f75379fe..31e206c0c91 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/ConsumeEffect_TypeMixin_API.java @@ -25,9 +25,9 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.ConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffectType; +import org.spongepowered.api.data.type.ItemActionType; import org.spongepowered.asm.mixin.Mixin; @Mixin(ConsumeEffect.Type.class) -public abstract class ConsumeEffect_TypeMixin_API implements ItemActionEffectType { +public abstract class ConsumeEffect_TypeMixin_API implements ItemActionType { } diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java index e426c3e4c63..4e3f681d634 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/PlaySoundConsumeEffectMixin_API.java @@ -27,14 +27,14 @@ import net.minecraft.core.Holder; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.effect.sound.SoundType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(PlaySoundConsumeEffect.class) -public abstract class PlaySoundConsumeEffectMixin_API implements ItemActionEffect.PlaySound { +public abstract class PlaySoundConsumeEffectMixin_API implements ItemAction.PlaySound { @Shadow @Final private Holder sound; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java index f620b12595d..1aad96d28f3 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/RemoveStatusEffectsConsumeEffectMixin_API.java @@ -28,7 +28,7 @@ import net.minecraft.core.HolderSet; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.effect.potion.PotionEffectType; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; @@ -38,7 +38,7 @@ import java.util.stream.Collectors; @Mixin(RemoveStatusEffectsConsumeEffect.class) -public abstract class RemoveStatusEffectsConsumeEffectMixin_API implements ItemActionEffect.RemoveEffects { +public abstract class RemoveStatusEffectsConsumeEffectMixin_API implements ItemAction.RemoveEffects { @Shadow @Final private HolderSet effects; diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java index 6a8dbd7b6ea..b1a9f2bd27d 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/item/consume_effects/TeleportRandomlyConsumeEffectMixin_API.java @@ -25,13 +25,13 @@ package org.spongepowered.common.mixin.api.minecraft.world.item.consume_effects; import net.minecraft.world.item.consume_effects.TeleportRandomlyConsumeEffect; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @Mixin(TeleportRandomlyConsumeEffect.class) -public abstract class TeleportRandomlyConsumeEffectMixin_API implements ItemActionEffect.TeleportRandomly { +public abstract class TeleportRandomlyConsumeEffectMixin_API implements ItemAction.TeleportRandomly { @Shadow @Final private float diameter; diff --git a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java index f14c7a36249..2f228a8f3a5 100644 --- a/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java +++ b/testplugins/src/main/java/org/spongepowered/test/data/ConsumableDataTest.java @@ -30,7 +30,7 @@ import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.parameter.CommandContext; import org.spongepowered.api.data.Keys; -import org.spongepowered.api.data.type.ItemActionEffect; +import org.spongepowered.api.data.type.ItemAction; import org.spongepowered.api.effect.potion.PotionEffect; import org.spongepowered.api.effect.potion.PotionEffectTypes; import org.spongepowered.api.effect.sound.SoundTypes; @@ -75,29 +75,29 @@ private CommandResult items(final CommandContext commandContext) { final ItemStack stack1 = ItemStack.of(ItemTypes.BRICKS); stack1.offer(Keys.CUSTOM_NAME, Component.text("Remove slowness, get speed & regeneration")); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.playSound(SoundTypes.BLOCK_ANVIL_BREAK)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.teleportRandomly(5)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.removeEffects(PotionEffectTypes.SLOWNESS)); - stack1.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.applyEffects( + stack1.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.playSound(SoundTypes.BLOCK_ANVIL_BREAK)); + stack1.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.teleportRandomly(5)); + stack1.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.removeEffects(PotionEffectTypes.SLOWNESS)); + stack1.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.applyEffects( PotionEffect.of(PotionEffectTypes.SPEED, 1, Ticks.of(20 * 30)), PotionEffect.of(PotionEffectTypes.REGENERATION, 0, Ticks.of(20 * 30)) )); final ItemStack stack2 = ItemStack.of(ItemTypes.CHORUS_FRUIT); stack2.offer(Keys.CUSTOM_NAME, Component.text("Remove all effects, get slowness & haste with 50% chance")); - stack2.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.clearEffects()); - stack2.offerSingle(Keys.CONSUME_EFFECTS, ItemActionEffect.applyEffects(0.5, + stack2.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.clearEffects()); + stack2.offerSingle(Keys.CONSUME_ACTIONS, ItemAction.applyEffects(0.5, PotionEffect.of(PotionEffectTypes.SLOWNESS, 1, Ticks.of(20 * 10)), PotionEffect.of(PotionEffectTypes.HASTE, 0, Ticks.of(20 * 10)) )); final ItemStack stack3 = ItemStack.of(ItemTypes.TOTEM_OF_UNDYING); stack3.offer(Keys.CUSTOM_NAME, Component.text("No death protection")); - stack3.remove(Keys.DEATH_PROTECTION_EFFECTS); + stack3.remove(Keys.DEATH_PROTECTION_ACTIONS); final ItemStack stack4 = ItemStack.of(ItemTypes.ANVIL); stack4.offer(Keys.CUSTOM_NAME, Component.text("Teleport on death")); - stack4.offerSingle(Keys.DEATH_PROTECTION_EFFECTS, ItemActionEffect.teleportRandomly(20)); + stack4.offerSingle(Keys.DEATH_PROTECTION_ACTIONS, ItemAction.teleportRandomly(20)); player.inventory().offer(stack1, stack2, stack3, stack4); return CommandResult.success(); @@ -109,7 +109,7 @@ private CommandResult applyTeleport(final CommandContext commandContext) { return CommandResult.error(Component.text("Must be run ingame by a player")); } - ItemActionEffect.teleportRandomly(20).apply(player); + ItemAction.teleportRandomly(20).apply(player); return CommandResult.success(); } @@ -119,7 +119,7 @@ private CommandResult applySound(final CommandContext commandContext) { return CommandResult.error(Component.text("Must be run ingame by a player")); } - ItemActionEffect.playSound(SoundTypes.BLOCK_BELL_USE).apply(player); + ItemAction.playSound(SoundTypes.BLOCK_BELL_USE).apply(player); return CommandResult.success(); } } From 6bc06169e9f72d273510ee4ec09f5ed09a9d5e8d Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 15 Sep 2025 21:53:24 +0300 Subject: [PATCH 11/12] Update SpongeAPI --- SpongeAPI | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SpongeAPI b/SpongeAPI index 60cc9274b7e..34dda9c933d 160000 --- a/SpongeAPI +++ b/SpongeAPI @@ -1 +1 @@ -Subproject commit 60cc9274b7e7d14a9b54bafdfd243658bc13ee51 +Subproject commit 34dda9c933d867c35e04fd77d951d6440ff2a384 From ebbe361042bdc6819fa01aef0fc4826350d93526 Mon Sep 17 00:00:00 2001 From: MrHell228 Date: Mon, 15 Sep 2025 22:18:43 +0300 Subject: [PATCH 12/12] remove leftover from merge commit --- .../world/effect/MobEffectMixin_API.java | 27 ------------------- 1 file changed, 27 deletions(-) diff --git a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java index f28400cd18c..11c63c2219c 100644 --- a/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java +++ b/src/mixins/java/org/spongepowered/common/mixin/api/minecraft/world/effect/MobEffectMixin_API.java @@ -25,25 +25,15 @@ package org.spongepowered.common.mixin.api.minecraft.world.effect; import net.kyori.adventure.text.Component; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; -import net.minecraft.core.registries.Registries; -import net.minecraft.tags.TagKey; import net.minecraft.world.effect.MobEffect; import org.spongepowered.api.effect.potion.PotionEffectType; -import org.spongepowered.api.registry.DefaultedRegistryType; -import org.spongepowered.api.registry.RegistryTypes; -import org.spongepowered.api.tag.Tag; import org.spongepowered.asm.mixin.Implements; import org.spongepowered.asm.mixin.Interface; import org.spongepowered.asm.mixin.Interface.Remap; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.common.SpongeCommon; import org.spongepowered.common.adventure.SpongeAdventure; -import java.util.Collection; - @Mixin(MobEffect.class) @Implements(@Interface(iface = PotionEffectType.class, prefix = "potionEffectType$", remap = Remap.NONE)) public abstract class MobEffectMixin_API implements PotionEffectType { @@ -61,21 +51,4 @@ public abstract class MobEffectMixin_API implements PotionEffectType { public Component asComponent() { return SpongeAdventure.asAdventure(this.shadow$getDisplayName()); } - - @Override - public DefaultedRegistryType registryType() { - return RegistryTypes.POTION_EFFECT_TYPE; - } - - @Override - public Collection> tags() { - return this.registryType().get().tags().filter(this::is).toList(); - } - - @Override - public boolean is(final Tag tag) { - final Registry registry = SpongeCommon.vanillaRegistry(Registries.MOB_EFFECT); - final Holder.Reference holder = registry.createIntrusiveHolder((MobEffect) (Object) this); - return holder.is(((TagKey) (Object) tag)); - } }