From 4c9d62326fa96aea984f94c8b183d714dea9f840 Mon Sep 17 00:00:00 2001 From: Space Walker Date: Fri, 9 Oct 2026 14:51:58 +0200 Subject: [PATCH] Implement Effects API --- libraries/effects/README.md | 41 +++++ libraries/effects/build.gradle | 1 + .../effects-mc14w28a-mc1.8.9/build.gradle | 1 + .../gradle.properties | 4 + .../osl/effects/api/StatusEffectEvents.java | 34 ++++ .../osl/effects/api/StatusEffectRegistry.java | 109 +++++++++++++ .../api/effect/StatusEffectExtension.java | 16 ++ .../osl/effects/impl/EffectsInit.java | 10 ++ .../impl/StatusEffectRegistryImpl.java | 111 ++++++++++++++ .../effects/impl/VanillaStatusEffects.java | 75 +++++++++ .../impl/WrappedStatusEffectRegistry.java | 50 ++++++ .../effect/StatusEffectExtensionImpl.java | 6 + .../impl/effect/StatusEffectIdFixer.java | 19 +++ .../impl/mixin/common/StatusEffectMixin.java | 140 +++++++++++++++++ .../src/main/resources/fabric.mod.json | 37 +++++ .../main/resources/osl.effects.classtweaker | 7 + .../main/resources/osl.effects.mixins.json | 16 ++ .../effects-mc15w31a-mc18w31a/build.gradle | 1 + .../gradle.properties | 4 + .../osl/effects/api/StatusEffectEvents.java | 34 ++++ .../osl/effects/api/StatusEffectRegistry.java | 94 ++++++++++++ .../osl/effects/impl/EffectsInit.java | 10 ++ .../impl/StatusEffectRegistryImpl.java | 80 ++++++++++ .../impl/mixin/common/StatusEffectMixin.java | 64 ++++++++ .../src/main/resources/fabric.mod.json | 36 +++++ .../main/resources/osl.effects.mixins.json | 17 ++ .../effects-mc18w32a-mc1.13.2/build.gradle | 1 + .../gradle.properties | 4 + .../osl/effects/api/StatusEffectEvents.java | 34 ++++ .../osl/effects/api/StatusEffectRegistry.java | 94 ++++++++++++ .../osl/effects/impl/EffectsInit.java | 10 ++ .../impl/StatusEffectRegistryImpl.java | 80 ++++++++++ .../impl/mixin/common/StatusEffectMixin.java | 34 ++++ .../src/main/resources/fabric.mod.json | 36 +++++ .../main/resources/osl.effects.mixins.json | 16 ++ .../effects-mc18w43a-mc1.14.4/build.gradle | 1 + .../gradle.properties | 4 + .../osl/effects/api/StatusEffectEvents.java | 34 ++++ .../osl/effects/api/StatusEffectRegistry.java | 94 ++++++++++++ .../osl/effects/impl/EffectsInit.java | 10 ++ .../impl/StatusEffectRegistryImpl.java | 80 ++++++++++ .../impl/mixin/common/StatusEffectsMixin.java | 34 ++++ .../src/main/resources/fabric.mod.json | 36 +++++ .../main/resources/osl.effects.mixins.json | 16 ++ .../effects-mcb1.8-pre1-mc14w27b/build.gradle | 1 + .../gradle.properties | 7 + .../osl/effects/api/StatusEffectEvents.java | 34 ++++ .../osl/effects/api/StatusEffectRegistry.java | 109 +++++++++++++ .../api/effect/StatusEffectExtension.java | 12 ++ .../osl/effects/impl/EffectsInit.java | 10 ++ .../impl/StatusEffectRegistryImpl.java | 111 ++++++++++++++ .../effects/impl/VanillaStatusEffects.java | 75 +++++++++ .../effect/StatusEffectExtensionImpl.java | 6 + .../impl/effect/StatusEffectIdFixer.java | 19 +++ .../impl/mixin/common/StatusEffectMixin.java | 145 ++++++++++++++++++ .../src/main/resources/fabric.mod.json | 37 +++++ .../main/resources/osl.effects.classtweaker | 6 + .../main/resources/osl.effects.mixins.json | 17 ++ libraries/effects/gradle.properties | 7 + settings.gradle | 7 + 60 files changed, 2238 insertions(+) create mode 100644 libraries/effects/README.md create mode 100644 libraries/effects/build.gradle create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/build.gradle create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/gradle.properties create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/WrappedStatusEffectRegistry.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.classtweaker create mode 100644 libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.mixins.json create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/build.gradle create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/gradle.properties create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json create mode 100644 libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/osl.effects.mixins.json create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/build.gradle create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/gradle.properties create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json create mode 100644 libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/osl.effects.mixins.json create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/build.gradle create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/gradle.properties create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectsMixin.java create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json create mode 100644 libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/osl.effects.mixins.json create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/build.gradle create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/gradle.properties create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/fabric.mod.json create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.classtweaker create mode 100644 libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.mixins.json create mode 100644 libraries/effects/gradle.properties diff --git a/libraries/effects/README.md b/libraries/effects/README.md new file mode 100644 index 000000000..d20d907f3 --- /dev/null +++ b/libraries/effects/README.md @@ -0,0 +1,41 @@ +# Effects API + +The Effects API provides events and utilities for registering and working with status effects. + +## Registering Custom Status Effects + +Effect registration should be done in a listener to the `REGISTER_STATUS_EFFECTS` event. The `StatusEffectRegistry` class provides utility methods for registering effects. + +An example is shown below. + +```java +package com.example; + +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.entrypoints.api.ModInitializer; + +public class ExampleInitializer implements ModInitializer { + + @Override + public void init() { + StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(ExampleStatusEffects::init); + } +} +``` + +```java +package com.example; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.util.NamespacedIdentifiers; +import net.ornithemc.osl.effects.api.StatusEffectRegistry; + +public final class ExampleStatusEffects { + + public static final CookieStatusEffect COOKIE = StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect()); + + public static void init() { + } +} +``` diff --git a/libraries/effects/build.gradle b/libraries/effects/build.gradle new file mode 100644 index 000000000..e98ba2c6a --- /dev/null +++ b/libraries/effects/build.gradle @@ -0,0 +1 @@ +setUpLibrary(project) diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/build.gradle b/libraries/effects/effects-mc14w28a-mc1.8.9/build.gradle new file mode 100644 index 000000000..0a350fdb3 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/gradle.properties b/libraries/effects/effects-mc14w28a-mc1.8.9/gradle.properties new file mode 100644 index 000000000..79564e3a4 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 14w28a +max_mc_version = 1.8.9 + +minecraft_version = 1.8.9 diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java new file mode 100644 index 000000000..ee1cbc49a --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the status effects lifecycle. + */ +public final class StatusEffectEvents { + + /** + * This event is invoked upon game start-up, after Vanilla effect registration is finished. + * + *

+ * Custom effect registration should be done in a listener of this event. + * Helper methods for registering effects can be found in the {@linkplain + * StatusEffectRegistry} class. + * + *

+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *

+	 * {@code
+	 * StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(() -> {
+	 * 	StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect(StatusEffect.AUTO_ASSIGN_ID));
+	 * });
+	 * }
+	 * 
+ * + * @see StatusEffectRegistry + */ + public static final Event REGISTER_STATUS_EFFECTS = Event.runnable(); + +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java new file mode 100644 index 000000000..7b7cf43c2 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java @@ -0,0 +1,109 @@ +package net.ornithemc.osl.effects.api; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the StatusEffects registry. + */ +public final class StatusEffectRegistry { + + public static final Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given effect. + */ + public static int getId(StatusEffect effect) { + return StatusEffectRegistryImpl.getId(effect); + } + + /** + * @return the namespaced ID assigned to the given effect. + */ + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return StatusEffectRegistryImpl.getIdentifier(effect); + } + + /** + * @return the resource key assigned to the given effect. + */ + public static ResourceKey getKey(StatusEffect effect) { + return StatusEffectRegistryImpl.getKey(effect); + } + + /** + * @return the effect mapped to the given numerical ID. + */ + public static StatusEffect getStatusEffect(int id) { + return StatusEffectRegistryImpl.getStatusEffect(id); + } + + /** + * @return the effect mapped to the given namespaced ID. + */ + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return StatusEffectRegistryImpl.getStatusEffect(identifier); + } + + /** + * @return the effect mapped to the given resource key. + */ + public static StatusEffect getStatusEffect(ResourceKey key) { + return StatusEffectRegistryImpl.getStatusEffect(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return StatusEffectRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set> keySet() { + return StatusEffectRegistryImpl.keySet(); + } + + /** + * @param the effect type. + * @param identifier the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(NamespacedIdentifier identifier, T effect) { + return StatusEffectRegistryImpl.register(identifier, effect); + } + + /** + * @param the effect type. + * @param key the resource key of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(ResourceKey key, T effect) { + return StatusEffectRegistryImpl.register(key, effect); + } + + /** + * @param the effect type. + * @param id the numerical ID of the effect. + * @param key the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + * + * @deprecated use {@linkplain #register(NamespacedIdentifier, StatusEffect)} + * or {@linkplain #register(ResourceKey, StatusEffect)} instead. + */ + @Deprecated + public static T register(int id, NamespacedIdentifier key, T effect) { + return StatusEffectRegistryImpl.register(id, key, effect); + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java new file mode 100644 index 000000000..20afbb6ed --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java @@ -0,0 +1,16 @@ +package net.ornithemc.osl.effects.api.effect; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; + +public interface StatusEffectExtension { + + Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + int AUTO_ASSIGN_ID = -172; + NamespacedIdentifier PLACEHOLDER_NAMESPACED_ID = NamespacedIdentifiers.from("osl", "placeholder"); + +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java new file mode 100644 index 000000000..0ffd88e77 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.effects.impl; + +import net.ornithemc.osl.registries.api.RegistryEvents; + +public final class EffectsInit { + + public static void init() { + RegistryEvents.INIT_REGISTRIES.register(StatusEffectRegistryImpl::init); + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java new file mode 100644 index 000000000..17377ff75 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java @@ -0,0 +1,111 @@ +package net.ornithemc.osl.effects.impl; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.effects.impl.effect.StatusEffectIdFixer; +import net.ornithemc.osl.registries.api.registry.Registries; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.impl.registry.RegistriesImpl; + +public final class StatusEffectRegistryImpl { + + public static final Registry REGISTRY = Registries.registerSimple(RegistryKeys.STATUS_EFFECT, () -> StatusEffect.BY_ID.getClass()); + + private static boolean locked = true; + + public static int getId(StatusEffect effect) { + return REGISTRY.getId(effect); + } + + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return REGISTRY.getIdentifier(effect); + } + + public static ResourceKey getKey(StatusEffect effect) { + return REGISTRY.getKey(effect); + } + + public static StatusEffect getStatusEffect(int id) { + return REGISTRY.get(id); + } + + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static StatusEffect getStatusEffect(ResourceKey key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set> keySet() { + return REGISTRY.keySet(); + } + + @SuppressWarnings("deprecation") + public static T register(NamespacedIdentifier identifier, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, effect.id, identifier, effect); + } + } + + @SuppressWarnings("deprecation") + public static T register(ResourceKey key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, effect.id, key, effect); + } + } + + @Deprecated + public static T register(int id, NamespacedIdentifier key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + if (effect.id != id) { + throw new IllegalArgumentException("ID " + id + " does not match effect ID " + effect.id + " for " + key); + } + + return Registry.register(REGISTRY, id, key, effect); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.STATUS_EFFECT); + SyncedRegistries.registerFixer(RegistryKeys.STATUS_EFFECT, NamespacedIdentifiers.from("mob_effect/id"), new StatusEffectIdFixer()); + } + + public static void unlock() { + locked = false; + } + + public static void registerStatusEffects() { + VanillaStatusEffects.init(); + StatusEffectEvents.REGISTER_STATUS_EFFECTS.invoker().run(); + } + + public static void registerUnknownStatusEffects() { + for (StatusEffect effect : StatusEffect.BY_ID) { + if (effect != null && REGISTRY.getIdentifier(effect) == null) { + NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "mob_effect_" + effect.id); + + RegistriesImpl.LOGGER.warn("StatusEffect {}/{}", effect.id, effect.getClass().getSimpleName() + " was not registered to OSL's StatusEffect registry! Adding it as '" + identifier + "'..."); + StatusEffectRegistryImpl.register(identifier, effect); + } + } + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java new file mode 100644 index 000000000..abd59783f --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java @@ -0,0 +1,75 @@ +package net.ornithemc.osl.effects.impl; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; + +public final class VanillaStatusEffects { + + /** + * Namespaced IDs were introduced in 14w28a. Before then, the numerical IDs + * were the only unique identifiers for status effects, and were still used + * until 1.9 . Here we assign namespaced IDs to pre-1.9 effects, matching + * the 1.9 IDs where possible. + */ + private static final String[] IDENTIFIERS = { + // grouped per 10 for easier lookup + + null, + "speed", + "slowness", + "haste", + "mining_fatigue", + "strength", + "instant_health", + "instant_damage", + "jump_boost", + "nausea", + + "regeneration", + "resistance", + "fire_resistance", + "water_breathing", + "invisibility", + "blindness", + "night_vision", + "hunger", + "weakness", + "poison", + + "wither", + "health_boost", + "absorption", + "saturation" + }; + + public static final int MAX_ID = 255; + + static void init() { + for (Field f : StatusEffect.class.getDeclaredFields()) { + if (Modifier.isStatic(f.getModifiers()) && StatusEffect.class.isAssignableFrom(f.getType())) { + try { + StatusEffect effect = (StatusEffect) f.get(null); + + if (effect != null) { + register(effect); + } + } catch (Throwable t) { + } + } + } + } + + private static void register(StatusEffect effect) { + if (effect.id >= 0 && effect.id < IDENTIFIERS.length) { + String identifier = IDENTIFIERS[effect.id]; + + if (identifier != null) { + StatusEffectRegistryImpl.register(NamespacedIdentifiers.from(identifier), effect); + } + } + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/WrappedStatusEffectRegistry.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/WrappedStatusEffectRegistry.java new file mode 100644 index 000000000..bc029082a --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/WrappedStatusEffectRegistry.java @@ -0,0 +1,50 @@ +package net.ornithemc.osl.effects.impl; + +import net.minecraft.entity.living.effect.StatusEffect; +import net.minecraft.resource.Identifier; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.ResourceKeys; +import net.ornithemc.osl.registries.impl.registry.SimpleRegistry; + +public class WrappedStatusEffectRegistry extends SimpleRegistry { + + private boolean skipStatusEffectRegister; + + WrappedStatusEffectRegistry(NamespacedIdentifier identifier) { + super(identifier); + } + + public void register(int id, NamespacedIdentifier identifier, StatusEffect effect) { + ResourceKey key = ResourceKeys.from(this.identifier(), identifier); + + this.skipStatusEffectRegister = true; + this.register(id, key, effect); + this.skipStatusEffectRegister = false; + } + + @Override + public V register(int id, ResourceKey key, V effect) { + effect = super.register(id, key, effect); + + if (!this.skipStatusEffectRegister) { + Identifier identifier = new Identifier(key.identifier().namespace(), key.identifier().identifier()); + + if (StatusEffect.REGISTRY.containsKey(identifier)) { + throw new IllegalStateException("Duplicate StatusEffect ID " + identifier); + } + + StatusEffect.REGISTRY.put(identifier, effect); + } + + return effect; + } + + @Override + public void clear() { + super.clear(); + + StatusEffect.REGISTRY.clear(); + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java new file mode 100644 index 000000000..ca6295cb6 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java @@ -0,0 +1,6 @@ +package net.ornithemc.osl.effects.impl.effect; + +import net.ornithemc.osl.effects.api.effect.StatusEffectExtension; + +public interface StatusEffectExtensionImpl extends StatusEffectExtension { +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java new file mode 100644 index 000000000..8443e23d6 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java @@ -0,0 +1,19 @@ +package net.ornithemc.osl.effects.impl.effect; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.registries.api.registry.sync.IdFixer; + +public class StatusEffectIdFixer implements IdFixer { + + @Override + public void apply() { + for (int id = 0; id < StatusEffect.BY_ID.length; id++) { + StatusEffect effect = StatusEffect.BY_ID[id]; + + if (effect != null) { + effect.id = id; + } + } + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java new file mode 100644 index 000000000..36f545971 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java @@ -0,0 +1,140 @@ +package net.ornithemc.osl.effects.impl.mixin.common; + +import java.util.Map; + +import org.objectweb.asm.Opcodes; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import com.llamalad7.mixinextras.sugar.Local; + +import net.minecraft.entity.living.effect.StatusEffect; +import net.minecraft.resource.Identifier; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.core.impl.util.Util; +import net.ornithemc.osl.effects.api.effect.StatusEffectExtension; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.effects.impl.VanillaStatusEffects; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.api.registry.sync.ArrayMapper; +import net.ornithemc.osl.registries.api.registry.sync.DynamicArray; + +@Mixin(StatusEffect.class) +public class StatusEffectMixin implements StatusEffectExtension { + + @Shadow @Final @Mutable + private static StatusEffect[] BY_ID; + + @Shadow + private String key; + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$effects$unlockStatusEffectRegistry(CallbackInfo ci) { + StatusEffectRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$effects$registerStatusEffectsAndArrayMappers(CallbackInfo ci) { + StatusEffectRegistryImpl.registerStatusEffects(); + StatusEffectRegistryImpl.registerUnknownStatusEffects(); + + SyncedRegistries.registerMapper(RegistryKeys.STATUS_EFFECT, NamespacedIdentifiers.from("mob_effect/by_id"), ArrayMapper.of(() -> BY_ID, a -> BY_ID = a)); + } + + @ModifyVariable( + method = "", + argsOnly = true, + ordinal = 0, + at = @At( + value = "INVOKE", + target = "Ljava/lang/Object;()V", + shift = Shift.AFTER + ) + ) + private int osl$effects$handleAutoAssignId(int id) { + if (id == AUTO_ASSIGN_ID) { + // the StatusEffect[] array must contain all effects so this should + // give us a valid ID for the StatusEffect registry to use. + id = DynamicArray.length(BY_ID); + + // keep 0-255 free for all Vanilla effects + if (id <= VanillaStatusEffects.MAX_ID) { + id = VanillaStatusEffects.MAX_ID + 1; + } + } + + return id; + } + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/living/effect/StatusEffect;BY_ID:[Lnet/minecraft/entity/living/effect/StatusEffect;", + opcode = Opcodes.GETSTATIC, + args = "array=set" + ) + ) + private void osl$effects$growArrays(CallbackInfo ci, @Local(ordinal = 0) int id) { + int capacity = id + 1; + + BY_ID = DynamicArray.grow(BY_ID, capacity); + } + + @WrapOperation( + method = "", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;" + ) + ) + private Object osl$effects$cancelPlaceholderNamespacedId(Map REGISTRY, Object key, Object effect, Operation op) { + if (key == PLACEHOLDER_NAMESPACED_ID) { + return null; + } else { + return op.call(REGISTRY, key, effect); + } + } + + @Inject( + method = "getTranslationKey", + at = @At( + value = "HEAD" + ) + ) + private void osl$effects$autoAssignTranslationKey(CallbackInfoReturnable cir) { + if (this.key == null) { + NamespacedIdentifier identifier = StatusEffectRegistryImpl.getIdentifier((StatusEffect) (Object) this); + + if (identifier == null) { + this.key = "potion.unknown"; + } else { + this.key = Util.makeTranslationKey("potion", identifier); + } + } + } +} diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..78d7af3e3 --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-effects", + "version": "0.1.0-alpha.1+mc14w28a-mc1.8.9", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.effects.impl.EffectsInit::init" + ] + }, + "mixins": [ + "osl.effects.mixins.json" + ], + "accessWidener": "osl.effects.classtweaker", + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.8-alpha.14.28.a \u003c\u003d1.8.9", + "osl-core": "\u003e\u003d0.11.0", + "osl-entrypoints": "\u003e\u003d0.5.0", + "osl-lifecycle-events": "\u003e\u003d0.6.0", + "osl-executors": "\u003e\u003d0.1.0", + "osl-text-components": "\u003e\u003d0.1.0", + "osl-networking": "\u003e\u003d0.12.1", + "osl-registries": "\u003e\u003d0.4.0" + }, + "name": "OSL Effects", + "description": "Effects API and events.", + "authors": [ + "OrnitheMC" + ], + "contact": { + "homepage": "https://ornithemc.net/", + "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues", + "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.classtweaker b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.classtweaker new file mode 100644 index 000000000..f60b65f9b --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.classtweaker @@ -0,0 +1,7 @@ +classTweaker v1 named + +transitive-inject-interface net/minecraft/entity/living/effect/StatusEffect net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl + +mutable field net/minecraft/entity/living/effect/StatusEffect id I +accessible field net/minecraft/entity/living/effect/StatusEffect BY_ID [Lnet/minecraft/entity/living/effect/StatusEffect; +accessible field net/minecraft/entity/living/effect/StatusEffect REGISTRY Ljava/util/Map; diff --git a/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.mixins.json b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.mixins.json new file mode 100644 index 000000000..e107d62be --- /dev/null +++ b/libraries/effects/effects-mc14w28a-mc1.8.9/src/main/resources/osl.effects.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.effects.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.StatusEffectMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/build.gradle b/libraries/effects/effects-mc15w31a-mc18w31a/build.gradle new file mode 100644 index 000000000..0a350fdb3 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/gradle.properties b/libraries/effects/effects-mc15w31a-mc18w31a/gradle.properties new file mode 100644 index 000000000..86cd93600 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 15w31a +max_mc_version = 18w31a + +minecraft_version = 1.12.2 diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java new file mode 100644 index 000000000..c56c5bfdf --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the status effects lifecycle. + */ +public final class StatusEffectEvents { + + /** + * This event is invoked upon game start-up, after Vanilla effect registration is finished. + * + *

+ * Custom effect registration should be done in a listener of this event. + * Helper methods for registering effects can be found in the {@linkplain + * StatusEffectRegistry} class. + * + *

+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *

+	 * {@code
+	 * StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(() -> {
+	 * 	StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect());
+	 * });
+	 * }
+	 * 
+ * + * @see StatusEffectRegistry + */ + public static final Event REGISTER_STATUS_EFFECTS = Event.runnable(); + +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java new file mode 100644 index 000000000..66a9b8281 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java @@ -0,0 +1,94 @@ +package net.ornithemc.osl.effects.api; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the StatusEffects registry. + */ +public final class StatusEffectRegistry { + + public static final Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given effect. + */ + public static int getId(StatusEffect effect) { + return StatusEffectRegistryImpl.getId(effect); + } + + /** + * @return the namespaced ID assigned to the given effect. + */ + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return StatusEffectRegistryImpl.getIdentifier(effect); + } + + /** + * @return the resource key assigned to the given effect. + */ + public static ResourceKey getKey(StatusEffect effect) { + return StatusEffectRegistryImpl.getKey(effect); + } + + /** + * @return the effect mapped to the given numerical ID. + */ + public static StatusEffect getStatusEffect(int id) { + return StatusEffectRegistryImpl.getStatusEffect(id); + } + + /** + * @return the effect mapped to the given namespaced ID. + */ + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return StatusEffectRegistryImpl.getStatusEffect(identifier); + } + + /** + * @return the effect mapped to the given resource key. + */ + public static StatusEffect getStatusEffect(ResourceKey key) { + return StatusEffectRegistryImpl.getStatusEffect(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return StatusEffectRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set> keySet() { + return StatusEffectRegistryImpl.keySet(); + } + + /** + * @param the effect type. + * @param identifier the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(NamespacedIdentifier identifier, T effect) { + return StatusEffectRegistryImpl.register(identifier, effect); + } + + /** + * @param the effect type. + * @param key the resource key of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(ResourceKey key, T effect) { + return StatusEffectRegistryImpl.register(key, effect); + } +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java new file mode 100644 index 000000000..0ffd88e77 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.effects.impl; + +import net.ornithemc.osl.registries.api.RegistryEvents; + +public final class EffectsInit { + + public static void init() { + RegistryEvents.INIT_REGISTRIES.register(StatusEffectRegistryImpl::init); + } +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java new file mode 100644 index 000000000..d7c7402d5 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.effects.impl; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.impl.registry.VanillaRegistries; + +public final class StatusEffectRegistryImpl { + + public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.STATUS_EFFECT, StatusEffect.REGISTRY); + + private static boolean locked = true; + + public static int getId(StatusEffect effect) { + return REGISTRY.getId(effect); + } + + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return REGISTRY.getIdentifier(effect); + } + + public static ResourceKey getKey(StatusEffect effect) { + return REGISTRY.getKey(effect); + } + + public static StatusEffect getStatusEffect(int id) { + return REGISTRY.get(id); + } + + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static StatusEffect getStatusEffect(ResourceKey key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set> keySet() { + return REGISTRY.keySet(); + } + + public static T register(NamespacedIdentifier identifier, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, effect); + } + } + + public static T register(ResourceKey key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, effect); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.STATUS_EFFECT); + } + + public static void unlock() { + locked = false; + } + + public static void registerStatusEffects() { + StatusEffectEvents.REGISTER_STATUS_EFFECTS.invoker().run(); + } +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java new file mode 100644 index 000000000..a99fa31f2 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java @@ -0,0 +1,64 @@ +package net.ornithemc.osl.effects.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.conditionalmixin.annotations.Conditional; +import net.ornithemc.conditionalmixin.annotations.Version; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.impl.util.Util; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; + +@Mixin(StatusEffect.class) +public class StatusEffectMixin { + + @Conditional(minecraftVersion = @Version("<1.13-pre5")) + @Shadow + private String key; + + @Inject( + method = "init", + at = @At( + value = "HEAD" + ) + ) + private static void osl$effects$unlockStatusEffectRegistry(CallbackInfo ci) { + StatusEffectRegistryImpl.unlock(); + } + + @Inject( + method = "init", + at = @At( + value = "TAIL" + ) + ) + private static void osl$effects$registerStatusEffects(CallbackInfo ci) { + StatusEffectRegistryImpl.registerStatusEffects(); + } + + @Conditional(minecraftVersion = @Version("<1.13-pre5")) + @Inject( + method = "getTranslationKey", + at = @At( + value = "HEAD" + ) + ) + private void osl$effects$autoAssignTranslationKey(CallbackInfoReturnable cir) { + if (this.key == null) { + NamespacedIdentifier identifier = StatusEffectRegistryImpl.getIdentifier((StatusEffect) (Object) this); + + if (identifier == null) { + this.key = "effect.unknown"; + } else { + this.key = Util.makeTranslationKey("effect", identifier); + } + } + } +} diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..311c2cf0a --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "osl-effects", + "version": "0.1.0-alpha.1+mc15w31a-mc18w31a", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.effects.impl.EffectsInit::init" + ] + }, + "mixins": [ + "osl.effects.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.9-alpha.15.31.a \u003c\u003d1.13.1-alpha.18.31.a", + "osl-core": "\u003e\u003d0.11.0", + "osl-entrypoints": "\u003e\u003d0.5.0", + "osl-lifecycle-events": "\u003e\u003d0.6.0", + "osl-executors": "\u003e\u003d0.1.0", + "osl-text-components": "\u003e\u003d0.1.0", + "osl-networking": "\u003e\u003d0.12.1", + "osl-registries": "\u003e\u003d0.4.0" + }, + "name": "OSL Effects", + "description": "Effects API and events.", + "authors": [ + "OrnitheMC" + ], + "contact": { + "homepage": "https://ornithemc.net/", + "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues", + "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/osl.effects.mixins.json b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/osl.effects.mixins.json new file mode 100644 index 000000000..6543d90d8 --- /dev/null +++ b/libraries/effects/effects-mc15w31a-mc18w31a/src/main/resources/osl.effects.mixins.json @@ -0,0 +1,17 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.effects.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.conditionalmixin.mixin.ConditionalMixinPlugin", + "mixins": [ + "common.StatusEffectMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/build.gradle b/libraries/effects/effects-mc18w32a-mc1.13.2/build.gradle new file mode 100644 index 000000000..0a350fdb3 --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/gradle.properties b/libraries/effects/effects-mc18w32a-mc1.13.2/gradle.properties new file mode 100644 index 000000000..1a4324eff --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 18w32a +max_mc_version = 1.13.2 + +minecraft_version = 1.13.2 diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java new file mode 100644 index 000000000..c56c5bfdf --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the status effects lifecycle. + */ +public final class StatusEffectEvents { + + /** + * This event is invoked upon game start-up, after Vanilla effect registration is finished. + * + *

+ * Custom effect registration should be done in a listener of this event. + * Helper methods for registering effects can be found in the {@linkplain + * StatusEffectRegistry} class. + * + *

+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *

+	 * {@code
+	 * StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(() -> {
+	 * 	StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect());
+	 * });
+	 * }
+	 * 
+ * + * @see StatusEffectRegistry + */ + public static final Event REGISTER_STATUS_EFFECTS = Event.runnable(); + +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java new file mode 100644 index 000000000..66a9b8281 --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java @@ -0,0 +1,94 @@ +package net.ornithemc.osl.effects.api; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the StatusEffects registry. + */ +public final class StatusEffectRegistry { + + public static final Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given effect. + */ + public static int getId(StatusEffect effect) { + return StatusEffectRegistryImpl.getId(effect); + } + + /** + * @return the namespaced ID assigned to the given effect. + */ + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return StatusEffectRegistryImpl.getIdentifier(effect); + } + + /** + * @return the resource key assigned to the given effect. + */ + public static ResourceKey getKey(StatusEffect effect) { + return StatusEffectRegistryImpl.getKey(effect); + } + + /** + * @return the effect mapped to the given numerical ID. + */ + public static StatusEffect getStatusEffect(int id) { + return StatusEffectRegistryImpl.getStatusEffect(id); + } + + /** + * @return the effect mapped to the given namespaced ID. + */ + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return StatusEffectRegistryImpl.getStatusEffect(identifier); + } + + /** + * @return the effect mapped to the given resource key. + */ + public static StatusEffect getStatusEffect(ResourceKey key) { + return StatusEffectRegistryImpl.getStatusEffect(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return StatusEffectRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set> keySet() { + return StatusEffectRegistryImpl.keySet(); + } + + /** + * @param the effect type. + * @param identifier the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(NamespacedIdentifier identifier, T effect) { + return StatusEffectRegistryImpl.register(identifier, effect); + } + + /** + * @param the effect type. + * @param key the resource key of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(ResourceKey key, T effect) { + return StatusEffectRegistryImpl.register(key, effect); + } +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java new file mode 100644 index 000000000..0ffd88e77 --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.effects.impl; + +import net.ornithemc.osl.registries.api.RegistryEvents; + +public final class EffectsInit { + + public static void init() { + RegistryEvents.INIT_REGISTRIES.register(StatusEffectRegistryImpl::init); + } +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java new file mode 100644 index 000000000..6f472b5ad --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.effects.impl; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.impl.registry.VanillaRegistries; + +public final class StatusEffectRegistryImpl { + + public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.STATUS_EFFECT, net.minecraft.util.registry.Registry.STATUS_EFFECT); + + private static boolean locked = true; + + public static int getId(StatusEffect effect) { + return REGISTRY.getId(effect); + } + + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return REGISTRY.getIdentifier(effect); + } + + public static ResourceKey getKey(StatusEffect effect) { + return REGISTRY.getKey(effect); + } + + public static StatusEffect getStatusEffect(int id) { + return REGISTRY.get(id); + } + + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static StatusEffect getStatusEffect(ResourceKey key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set> keySet() { + return REGISTRY.keySet(); + } + + public static T register(NamespacedIdentifier identifier, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, effect); + } + } + + public static T register(ResourceKey key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, effect); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.STATUS_EFFECT); + } + + public static void unlock() { + locked = false; + } + + public static void registerStatusEffects() { + StatusEffectEvents.REGISTER_STATUS_EFFECTS.invoker().run(); + } +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java new file mode 100644 index 000000000..892374b56 --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; + +@Mixin(StatusEffect.class) +public class StatusEffectMixin { + + @Inject( + method = "init", + at = @At( + value = "HEAD" + ) + ) + private static void osl$effects$unlockStatusEffectRegistry(CallbackInfo ci) { + StatusEffectRegistryImpl.unlock(); + } + + @Inject( + method = "init", + at = @At( + value = "TAIL" + ) + ) + private static void osl$effects$registerStatusEffects(CallbackInfo ci) { + StatusEffectRegistryImpl.registerStatusEffects(); + } +} diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..ab4f27ca4 --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "osl-effects", + "version": "0.1.0-alpha.1+mc18w32a-mc1.13.2", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.effects.impl.EffectsInit::init" + ] + }, + "mixins": [ + "osl.effects.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.13.1-alpha.18.32.a \u003c\u003d1.13.2", + "osl-core": "\u003e\u003d0.11.0", + "osl-entrypoints": "\u003e\u003d0.5.0", + "osl-lifecycle-events": "\u003e\u003d0.6.0", + "osl-executors": "\u003e\u003d0.1.0", + "osl-text-components": "\u003e\u003d0.1.0", + "osl-networking": "\u003e\u003d0.12.1", + "osl-registries": "\u003e\u003d0.4.0" + }, + "name": "OSL Effects", + "description": "Effects API and events.", + "authors": [ + "OrnitheMC" + ], + "contact": { + "homepage": "https://ornithemc.net/", + "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues", + "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/osl.effects.mixins.json b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/osl.effects.mixins.json new file mode 100644 index 000000000..e107d62be --- /dev/null +++ b/libraries/effects/effects-mc18w32a-mc1.13.2/src/main/resources/osl.effects.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.effects.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.StatusEffectMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/build.gradle b/libraries/effects/effects-mc18w43a-mc1.14.4/build.gradle new file mode 100644 index 000000000..0a350fdb3 --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/gradle.properties b/libraries/effects/effects-mc18w43a-mc1.14.4/gradle.properties new file mode 100644 index 000000000..54620cacd --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 18w43a +max_mc_version = 1.14.4 + +minecraft_version = 1.14.4 diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java new file mode 100644 index 000000000..c56c5bfdf --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the status effects lifecycle. + */ +public final class StatusEffectEvents { + + /** + * This event is invoked upon game start-up, after Vanilla effect registration is finished. + * + *

+ * Custom effect registration should be done in a listener of this event. + * Helper methods for registering effects can be found in the {@linkplain + * StatusEffectRegistry} class. + * + *

+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *

+	 * {@code
+	 * StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(() -> {
+	 * 	StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect());
+	 * });
+	 * }
+	 * 
+ * + * @see StatusEffectRegistry + */ + public static final Event REGISTER_STATUS_EFFECTS = Event.runnable(); + +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java new file mode 100644 index 000000000..66a9b8281 --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java @@ -0,0 +1,94 @@ +package net.ornithemc.osl.effects.api; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the StatusEffects registry. + */ +public final class StatusEffectRegistry { + + public static final Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given effect. + */ + public static int getId(StatusEffect effect) { + return StatusEffectRegistryImpl.getId(effect); + } + + /** + * @return the namespaced ID assigned to the given effect. + */ + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return StatusEffectRegistryImpl.getIdentifier(effect); + } + + /** + * @return the resource key assigned to the given effect. + */ + public static ResourceKey getKey(StatusEffect effect) { + return StatusEffectRegistryImpl.getKey(effect); + } + + /** + * @return the effect mapped to the given numerical ID. + */ + public static StatusEffect getStatusEffect(int id) { + return StatusEffectRegistryImpl.getStatusEffect(id); + } + + /** + * @return the effect mapped to the given namespaced ID. + */ + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return StatusEffectRegistryImpl.getStatusEffect(identifier); + } + + /** + * @return the effect mapped to the given resource key. + */ + public static StatusEffect getStatusEffect(ResourceKey key) { + return StatusEffectRegistryImpl.getStatusEffect(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return StatusEffectRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set> keySet() { + return StatusEffectRegistryImpl.keySet(); + } + + /** + * @param the effect type. + * @param identifier the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(NamespacedIdentifier identifier, T effect) { + return StatusEffectRegistryImpl.register(identifier, effect); + } + + /** + * @param the effect type. + * @param key the resource key of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(ResourceKey key, T effect) { + return StatusEffectRegistryImpl.register(key, effect); + } +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java new file mode 100644 index 000000000..0ffd88e77 --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.effects.impl; + +import net.ornithemc.osl.registries.api.RegistryEvents; + +public final class EffectsInit { + + public static void init() { + RegistryEvents.INIT_REGISTRIES.register(StatusEffectRegistryImpl::init); + } +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java new file mode 100644 index 000000000..6f472b5ad --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.effects.impl; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.impl.registry.VanillaRegistries; + +public final class StatusEffectRegistryImpl { + + public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.STATUS_EFFECT, net.minecraft.util.registry.Registry.STATUS_EFFECT); + + private static boolean locked = true; + + public static int getId(StatusEffect effect) { + return REGISTRY.getId(effect); + } + + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return REGISTRY.getIdentifier(effect); + } + + public static ResourceKey getKey(StatusEffect effect) { + return REGISTRY.getKey(effect); + } + + public static StatusEffect getStatusEffect(int id) { + return REGISTRY.get(id); + } + + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static StatusEffect getStatusEffect(ResourceKey key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set> keySet() { + return REGISTRY.keySet(); + } + + public static T register(NamespacedIdentifier identifier, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, effect); + } + } + + public static T register(ResourceKey key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, effect); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.STATUS_EFFECT); + } + + public static void unlock() { + locked = false; + } + + public static void registerStatusEffects() { + StatusEffectEvents.REGISTER_STATUS_EFFECTS.invoker().run(); + } +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectsMixin.java b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectsMixin.java new file mode 100644 index 000000000..ba73a8e24 --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectsMixin.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.living.effect.StatusEffects; + +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; + +@Mixin(StatusEffects.class) +public class StatusEffectsMixin { + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$effects$unlockStatusEffectRegistry(CallbackInfo ci) { + StatusEffectRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$effects$registerStatusEffects(CallbackInfo ci) { + StatusEffectRegistryImpl.registerStatusEffects(); + } +} diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..316941c46 --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json @@ -0,0 +1,36 @@ +{ + "schemaVersion": 1, + "id": "osl-effects", + "version": "0.1.0-alpha.1+mc18w43a-mc1.14.4", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.effects.impl.EffectsInit::init" + ] + }, + "mixins": [ + "osl.effects.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.14-alpha.18.43.a \u003c\u003d1.14.4", + "osl-core": "\u003e\u003d0.11.0", + "osl-entrypoints": "\u003e\u003d0.5.0", + "osl-lifecycle-events": "\u003e\u003d0.6.0", + "osl-executors": "\u003e\u003d0.1.0", + "osl-text-components": "\u003e\u003d0.1.0", + "osl-networking": "\u003e\u003d0.12.1", + "osl-registries": "\u003e\u003d0.4.0" + }, + "name": "OSL Effects", + "description": "Effects API and events.", + "authors": [ + "OrnitheMC" + ], + "contact": { + "homepage": "https://ornithemc.net/", + "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues", + "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/osl.effects.mixins.json b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/osl.effects.mixins.json new file mode 100644 index 000000000..67829928e --- /dev/null +++ b/libraries/effects/effects-mc18w43a-mc1.14.4/src/main/resources/osl.effects.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.effects.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.StatusEffectsMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/build.gradle b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/build.gradle new file mode 100644 index 000000000..0a350fdb3 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/gradle.properties b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/gradle.properties new file mode 100644 index 000000000..25e0323c6 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/gradle.properties @@ -0,0 +1,7 @@ +min_mc_version = b1.8-pre1 +max_mc_version = 14w27b + +minecraft_version = 1.7.2 +raven_build = 1 +sparrow_build = 1 +nests_build = 3 diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java new file mode 100644 index 000000000..ee1cbc49a --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.effects.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the status effects lifecycle. + */ +public final class StatusEffectEvents { + + /** + * This event is invoked upon game start-up, after Vanilla effect registration is finished. + * + *

+ * Custom effect registration should be done in a listener of this event. + * Helper methods for registering effects can be found in the {@linkplain + * StatusEffectRegistry} class. + * + *

+ * Listeners to this event should be registered in your mod's entrypoint, + * and can be done as follows: + * + *

+	 * {@code
+	 * StatusEffectEvents.REGISTER_STATUS_EFFECTS.register(() -> {
+	 * 	StatusEffectRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieStatusEffect(StatusEffect.AUTO_ASSIGN_ID));
+	 * });
+	 * }
+	 * 
+ * + * @see StatusEffectRegistry + */ + public static final Event REGISTER_STATUS_EFFECTS = Event.runnable(); + +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java new file mode 100644 index 000000000..7b7cf43c2 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/StatusEffectRegistry.java @@ -0,0 +1,109 @@ +package net.ornithemc.osl.effects.api; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the StatusEffects registry. + */ +public final class StatusEffectRegistry { + + public static final Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given effect. + */ + public static int getId(StatusEffect effect) { + return StatusEffectRegistryImpl.getId(effect); + } + + /** + * @return the namespaced ID assigned to the given effect. + */ + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return StatusEffectRegistryImpl.getIdentifier(effect); + } + + /** + * @return the resource key assigned to the given effect. + */ + public static ResourceKey getKey(StatusEffect effect) { + return StatusEffectRegistryImpl.getKey(effect); + } + + /** + * @return the effect mapped to the given numerical ID. + */ + public static StatusEffect getStatusEffect(int id) { + return StatusEffectRegistryImpl.getStatusEffect(id); + } + + /** + * @return the effect mapped to the given namespaced ID. + */ + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return StatusEffectRegistryImpl.getStatusEffect(identifier); + } + + /** + * @return the effect mapped to the given resource key. + */ + public static StatusEffect getStatusEffect(ResourceKey key) { + return StatusEffectRegistryImpl.getStatusEffect(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return StatusEffectRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set> keySet() { + return StatusEffectRegistryImpl.keySet(); + } + + /** + * @param the effect type. + * @param identifier the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(NamespacedIdentifier identifier, T effect) { + return StatusEffectRegistryImpl.register(identifier, effect); + } + + /** + * @param the effect type. + * @param key the resource key of the effect. + * @param effect the effect to register. + * @return the registered effect. + */ + public static T register(ResourceKey key, T effect) { + return StatusEffectRegistryImpl.register(key, effect); + } + + /** + * @param the effect type. + * @param id the numerical ID of the effect. + * @param key the namespaced ID of the effect. + * @param effect the effect to register. + * @return the registered effect. + * + * @deprecated use {@linkplain #register(NamespacedIdentifier, StatusEffect)} + * or {@linkplain #register(ResourceKey, StatusEffect)} instead. + */ + @Deprecated + public static T register(int id, NamespacedIdentifier key, T effect) { + return StatusEffectRegistryImpl.register(id, key, effect); + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java new file mode 100644 index 000000000..e8fdd9719 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/api/effect/StatusEffectExtension.java @@ -0,0 +1,12 @@ +package net.ornithemc.osl.effects.api.effect; + +import net.minecraft.entity.living.effect.StatusEffect; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; + +public interface StatusEffectExtension { + + Registry REGISTRY = StatusEffectRegistryImpl.REGISTRY; + int AUTO_ASSIGN_ID = -172; + +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java new file mode 100644 index 000000000..0ffd88e77 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/EffectsInit.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.effects.impl; + +import net.ornithemc.osl.registries.api.RegistryEvents; + +public final class EffectsInit { + + public static void init() { + RegistryEvents.INIT_REGISTRIES.register(StatusEffectRegistryImpl::init); + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java new file mode 100644 index 000000000..4cc03bae3 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/StatusEffectRegistryImpl.java @@ -0,0 +1,111 @@ +package net.ornithemc.osl.effects.impl; + +import java.util.Set; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.effects.api.StatusEffectEvents; +import net.ornithemc.osl.effects.impl.effect.StatusEffectIdFixer; +import net.ornithemc.osl.registries.api.registry.Registries; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.ResourceKey; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.impl.registry.RegistriesImpl; + +public final class StatusEffectRegistryImpl { + + public static final Registry REGISTRY = Registries.registerSimple(RegistryKeys.STATUS_EFFECT, () -> StatusEffect.BY_ID.getClass()); + + private static boolean locked = true; + + public static int getId(StatusEffect effect) { + return REGISTRY.getId(effect); + } + + public static NamespacedIdentifier getIdentifier(StatusEffect effect) { + return REGISTRY.getIdentifier(effect); + } + + public static ResourceKey getKey(StatusEffect effect) { + return REGISTRY.getKey(effect); + } + + public static StatusEffect getStatusEffect(int id) { + return REGISTRY.get(id); + } + + public static StatusEffect getStatusEffect(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static StatusEffect getStatusEffect(ResourceKey key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set> keySet() { + return REGISTRY.keySet(); + } + + @SuppressWarnings("deprecation") + public static T register(NamespacedIdentifier identifier, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, effect.id, identifier, effect); + } + } + + @SuppressWarnings("deprecation") + public static T register(ResourceKey key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, effect.id, key, effect); + } + } + + @Deprecated + public static T register(int id, NamespacedIdentifier key, T effect) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + if (effect.id != id) { + throw new IllegalArgumentException("ID " + id + " does not match effect ID " + effect.id + " for " + key); + } + + return Registry.register(REGISTRY, id, key, effect); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.STATUS_EFFECT); + SyncedRegistries.registerFixer(RegistryKeys.STATUS_EFFECT, NamespacedIdentifiers.from("effect/id"), new StatusEffectIdFixer()); + } + + public static void unlock() { + locked = false; + } + + public static void registerStatusEffects() { + VanillaStatusEffects.init(); + StatusEffectEvents.REGISTER_STATUS_EFFECTS.invoker().run(); + } + + public static void registerUnknownStatusEffects() { + for (StatusEffect effect : StatusEffect.BY_ID) { + if (effect != null && REGISTRY.getIdentifier(effect) == null) { + NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "mob_effect_" + effect.id); + + RegistriesImpl.LOGGER.warn("StatusEffect {}/{}", effect.id, effect.getClass().getSimpleName() + " was not registered to OSL's StatusEffect registry! Adding it as '" + identifier + "'..."); + StatusEffectRegistryImpl.register(identifier, effect); + } + } + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java new file mode 100644 index 000000000..abd59783f --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/VanillaStatusEffects.java @@ -0,0 +1,75 @@ +package net.ornithemc.osl.effects.impl; + +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; + +public final class VanillaStatusEffects { + + /** + * Namespaced IDs were introduced in 14w28a. Before then, the numerical IDs + * were the only unique identifiers for status effects, and were still used + * until 1.9 . Here we assign namespaced IDs to pre-1.9 effects, matching + * the 1.9 IDs where possible. + */ + private static final String[] IDENTIFIERS = { + // grouped per 10 for easier lookup + + null, + "speed", + "slowness", + "haste", + "mining_fatigue", + "strength", + "instant_health", + "instant_damage", + "jump_boost", + "nausea", + + "regeneration", + "resistance", + "fire_resistance", + "water_breathing", + "invisibility", + "blindness", + "night_vision", + "hunger", + "weakness", + "poison", + + "wither", + "health_boost", + "absorption", + "saturation" + }; + + public static final int MAX_ID = 255; + + static void init() { + for (Field f : StatusEffect.class.getDeclaredFields()) { + if (Modifier.isStatic(f.getModifiers()) && StatusEffect.class.isAssignableFrom(f.getType())) { + try { + StatusEffect effect = (StatusEffect) f.get(null); + + if (effect != null) { + register(effect); + } + } catch (Throwable t) { + } + } + } + } + + private static void register(StatusEffect effect) { + if (effect.id >= 0 && effect.id < IDENTIFIERS.length) { + String identifier = IDENTIFIERS[effect.id]; + + if (identifier != null) { + StatusEffectRegistryImpl.register(NamespacedIdentifiers.from(identifier), effect); + } + } + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java new file mode 100644 index 000000000..ca6295cb6 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl.java @@ -0,0 +1,6 @@ +package net.ornithemc.osl.effects.impl.effect; + +import net.ornithemc.osl.effects.api.effect.StatusEffectExtension; + +public interface StatusEffectExtensionImpl extends StatusEffectExtension { +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java new file mode 100644 index 000000000..8443e23d6 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/effect/StatusEffectIdFixer.java @@ -0,0 +1,19 @@ +package net.ornithemc.osl.effects.impl.effect; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.osl.registries.api.registry.sync.IdFixer; + +public class StatusEffectIdFixer implements IdFixer { + + @Override + public void apply() { + for (int id = 0; id < StatusEffect.BY_ID.length; id++) { + StatusEffect effect = StatusEffect.BY_ID[id]; + + if (effect != null) { + effect.id = id; + } + } + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java new file mode 100644 index 000000000..9d4151f49 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/java/net/ornithemc/osl/effects/impl/mixin/common/StatusEffectMixin.java @@ -0,0 +1,145 @@ +package net.ornithemc.osl.effects.impl.mixin.common; + +import org.objectweb.asm.Opcodes; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import com.llamalad7.mixinextras.sugar.Local; + +import net.minecraft.entity.living.effect.StatusEffect; + +import net.ornithemc.conditionalmixin.annotations.Conditional; +import net.ornithemc.conditionalmixin.annotations.GameSide; +import net.ornithemc.conditionalmixin.annotations.Version; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.core.impl.util.Util; +import net.ornithemc.osl.effects.api.effect.StatusEffectExtension; +import net.ornithemc.osl.effects.impl.StatusEffectRegistryImpl; +import net.ornithemc.osl.effects.impl.VanillaStatusEffects; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.api.registry.sync.ArrayMapper; +import net.ornithemc.osl.registries.api.registry.sync.DynamicArray; + +@Mixin(StatusEffect.class) +public class StatusEffectMixin implements StatusEffectExtension { + + @Shadow @Final @Mutable + private static StatusEffect[] BY_ID; + + @Shadow + private String key; + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$effects$unlockStatusEffectRegistry(CallbackInfo ci) { + StatusEffectRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$effects$registerStatusEffectsAndArrayMappers1(CallbackInfo ci) { + StatusEffectRegistryImpl.registerStatusEffects(); + StatusEffectRegistryImpl.registerUnknownStatusEffects(); + + SyncedRegistries.registerMapper(RegistryKeys.STATUS_EFFECT, NamespacedIdentifiers.from("mob_effect/by_id"), ArrayMapper.of(() -> BY_ID, a -> BY_ID = a)); + } + + @ModifyVariable( + method = "", + argsOnly = true, + ordinal = 0, + at = @At( + value = "INVOKE", + target = "Ljava/lang/Object;()V", + shift = Shift.AFTER + ) + ) + private int osl$effects$handleAutoAssignId(int id) { + if (id == AUTO_ASSIGN_ID) { + // the StatusEffect[] array must contain all effects so this should + // give us a valid ID for the StatusEffect registry to use. + id = DynamicArray.length(BY_ID); + + // keep 0-255 free for all Vanilla effects + if (id <= VanillaStatusEffects.MAX_ID) { + id = VanillaStatusEffects.MAX_ID + 1; + } + } + + return id; + } + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/living/effect/StatusEffect;BY_ID:[Lnet/minecraft/entity/living/effect/StatusEffect;", + opcode = Opcodes.GETSTATIC, + args = "array=set" + ) + ) + private void osl$effects$growArrays(CallbackInfo ci, @Local(ordinal = 0) int id) { + int capacity = id + 1; + + BY_ID = DynamicArray.grow(BY_ID, capacity); + } + + @Conditional(minecraftVersion = { + @Version(value = ">=b1.9-pre3 <1.3.1", gameSide = GameSide.CLIENT), + @Version(value = ">=b1.9-pre4 <1.3.1", gameSide = GameSide.SERVER) + }) + @Inject( + method = "m_27822537", + at = @At( + value = "HEAD" + ) + ) + private void osl$effects$autoAssignTranslationKey1(CallbackInfoReturnable cir) { + this.autoAssignTranslationKey(); + } + + @Conditional(minecraftVersion = @Version(">=1.3.1")) + @Inject( + method = "getTranslationKey", + at = @At( + value = "HEAD" + ) + ) + private void osl$effects$autoAssignTranslationKey2(CallbackInfoReturnable cir) { + this.autoAssignTranslationKey(); + } + + @Unique + private void autoAssignTranslationKey() { + if (this.key == null) { + NamespacedIdentifier identifier = StatusEffectRegistryImpl.getIdentifier((StatusEffect) (Object) this); + + if (identifier == null) { + this.key = "potion.unknown"; + } else { + this.key = Util.makeTranslationKey("potion", identifier); + } + } + } +} diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/fabric.mod.json b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/fabric.mod.json new file mode 100644 index 000000000..1634ad99a --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-effects", + "version": "0.1.0-alpha.1+mcb1.8-pre1-mc14w27b", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.effects.impl.EffectsInit::init" + ] + }, + "mixins": [ + "osl.effects.mixins.json" + ], + "accessWidener": "osl.effects.classtweaker", + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.0.0-beta.8.0.1 \u003c\u003d1.8-alpha.14.27.b", + "osl-core": "\u003e\u003d0.11.0", + "osl-entrypoints": "\u003e\u003d0.5.0", + "osl-lifecycle-events": "\u003e\u003d0.6.0", + "osl-executors": "\u003e\u003d0.1.0", + "osl-text-components": "\u003e\u003d0.1.0", + "osl-networking": "\u003e\u003d0.12.1", + "osl-registries": "\u003e\u003d0.4.0" + }, + "name": "OSL Effects", + "description": "Effects API and events.", + "authors": [ + "OrnitheMC" + ], + "contact": { + "homepage": "https://ornithemc.net/", + "issues": "https://github.com/OrnitheMC/ornithe-standard-libraries/issues", + "sources": "https://github.com/OrnitheMC/ornithe-standard-libraries" + }, + "license": "Apache-2.0" +} \ No newline at end of file diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.classtweaker b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.classtweaker new file mode 100644 index 000000000..d16b0a900 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.classtweaker @@ -0,0 +1,6 @@ +classTweaker v1 named + +transitive-inject-interface net/minecraft/entity/living/effect/StatusEffect net/ornithemc/osl/effects/impl/effect/StatusEffectExtensionImpl + +mutable field net/minecraft/entity/living/effect/StatusEffect id I +accessible field net/minecraft/entity/living/effect/StatusEffect BY_ID [Lnet/minecraft/entity/living/effect/StatusEffect; diff --git a/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.mixins.json b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.mixins.json new file mode 100644 index 000000000..6543d90d8 --- /dev/null +++ b/libraries/effects/effects-mcb1.8-pre1-mc14w27b/src/main/resources/osl.effects.mixins.json @@ -0,0 +1,17 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.effects.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.conditionalmixin.mixin.ConditionalMixinPlugin", + "mixins": [ + "common.StatusEffectMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/effects/gradle.properties b/libraries/effects/gradle.properties new file mode 100644 index 000000000..40b3c45da --- /dev/null +++ b/libraries/effects/gradle.properties @@ -0,0 +1,7 @@ +library_id = effects +library_name = Effects +library_description = Effects API and events. +library_version = 0.1.0-alpha.1 + +entrypoint_init = net.ornithemc.osl.effects.impl.EffectsInit::init +osl_dependencies = core:0.9.0,entrypoints:0.5.0,registries:0.4.0 diff --git a/settings.gradle b/settings.gradle index fc0266334..aa6849b8c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -92,6 +92,13 @@ include ':libraries:crash-reports:crash-reports-mca1.0.1_01-mc1.2.5' include ':libraries:crash-reports:crash-reports-mc12w15a-mc1.4.2' include ':libraries:crash-reports:crash-reports-mc1.4.3-mc1.14.4' +include ':libraries:effects' +include ':libraries:effects:effects-mcb1.8-pre1-mc14w27b' +include ':libraries:effects:effects-mc14w28a-mc1.8.9' +include ':libraries:effects:effects-mc15w31a-mc18w31a' +include ':libraries:effects:effects-mc18w32a-mc1.13.2' +include ':libraries:effects:effects-mc18w43a-mc1.14.4' + include ':libraries:enchantments' include ':libraries:enchantments:enchantments-mcb1.9-pre4-mc14w27b' include ':libraries:enchantments:enchantments-mc14w28a-mc1.8.9'