diff --git a/libraries/enchantments/README.md b/libraries/enchantments/README.md
new file mode 100644
index 000000000..c3b502d61
--- /dev/null
+++ b/libraries/enchantments/README.md
@@ -0,0 +1,41 @@
+# Enchantments API
+
+The Enchantments API provides events and utilities for registering and working with enchantments.
+
+## Registering Custom Enchantments
+
+Enchantment registration should be done in a listener to the `REGISTER_ENCHANTMENTS` event. The `EnchantmentRegistry` class provides utility methods for registering enchantments.
+
+An example is shown below.
+
+```java
+package com.example;
+
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+import net.ornithemc.osl.entrypoints.api.ModInitializer;
+
+public class ExampleInitializer implements ModInitializer {
+
+ @Override
+ public void init() {
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.register(ExampleEnchantments::init);
+ }
+}
+```
+
+```java
+package com.example;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.util.NamespacedIdentifiers;
+import net.ornithemc.osl.enchantments.api.EnchantmentRegistry;
+
+public final class ExampleEnchantments {
+
+ public static final CookieEnchantment COOKIE = EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment());
+
+ public static void init() {
+ }
+}
+```
diff --git a/libraries/enchantments/build.gradle b/libraries/enchantments/build.gradle
new file mode 100644
index 000000000..e98ba2c6a
--- /dev/null
+++ b/libraries/enchantments/build.gradle
@@ -0,0 +1 @@
+setUpLibrary(project)
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/build.gradle b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/gradle.properties b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/gradle.properties
new file mode 100644
index 000000000..79564e3a4
--- /dev/null
+++ b/libraries/enchantments/enchantments-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/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
new file mode 100644
index 000000000..4c769939d
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the enchantments lifecycle.
+ */
+public final class EnchantmentEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla enchantment registration is finished.
+ *
+ *
+ * Custom enchantment registration should be done in a listener of this event.
+ * Helper methods for registering enchantments can be found in the {@linkplain
+ * EnchantmentRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * EnchantmentEvents.REGISTER_ENCHANTMENTS.register(() -> {
+ * EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment(Enchantment.AUTO_ASSIGN_ID));
+ * });
+ * }
+ *
+ *
+ * @see EnchantmentRegistry
+ */
+ public static final Event REGISTER_ENCHANTMENTS = Event.runnable();
+
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
new file mode 100644
index 000000000..d744cf7e8
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
@@ -0,0 +1,109 @@
+package net.ornithemc.osl.enchantments.api;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Enchantments registry.
+ */
+public final class EnchantmentRegistry {
+
+ public static final Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given enchantment.
+ */
+ public static int getId(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getId(enchantment);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given enchantment.
+ */
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getIdentifier(enchantment);
+ }
+
+ /**
+ * @return the resource key assigned to the given enchantment.
+ */
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getKey(enchantment);
+ }
+
+ /**
+ * @return the enchantment mapped to the given numerical ID.
+ */
+ public static Enchantment getEnchantment(int id) {
+ return EnchantmentRegistryImpl.getEnchantment(id);
+ }
+
+ /**
+ * @return the enchantment mapped to the given namespaced ID.
+ */
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return EnchantmentRegistryImpl.getEnchantment(identifier);
+ }
+
+ /**
+ * @return the enchantment mapped to the given resource key.
+ */
+ public static Enchantment getEnchantment(ResourceKey key) {
+ return EnchantmentRegistryImpl.getEnchantment(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return EnchantmentRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return EnchantmentRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param identifier the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(NamespacedIdentifier identifier, T enchantment) {
+ return EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param key the resource key of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(ResourceKey key, T enchantment) {
+ return EnchantmentRegistryImpl.register(key, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param id the numerical ID of the enchantment.
+ * @param key the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Enchantment)}
+ * or {@linkplain #register(ResourceKey, Enchantment)} instead.
+ */
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T enchantment) {
+ return EnchantmentRegistryImpl.register(id, key, enchantment);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java
new file mode 100644
index 000000000..e11f62fd4
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java
@@ -0,0 +1,16 @@
+package net.ornithemc.osl.enchantments.api.enchantment;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+
+public interface EnchantmentExtension {
+
+ Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+ int AUTO_ASSIGN_ID = -172;
+ NamespacedIdentifier PLACEHOLDER_NAMESPACED_ID = NamespacedIdentifiers.from("osl", "placeholder");
+
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
new file mode 100644
index 000000000..6382ad9d4
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
@@ -0,0 +1,110 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+import net.ornithemc.osl.enchantments.impl.enchantment.EnchantmentIdFixer;
+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 EnchantmentRegistryImpl {
+
+ public static final Registry REGISTRY = RegistriesImpl.register(RegistryKeys.ENCHANTMENT, new WrappedEnchantmentRegistry(RegistryKeys.ENCHANTMENT.identifier()), () -> Enchantment.BY_ID.getClass());
+
+ private static boolean locked = true;
+
+ public static int getId(Enchantment enchantment) {
+ return REGISTRY.getId(enchantment);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return REGISTRY.getIdentifier(enchantment);
+ }
+
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return REGISTRY.getKey(enchantment);
+ }
+
+ public static Enchantment getEnchantment(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Enchantment getEnchantment(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 enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, enchantment.id, identifier, enchantment);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public static T register(ResourceKey key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, enchantment.id, key, enchantment);
+ }
+ }
+
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ if (enchantment.id != id) {
+ throw new IllegalArgumentException("ID " + id + " does not match enchantment ID " + enchantment.id + " for " + key);
+ }
+
+ return Registry.register(REGISTRY, id, key, enchantment);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ENCHANTMENT);
+ SyncedRegistries.registerFixer(RegistryKeys.ENCHANTMENT, NamespacedIdentifiers.from("enchantment/id"), new EnchantmentIdFixer());
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerEnchantments() {
+ VanillaEnchantments.init();
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.invoker().run();
+ }
+
+ public static void registerUnknownEnchantments() {
+ for (Enchantment enchantment : Enchantment.BY_ID) {
+ if (enchantment != null && REGISTRY.getIdentifier(enchantment) == null) {
+ NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "enchantment_" + enchantment.id);
+
+ RegistriesImpl.LOGGER.warn("Enchantment {}/{}", enchantment.id, enchantment.getClass().getSimpleName() + " was not registered to OSL's Enchantment registry! Adding it as '" + identifier + "'...");
+ EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
new file mode 100644
index 000000000..7c84f6e7b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.ornithemc.osl.registries.api.RegistryEvents;
+
+public final class EnchantmentsInit {
+
+ public static void init() {
+ RegistryEvents.INIT_REGISTRIES.register(EnchantmentRegistryImpl::init);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java
new file mode 100644
index 000000000..75659ac8d
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java
@@ -0,0 +1,118 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+
+public final class VanillaEnchantments {
+
+ /**
+ * Namespaced IDs were introduced in 14w28a. Before then, the numerical IDs
+ * were the only unique identifiers for enchantments, and were still used
+ * until 1.9 . Here we assign namespaced IDs to pre-1.9 enchantments, matching
+ * the 1.9 IDs where possible.
+ */
+ private static final String[] IDENTIFIERS = {
+ // grouped per 10 for easier lookup
+
+ "protection",
+ "fire_protection",
+ "feather_falling",
+ "blast_protection",
+ "projectile_protection",
+ "respiration",
+ "aqua_affinity",
+ "thorns",
+ "depth_strider",
+ null,
+
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "sharpness",
+ "smite",
+ "bane_of_arthropods",
+ "knockback",
+
+ "fire_aspect",
+ "looting",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ null,
+ "efficiency",
+ "silk_touch",
+ "unbreaking",
+ "fortune",
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "power",
+ "punch",
+
+ "flame",
+ "infinity",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ "luck_of_the_sea",
+ "lure"
+ };
+
+ public static final int MAX_ID = 255;
+
+ static void init() {
+ for (Field f : Enchantment.class.getDeclaredFields()) {
+ if (Modifier.isStatic(f.getModifiers()) && Enchantment.class.isAssignableFrom(f.getType())) {
+ try {
+ Enchantment enchantment = (Enchantment) f.get(null);
+
+ if (enchantment != null) {
+ register(enchantment);
+ }
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ private static void register(Enchantment enchantment) {
+ if (enchantment.id >= 0 && enchantment.id < IDENTIFIERS.length) {
+ String identifier = IDENTIFIERS[enchantment.id];
+
+ if (identifier != null) {
+ EnchantmentRegistryImpl.register(NamespacedIdentifiers.from(identifier), enchantment);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/WrappedEnchantmentRegistry.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/WrappedEnchantmentRegistry.java
new file mode 100644
index 000000000..543fa939b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/WrappedEnchantmentRegistry.java
@@ -0,0 +1,50 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.minecraft.enchantment.Enchantment;
+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 WrappedEnchantmentRegistry extends SimpleRegistry {
+
+ private boolean skipEnchantmentRegister;
+
+ WrappedEnchantmentRegistry(NamespacedIdentifier identifier) {
+ super(identifier);
+ }
+
+ public void register(int id, NamespacedIdentifier identifier, Enchantment enchantment) {
+ ResourceKey key = ResourceKeys.from(this.identifier(), identifier);
+
+ this.skipEnchantmentRegister = true;
+ this.register(id, key, enchantment);
+ this.skipEnchantmentRegister = false;
+ }
+
+ @Override
+ public V register(int id, ResourceKey key, V enchantment) {
+ enchantment = super.register(id, key, enchantment);
+
+ if (!this.skipEnchantmentRegister) {
+ Identifier identifier = new Identifier(key.identifier().namespace(), key.identifier().identifier());
+
+ if (Enchantment.BY_KEY.containsKey(identifier)) {
+ throw new IllegalStateException("Duplicate Enchantment ID " + identifier);
+ }
+
+ Enchantment.BY_KEY.put(identifier, enchantment);
+ }
+
+ return enchantment;
+ }
+
+ @Override
+ public void clear() {
+ super.clear();
+
+ Enchantment.BY_KEY.clear();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java
new file mode 100644
index 000000000..c9fcc9697
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java
@@ -0,0 +1,6 @@
+package net.ornithemc.osl.enchantments.impl.enchantment;
+
+import net.ornithemc.osl.enchantments.api.enchantment.EnchantmentExtension;
+
+public interface EnchantmentExtensionImpl extends EnchantmentExtension {
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java
new file mode 100644
index 000000000..6c5f9eee1
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java
@@ -0,0 +1,19 @@
+package net.ornithemc.osl.enchantments.impl.enchantment;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+
+public class EnchantmentIdFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ for (int id = 0; id < Enchantment.BY_ID.length; id++) {
+ Enchantment enchantment = Enchantment.BY_ID[id];
+
+ if (enchantment != null) {
+ enchantment.id = id;
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
new file mode 100644
index 000000000..bfc8013f5
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
@@ -0,0 +1,142 @@
+package net.ornithemc.osl.enchantments.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.enchantment.Enchantment;
+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.enchantments.api.enchantment.EnchantmentExtension;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.enchantments.impl.VanillaEnchantments;
+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(Enchantment.class)
+public class EnchantmentMixin implements EnchantmentExtension {
+
+ @Shadow @Final @Mutable
+ private static Enchantment[] BY_ID;
+
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$enchantments$unlockEnchantmentRegistry(CallbackInfo ci) {
+ EnchantmentRegistryImpl.unlock();
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/enchantment/Enchantment;BY_ID:[Lnet/minecraft/enchantment/Enchantment;",
+ opcode = Opcodes.GETSTATIC
+ )
+ )
+ private static void osl$enchantments$registerEnchantmentsAndArrayMappers(CallbackInfo ci) {
+ EnchantmentRegistryImpl.registerEnchantments();
+ EnchantmentRegistryImpl.registerUnknownEnchantments();
+
+ SyncedRegistries.registerMapper(RegistryKeys.ENCHANTMENT, NamespacedIdentifiers.from("enchantment/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$enchantments$handleAutoAssignId(int id) {
+ if (id == AUTO_ASSIGN_ID) {
+ // the Enchantment[] array must contain all enchantments so this should
+ // give us a valid ID for the Enchantment registry to use.
+ id = DynamicArray.length(BY_ID);
+
+ // keep 0-255 free for all Vanilla enchantments
+ if (id <= VanillaEnchantments.MAX_ID) {
+ id = VanillaEnchantments.MAX_ID + 1;
+ }
+ }
+
+ return id;
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/enchantment/Enchantment;BY_ID:[Lnet/minecraft/enchantment/Enchantment;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$enchantments$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$enchantments$cancelPlaceholderNamespacedId(Map BY_KEY, Object key, Object enchantment, Operation op) {
+ if (key == PLACEHOLDER_NAMESPACED_ID) {
+ return null;
+ } else {
+ return op.call(BY_KEY, key, enchantment);
+ }
+ }
+
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$enchantments$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = EnchantmentRegistryImpl.getIdentifier((Enchantment) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..bfc240e54
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/fabric.mod.json
@@ -0,0 +1,37 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-enchantments",
+ "version": "0.1.0-alpha.1+mc14w28a-mc1.8.9",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init"
+ ]
+ },
+ "mixins": [
+ "osl.enchantments.mixins.json"
+ ],
+ "accessWidener": "osl.enchantments.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 Enchantments",
+ "description": "Enchantments 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/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.classtweaker b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.classtweaker
new file mode 100644
index 000000000..5a0e6ba99
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.classtweaker
@@ -0,0 +1,7 @@
+classTweaker v1 named
+
+transitive-inject-interface net/minecraft/enchantment/Enchantment net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl
+
+mutable field net/minecraft/enchantment/Enchantment id I
+accessible field net/minecraft/enchantment/Enchantment BY_ID [Lnet/minecraft/enchantment/Enchantment;
+accessible field net/minecraft/enchantment/Enchantment BY_KEY Ljava/util/Map;
diff --git a/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.mixins.json b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.mixins.json
new file mode 100644
index 000000000..543ac20f9
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc14w28a-mc1.8.9/src/main/resources/osl.enchantments.mixins.json
@@ -0,0 +1,16 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.enchantments.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "mixins": [
+ "common.EnchantmentMixin"
+ ],
+ "client": [
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/build.gradle b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/gradle.properties b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/gradle.properties
new file mode 100644
index 000000000..86cd93600
--- /dev/null
+++ b/libraries/enchantments/enchantments-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/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
new file mode 100644
index 000000000..58469a3bc
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the enchantments lifecycle.
+ */
+public final class EnchantmentEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla enchantment registration is finished.
+ *
+ *
+ * Custom enchantment registration should be done in a listener of this event.
+ * Helper methods for registering enchantments can be found in the {@linkplain
+ * EnchantmentRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * EnchantmentEvents.REGISTER_ENCHANTMENTS.register(() -> {
+ * EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment());
+ * });
+ * }
+ *
+ *
+ * @see EnchantmentRegistry
+ */
+ public static final Event REGISTER_ENCHANTMENTS = Event.runnable();
+
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
new file mode 100644
index 000000000..5db083406
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
@@ -0,0 +1,94 @@
+package net.ornithemc.osl.enchantments.api;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Enchantments registry.
+ */
+public final class EnchantmentRegistry {
+
+ public static final Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given enchantment.
+ */
+ public static int getId(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getId(enchantment);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given enchantment.
+ */
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getIdentifier(enchantment);
+ }
+
+ /**
+ * @return the resource key assigned to the given enchantment.
+ */
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getKey(enchantment);
+ }
+
+ /**
+ * @return the enchantment mapped to the given numerical ID.
+ */
+ public static Enchantment getEnchantment(int id) {
+ return EnchantmentRegistryImpl.getEnchantment(id);
+ }
+
+ /**
+ * @return the enchantment mapped to the given namespaced ID.
+ */
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return EnchantmentRegistryImpl.getEnchantment(identifier);
+ }
+
+ /**
+ * @return the enchantment mapped to the given resource key.
+ */
+ public static Enchantment getEnchantment(ResourceKey key) {
+ return EnchantmentRegistryImpl.getEnchantment(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return EnchantmentRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return EnchantmentRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param identifier the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(NamespacedIdentifier identifier, T enchantment) {
+ return EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param key the resource key of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(ResourceKey key, T enchantment) {
+ return EnchantmentRegistryImpl.register(key, enchantment);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
new file mode 100644
index 000000000..9219e0d8b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
@@ -0,0 +1,80 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+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 EnchantmentRegistryImpl {
+
+ public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENCHANTMENT, Enchantment.REGISTRY);
+
+ private static boolean locked = true;
+
+ public static int getId(Enchantment enchantment) {
+ return REGISTRY.getId(enchantment);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return REGISTRY.getIdentifier(enchantment);
+ }
+
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return REGISTRY.getKey(enchantment);
+ }
+
+ public static Enchantment getEnchantment(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Enchantment getEnchantment(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 enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, enchantment);
+ }
+ }
+
+ public static T register(ResourceKey key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, enchantment);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ENCHANTMENT);
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerEnchantments() {
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.invoker().run();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
new file mode 100644
index 000000000..7c84f6e7b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.ornithemc.osl.registries.api.RegistryEvents;
+
+public final class EnchantmentsInit {
+
+ public static void init() {
+ RegistryEvents.INIT_REGISTRIES.register(EnchantmentRegistryImpl::init);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
new file mode 100644
index 000000000..c454bf1a4
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
@@ -0,0 +1,64 @@
+package net.ornithemc.osl.enchantments.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.enchantment.Enchantment;
+
+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.enchantments.impl.EnchantmentRegistryImpl;
+
+@Mixin(Enchantment.class)
+public class EnchantmentMixin {
+
+ @Conditional(minecraftVersion = @Version("<1.13-pre5"))
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$enchantments$unlockEnchantmentRegistry(CallbackInfo ci) {
+ EnchantmentRegistryImpl.unlock();
+ }
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$enchantments$registerEnchantments(CallbackInfo ci) {
+ EnchantmentRegistryImpl.registerEnchantments();
+ }
+
+ @Conditional(minecraftVersion = @Version("<1.13-pre5"))
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$enchantments$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = EnchantmentRegistryImpl.getIdentifier((Enchantment) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..b336cbb7e
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/fabric.mod.json
@@ -0,0 +1,36 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-enchantments",
+ "version": "0.1.0-alpha.1+mc15w31a-mc18w31a",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init"
+ ]
+ },
+ "mixins": [
+ "osl.enchantments.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 Enchantments",
+ "description": "Enchantments 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/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/osl.enchantments.mixins.json b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/osl.enchantments.mixins.json
new file mode 100644
index 000000000..d028375a8
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc15w31a-mc18w31a/src/main/resources/osl.enchantments.mixins.json
@@ -0,0 +1,17 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.enchantments.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "plugin": "net.ornithemc.conditionalmixin.mixin.ConditionalMixinPlugin",
+ "mixins": [
+ "common.EnchantmentMixin"
+ ],
+ "client": [
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/build.gradle b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/gradle.properties b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/gradle.properties
new file mode 100644
index 000000000..1a4324eff
--- /dev/null
+++ b/libraries/enchantments/enchantments-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/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
new file mode 100644
index 000000000..58469a3bc
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the enchantments lifecycle.
+ */
+public final class EnchantmentEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla enchantment registration is finished.
+ *
+ *
+ * Custom enchantment registration should be done in a listener of this event.
+ * Helper methods for registering enchantments can be found in the {@linkplain
+ * EnchantmentRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * EnchantmentEvents.REGISTER_ENCHANTMENTS.register(() -> {
+ * EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment());
+ * });
+ * }
+ *
+ *
+ * @see EnchantmentRegistry
+ */
+ public static final Event REGISTER_ENCHANTMENTS = Event.runnable();
+
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
new file mode 100644
index 000000000..29127bb8c
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
@@ -0,0 +1,94 @@
+package net.ornithemc.osl.enchantments.api;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Enchantments registry.
+ */
+public final class EnchantmentRegistry {
+
+ public static final Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given enchantment.
+ */
+ public static int getId(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getId(enchantment);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given enchantment.
+ */
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getIdentifier(enchantment);
+ }
+
+ /**
+ * @return the resource key assigned to the given enchantment.
+ */
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getKey(enchantment);
+ }
+
+ /**
+ * @return the enchantment mapped to the given numerical ID.
+ */
+ public static Enchantment getEnchantment(int id) {
+ return EnchantmentRegistryImpl.getEnchantment(id);
+ }
+
+ /**
+ * @return the enchantment mapped to the given namespaced ID.
+ */
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return EnchantmentRegistryImpl.getEnchantment(identifier);
+ }
+
+ /**
+ * @return the enchantment mapped to the given resource key.
+ */
+ public static Enchantment getEnchantment(ResourceKey key) {
+ return EnchantmentRegistryImpl.getEnchantment(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return EnchantmentRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return EnchantmentRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param identifier the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(NamespacedIdentifier identifier, T enchantment) {
+ return EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param key the resource key of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(ResourceKey key, T enchantment) {
+ return EnchantmentRegistryImpl.register(key, enchantment);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
new file mode 100644
index 000000000..988df5e14
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
@@ -0,0 +1,80 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+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 EnchantmentRegistryImpl {
+
+ public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENCHANTMENT, net.minecraft.util.registry.Registry.ENCHANTMENT);
+
+ private static boolean locked = true;
+
+ public static int getId(Enchantment enchantment) {
+ return REGISTRY.getId(enchantment);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return REGISTRY.getIdentifier(enchantment);
+ }
+
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return REGISTRY.getKey(enchantment);
+ }
+
+ public static Enchantment getEnchantment(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Enchantment getEnchantment(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 enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, enchantment);
+ }
+ }
+
+ public static T register(ResourceKey key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, enchantment);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ENCHANTMENT);
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerEnchantments() {
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.invoker().run();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
new file mode 100644
index 000000000..7c84f6e7b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.ornithemc.osl.registries.api.RegistryEvents;
+
+public final class EnchantmentsInit {
+
+ public static void init() {
+ RegistryEvents.INIT_REGISTRIES.register(EnchantmentRegistryImpl::init);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
new file mode 100644
index 000000000..5d800b3fb
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.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.enchantment.Enchantment;
+
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+
+@Mixin(Enchantment.class)
+public class EnchantmentMixin {
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$enchantments$unlockEnchantmentRegistry(CallbackInfo ci) {
+ EnchantmentRegistryImpl.unlock();
+ }
+
+ @Inject(
+ method = "init",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$enchantments$registerEnchantments(CallbackInfo ci) {
+ EnchantmentRegistryImpl.registerEnchantments();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..032530d6d
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/fabric.mod.json
@@ -0,0 +1,36 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-enchantments",
+ "version": "0.1.0-alpha.1+mc18w32a-mc1.13.2",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init"
+ ]
+ },
+ "mixins": [
+ "osl.enchantments.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 Enchantments",
+ "description": "Enchantments 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/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/osl.enchantments.mixins.json b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/osl.enchantments.mixins.json
new file mode 100644
index 000000000..543ac20f9
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w32a-mc1.13.2/src/main/resources/osl.enchantments.mixins.json
@@ -0,0 +1,16 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.enchantments.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "mixins": [
+ "common.EnchantmentMixin"
+ ],
+ "client": [
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/build.gradle b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/gradle.properties b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/gradle.properties
new file mode 100644
index 000000000..54620cacd
--- /dev/null
+++ b/libraries/enchantments/enchantments-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/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
new file mode 100644
index 000000000..58469a3bc
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the enchantments lifecycle.
+ */
+public final class EnchantmentEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla enchantment registration is finished.
+ *
+ *
+ * Custom enchantment registration should be done in a listener of this event.
+ * Helper methods for registering enchantments can be found in the {@linkplain
+ * EnchantmentRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * EnchantmentEvents.REGISTER_ENCHANTMENTS.register(() -> {
+ * EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment());
+ * });
+ * }
+ *
+ *
+ * @see EnchantmentRegistry
+ */
+ public static final Event REGISTER_ENCHANTMENTS = Event.runnable();
+
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
new file mode 100644
index 000000000..5db083406
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
@@ -0,0 +1,94 @@
+package net.ornithemc.osl.enchantments.api;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Enchantments registry.
+ */
+public final class EnchantmentRegistry {
+
+ public static final Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given enchantment.
+ */
+ public static int getId(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getId(enchantment);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given enchantment.
+ */
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getIdentifier(enchantment);
+ }
+
+ /**
+ * @return the resource key assigned to the given enchantment.
+ */
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getKey(enchantment);
+ }
+
+ /**
+ * @return the enchantment mapped to the given numerical ID.
+ */
+ public static Enchantment getEnchantment(int id) {
+ return EnchantmentRegistryImpl.getEnchantment(id);
+ }
+
+ /**
+ * @return the enchantment mapped to the given namespaced ID.
+ */
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return EnchantmentRegistryImpl.getEnchantment(identifier);
+ }
+
+ /**
+ * @return the enchantment mapped to the given resource key.
+ */
+ public static Enchantment getEnchantment(ResourceKey key) {
+ return EnchantmentRegistryImpl.getEnchantment(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return EnchantmentRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return EnchantmentRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param identifier the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(NamespacedIdentifier identifier, T enchantment) {
+ return EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param key the resource key of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(ResourceKey key, T enchantment) {
+ return EnchantmentRegistryImpl.register(key, enchantment);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
new file mode 100644
index 000000000..988df5e14
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
@@ -0,0 +1,80 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+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 EnchantmentRegistryImpl {
+
+ public static final Registry REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENCHANTMENT, net.minecraft.util.registry.Registry.ENCHANTMENT);
+
+ private static boolean locked = true;
+
+ public static int getId(Enchantment enchantment) {
+ return REGISTRY.getId(enchantment);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return REGISTRY.getIdentifier(enchantment);
+ }
+
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return REGISTRY.getKey(enchantment);
+ }
+
+ public static Enchantment getEnchantment(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Enchantment getEnchantment(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 enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, identifier, enchantment);
+ }
+ }
+
+ public static T register(ResourceKey key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, key, enchantment);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ENCHANTMENT);
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerEnchantments() {
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.invoker().run();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
new file mode 100644
index 000000000..7c84f6e7b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.ornithemc.osl.registries.api.RegistryEvents;
+
+public final class EnchantmentsInit {
+
+ public static void init() {
+ RegistryEvents.INIT_REGISTRIES.register(EnchantmentRegistryImpl::init);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentsMixin.java b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentsMixin.java
new file mode 100644
index 000000000..8541fddea
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentsMixin.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.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.enchantment.Enchantments;
+
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+
+@Mixin(Enchantments.class)
+public class EnchantmentsMixin {
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$enchantments$unlockEnchantmentRegistry(CallbackInfo ci) {
+ EnchantmentRegistryImpl.unlock();
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$enchantments$registerEnchantments(CallbackInfo ci) {
+ EnchantmentRegistryImpl.registerEnchantments();
+ }
+}
diff --git a/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..2fb25a5be
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/fabric.mod.json
@@ -0,0 +1,36 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-enchantments",
+ "version": "0.1.0-alpha.1+mc18w43a-mc1.14.4",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init"
+ ]
+ },
+ "mixins": [
+ "osl.enchantments.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 Enchantments",
+ "description": "Enchantments 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/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/osl.enchantments.mixins.json b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/osl.enchantments.mixins.json
new file mode 100644
index 000000000..ebfe9f1d1
--- /dev/null
+++ b/libraries/enchantments/enchantments-mc18w43a-mc1.14.4/src/main/resources/osl.enchantments.mixins.json
@@ -0,0 +1,16 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.enchantments.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "mixins": [
+ "common.EnchantmentsMixin"
+ ],
+ "client": [
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/build.gradle b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/build.gradle
new file mode 100644
index 000000000..0a350fdb3
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/build.gradle
@@ -0,0 +1 @@
+setUpModule(project)
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/gradle.properties b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/gradle.properties
new file mode 100644
index 000000000..aa32dc385
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/gradle.properties
@@ -0,0 +1,7 @@
+min_mc_version = b1.9-pre4
+max_mc_version = 14w27b
+
+minecraft_version = 1.7.2
+raven_build = 1
+sparrow_build = 1
+nests_build = 3
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
new file mode 100644
index 000000000..4c769939d
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentEvents.java
@@ -0,0 +1,34 @@
+package net.ornithemc.osl.enchantments.api;
+
+import net.ornithemc.osl.core.api.events.Event;
+
+/**
+ * Events related to the enchantments lifecycle.
+ */
+public final class EnchantmentEvents {
+
+ /**
+ * This event is invoked upon game start-up, after Vanilla enchantment registration is finished.
+ *
+ *
+ * Custom enchantment registration should be done in a listener of this event.
+ * Helper methods for registering enchantments can be found in the {@linkplain
+ * EnchantmentRegistry} class.
+ *
+ *
+ * Listeners to this event should be registered in your mod's entrypoint,
+ * and can be done as follows:
+ *
+ *
+ * {@code
+ * EnchantmentEvents.REGISTER_ENCHANTMENTS.register(() -> {
+ * EnchantmentRegistry.register(NamespacedIdentifiers.from("example", "cookie"), new CookieEnchantment(Enchantment.AUTO_ASSIGN_ID));
+ * });
+ * }
+ *
+ *
+ * @see EnchantmentRegistry
+ */
+ public static final Event REGISTER_ENCHANTMENTS = Event.runnable();
+
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
new file mode 100644
index 000000000..d744cf7e8
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/EnchantmentRegistry.java
@@ -0,0 +1,109 @@
+package net.ornithemc.osl.enchantments.api;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+import net.ornithemc.osl.registries.api.registry.ResourceKey;
+
+/**
+ * Public access to the Enchantments registry.
+ */
+public final class EnchantmentRegistry {
+
+ public static final Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+
+ /**
+ * @return the numerical ID assigned to the given enchantment.
+ */
+ public static int getId(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getId(enchantment);
+ }
+
+ /**
+ * @return the namespaced ID assigned to the given enchantment.
+ */
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getIdentifier(enchantment);
+ }
+
+ /**
+ * @return the resource key assigned to the given enchantment.
+ */
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return EnchantmentRegistryImpl.getKey(enchantment);
+ }
+
+ /**
+ * @return the enchantment mapped to the given numerical ID.
+ */
+ public static Enchantment getEnchantment(int id) {
+ return EnchantmentRegistryImpl.getEnchantment(id);
+ }
+
+ /**
+ * @return the enchantment mapped to the given namespaced ID.
+ */
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return EnchantmentRegistryImpl.getEnchantment(identifier);
+ }
+
+ /**
+ * @return the enchantment mapped to the given resource key.
+ */
+ public static Enchantment getEnchantment(ResourceKey key) {
+ return EnchantmentRegistryImpl.getEnchantment(key);
+ }
+
+ /**
+ * @return a set containing all namespaced IDs in the registry.
+ */
+ public static Set identifierSet() {
+ return EnchantmentRegistryImpl.identifierSet();
+ }
+
+ /**
+ * @return a set containing all resource keys in the registry.
+ */
+ public static Set> keySet() {
+ return EnchantmentRegistryImpl.keySet();
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param identifier the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(NamespacedIdentifier identifier, T enchantment) {
+ return EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param key the resource key of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ */
+ public static T register(ResourceKey key, T enchantment) {
+ return EnchantmentRegistryImpl.register(key, enchantment);
+ }
+
+ /**
+ * @param the enchantment type.
+ * @param id the numerical ID of the enchantment.
+ * @param key the namespaced ID of the enchantment.
+ * @param enchantment the enchantment to register.
+ * @return the registered enchantment.
+ *
+ * @deprecated use {@linkplain #register(NamespacedIdentifier, Enchantment)}
+ * or {@linkplain #register(ResourceKey, Enchantment)} instead.
+ */
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T enchantment) {
+ return EnchantmentRegistryImpl.register(id, key, enchantment);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java
new file mode 100644
index 000000000..ef219f7fd
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/api/enchantment/EnchantmentExtension.java
@@ -0,0 +1,13 @@
+package net.ornithemc.osl.enchantments.api.enchantment;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.registries.api.registry.Registry;
+
+public interface EnchantmentExtension {
+
+ Registry REGISTRY = EnchantmentRegistryImpl.REGISTRY;
+ int AUTO_ASSIGN_ID = -172;
+
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
new file mode 100644
index 000000000..c8d76fcbd
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentRegistryImpl.java
@@ -0,0 +1,111 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.util.Set;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifier;
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+import net.ornithemc.osl.enchantments.api.EnchantmentEvents;
+import net.ornithemc.osl.enchantments.impl.enchantment.EnchantmentIdFixer;
+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 EnchantmentRegistryImpl {
+
+ public static final Registry REGISTRY = Registries.registerSimple(RegistryKeys.ENCHANTMENT, () -> Enchantment.BY_ID.getClass());
+
+ private static boolean locked = true;
+
+ public static int getId(Enchantment enchantment) {
+ return REGISTRY.getId(enchantment);
+ }
+
+ public static NamespacedIdentifier getIdentifier(Enchantment enchantment) {
+ return REGISTRY.getIdentifier(enchantment);
+ }
+
+ public static ResourceKey getKey(Enchantment enchantment) {
+ return REGISTRY.getKey(enchantment);
+ }
+
+ public static Enchantment getEnchantment(int id) {
+ return REGISTRY.get(id);
+ }
+
+ public static Enchantment getEnchantment(NamespacedIdentifier identifier) {
+ return REGISTRY.get(identifier);
+ }
+
+ public static Enchantment getEnchantment(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 enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, enchantment.id, identifier, enchantment);
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public static T register(ResourceKey key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ return Registry.register(REGISTRY, enchantment.id, key, enchantment);
+ }
+ }
+
+ @Deprecated
+ public static T register(int id, NamespacedIdentifier key, T enchantment) {
+ if (locked) {
+ throw new IllegalStateException("register called too early: registry locked!");
+ } else {
+ if (enchantment.id != id) {
+ throw new IllegalArgumentException("ID " + id + " does not match enchantment ID " + enchantment.id + " for " + key);
+ }
+
+ return Registry.register(REGISTRY, id, key, enchantment);
+ }
+ }
+
+ public static void init() {
+ SyncedRegistries.register(RegistryKeys.ENCHANTMENT);
+ SyncedRegistries.registerFixer(RegistryKeys.ENCHANTMENT, NamespacedIdentifiers.from("enchantment/id"), new EnchantmentIdFixer());
+ }
+
+ public static void unlock() {
+ locked = false;
+ }
+
+ public static void registerEnchantments() {
+ VanillaEnchantments.init();
+ EnchantmentEvents.REGISTER_ENCHANTMENTS.invoker().run();
+ }
+
+ public static void registerUnknownEnchantments() {
+ for (Enchantment enchantment : Enchantment.BY_ID) {
+ if (enchantment != null && REGISTRY.getIdentifier(enchantment) == null) {
+ NamespacedIdentifier identifier = NamespacedIdentifiers.from("osl", "enchantment_" + enchantment.id);
+
+ RegistriesImpl.LOGGER.warn("Enchantment {}/{}", enchantment.id, enchantment.getClass().getSimpleName() + " was not registered to OSL's Enchantment registry! Adding it as '" + identifier + "'...");
+ EnchantmentRegistryImpl.register(identifier, enchantment);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
new file mode 100644
index 000000000..7c84f6e7b
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/EnchantmentsInit.java
@@ -0,0 +1,10 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import net.ornithemc.osl.registries.api.RegistryEvents;
+
+public final class EnchantmentsInit {
+
+ public static void init() {
+ RegistryEvents.INIT_REGISTRIES.register(EnchantmentRegistryImpl::init);
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java
new file mode 100644
index 000000000..75659ac8d
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/VanillaEnchantments.java
@@ -0,0 +1,118 @@
+package net.ornithemc.osl.enchantments.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.core.api.util.NamespacedIdentifiers;
+
+public final class VanillaEnchantments {
+
+ /**
+ * Namespaced IDs were introduced in 14w28a. Before then, the numerical IDs
+ * were the only unique identifiers for enchantments, and were still used
+ * until 1.9 . Here we assign namespaced IDs to pre-1.9 enchantments, matching
+ * the 1.9 IDs where possible.
+ */
+ private static final String[] IDENTIFIERS = {
+ // grouped per 10 for easier lookup
+
+ "protection",
+ "fire_protection",
+ "feather_falling",
+ "blast_protection",
+ "projectile_protection",
+ "respiration",
+ "aqua_affinity",
+ "thorns",
+ "depth_strider",
+ null,
+
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "sharpness",
+ "smite",
+ "bane_of_arthropods",
+ "knockback",
+
+ "fire_aspect",
+ "looting",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ null,
+ "efficiency",
+ "silk_touch",
+ "unbreaking",
+ "fortune",
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ "power",
+ "punch",
+
+ "flame",
+ "infinity",
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+
+ null,
+ "luck_of_the_sea",
+ "lure"
+ };
+
+ public static final int MAX_ID = 255;
+
+ static void init() {
+ for (Field f : Enchantment.class.getDeclaredFields()) {
+ if (Modifier.isStatic(f.getModifiers()) && Enchantment.class.isAssignableFrom(f.getType())) {
+ try {
+ Enchantment enchantment = (Enchantment) f.get(null);
+
+ if (enchantment != null) {
+ register(enchantment);
+ }
+ } catch (Throwable t) {
+ }
+ }
+ }
+ }
+
+ private static void register(Enchantment enchantment) {
+ if (enchantment.id >= 0 && enchantment.id < IDENTIFIERS.length) {
+ String identifier = IDENTIFIERS[enchantment.id];
+
+ if (identifier != null) {
+ EnchantmentRegistryImpl.register(NamespacedIdentifiers.from(identifier), enchantment);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java
new file mode 100644
index 000000000..c9fcc9697
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl.java
@@ -0,0 +1,6 @@
+package net.ornithemc.osl.enchantments.impl.enchantment;
+
+import net.ornithemc.osl.enchantments.api.enchantment.EnchantmentExtension;
+
+public interface EnchantmentExtensionImpl extends EnchantmentExtension {
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java
new file mode 100644
index 000000000..6c5f9eee1
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentIdFixer.java
@@ -0,0 +1,19 @@
+package net.ornithemc.osl.enchantments.impl.enchantment;
+
+import net.minecraft.enchantment.Enchantment;
+
+import net.ornithemc.osl.registries.api.registry.sync.IdFixer;
+
+public class EnchantmentIdFixer implements IdFixer {
+
+ @Override
+ public void apply() {
+ for (int id = 0; id < Enchantment.BY_ID.length; id++) {
+ Enchantment enchantment = Enchantment.BY_ID[id];
+
+ if (enchantment != null) {
+ enchantment.id = id;
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
new file mode 100644
index 000000000..350d818e6
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/java/net/ornithemc/osl/enchantments/impl/mixin/common/EnchantmentMixin.java
@@ -0,0 +1,147 @@
+package net.ornithemc.osl.enchantments.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.enchantment.Enchantment;
+
+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.enchantments.api.enchantment.EnchantmentExtension;
+import net.ornithemc.osl.enchantments.impl.EnchantmentRegistryImpl;
+import net.ornithemc.osl.enchantments.impl.VanillaEnchantments;
+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(Enchantment.class)
+public class EnchantmentMixin implements EnchantmentExtension {
+
+ @Shadow @Final @Mutable
+ private static Enchantment[] BY_ID;
+
+ @Conditional(minecraftVersion = @Version(value = ">=1.4.4", gameSide = GameSide.SERVER))
+ @Shadow
+ private String key;
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private static void osl$enchantments$unlockEnchantmentRegistry(CallbackInfo ci) {
+ EnchantmentRegistryImpl.unlock();
+ }
+
+ @Conditional(minecraftVersion = @Version("<12w50a"))
+ @Inject(
+ method = "",
+ at = @At(
+ value = "TAIL"
+ )
+ )
+ private static void osl$enchantments$registerEnchantmentsAndArrayMappers1(CallbackInfo ci) {
+ registerEnchantmentsAndArrayMappers();
+ }
+
+ @Conditional(minecraftVersion = @Version(">=12w50a"))
+ @Inject(
+ method = "",
+ at = @At(
+ // target before the for-loop that fills the ALL Enchantment[] array
+ value = "FIELD",
+ target = "Lnet/minecraft/enchantment/Enchantment;BY_ID:[Lnet/minecraft/enchantment/Enchantment;",
+ opcode = Opcodes.GETSTATIC
+ )
+ )
+ private static void osl$enchantments$registerEnchantmentsAndArrayMappers2(CallbackInfo ci) {
+ registerEnchantmentsAndArrayMappers();
+ }
+
+ @Unique
+ private static void registerEnchantmentsAndArrayMappers() {
+ EnchantmentRegistryImpl.registerEnchantments();
+ EnchantmentRegistryImpl.registerUnknownEnchantments();
+
+ SyncedRegistries.registerMapper(RegistryKeys.ENCHANTMENT, NamespacedIdentifiers.from("enchantment/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$enchantments$handleAutoAssignId(int id) {
+ if (id == AUTO_ASSIGN_ID) {
+ // the Enchantment[] array must contain all enchantments so this should
+ // give us a valid ID for the Enchantment registry to use.
+ id = DynamicArray.length(BY_ID);
+
+ // keep 0-255 free for all Vanilla enchantments
+ if (id <= VanillaEnchantments.MAX_ID) {
+ id = VanillaEnchantments.MAX_ID + 1;
+ }
+ }
+
+ return id;
+ }
+
+ @Inject(
+ method = "",
+ at = @At(
+ value = "FIELD",
+ target = "Lnet/minecraft/enchantment/Enchantment;BY_ID:[Lnet/minecraft/enchantment/Enchantment;",
+ opcode = Opcodes.GETSTATIC,
+ args = "array=set"
+ )
+ )
+ private void osl$enchantments$growArrays(CallbackInfo ci, @Local(ordinal = 0) int id) {
+ int capacity = id + 1;
+
+ BY_ID = DynamicArray.grow(BY_ID, capacity);
+ }
+
+ @Conditional(minecraftVersion = @Version(value = ">=1.4.4", gameSide = GameSide.SERVER))
+ @Inject(
+ method = "getTranslationKey",
+ at = @At(
+ value = "HEAD"
+ )
+ )
+ private void osl$enchantments$autoAssignTranslationKey(CallbackInfoReturnable cir) {
+ if (this.key == null) {
+ NamespacedIdentifier identifier = EnchantmentRegistryImpl.getIdentifier((Enchantment) (Object) this);
+
+ if (identifier == null) {
+ this.key = "unknown";
+ } else {
+ this.key = Util.makeTranslationKey(identifier);
+ }
+ }
+ }
+}
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/fabric.mod.json b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/fabric.mod.json
new file mode 100644
index 000000000..b1d946921
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/fabric.mod.json
@@ -0,0 +1,37 @@
+{
+ "schemaVersion": 1,
+ "id": "osl-enchantments",
+ "version": "0.1.0-alpha.1+mcb1.9-pre4-mc14w27b",
+ "environment": "*",
+ "entrypoints": {
+ "init": [
+ "net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init"
+ ]
+ },
+ "mixins": [
+ "osl.enchantments.mixins.json"
+ ],
+ "accessWidener": "osl.enchantments.classtweaker",
+ "depends": {
+ "fabricloader": "\u003e\u003d0.18.0",
+ "minecraft": "\u003e\u003d1.0.0-beta.9.0.4 \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 Enchantments",
+ "description": "Enchantments 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/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.classtweaker b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.classtweaker
new file mode 100644
index 000000000..a0d9fdb66
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.classtweaker
@@ -0,0 +1,6 @@
+classTweaker v1 named
+
+transitive-inject-interface net/minecraft/enchantment/Enchantment net/ornithemc/osl/enchantments/impl/enchantment/EnchantmentExtensionImpl
+
+mutable field net/minecraft/enchantment/Enchantment id I
+accessible field net/minecraft/enchantment/Enchantment BY_ID [Lnet/minecraft/enchantment/Enchantment;
diff --git a/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.mixins.json b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.mixins.json
new file mode 100644
index 000000000..d028375a8
--- /dev/null
+++ b/libraries/enchantments/enchantments-mcb1.9-pre4-mc14w27b/src/main/resources/osl.enchantments.mixins.json
@@ -0,0 +1,17 @@
+{
+ "required": true,
+ "minVersion": "0.8",
+ "package": "net.ornithemc.osl.enchantments.impl.mixin",
+ "compatibilityLevel": "JAVA_8",
+ "plugin": "net.ornithemc.conditionalmixin.mixin.ConditionalMixinPlugin",
+ "mixins": [
+ "common.EnchantmentMixin"
+ ],
+ "client": [
+ ],
+ "server": [
+ ],
+ "injectors": {
+ "defaultRequire": 1
+ }
+}
diff --git a/libraries/enchantments/gradle.properties b/libraries/enchantments/gradle.properties
new file mode 100644
index 000000000..4db429b85
--- /dev/null
+++ b/libraries/enchantments/gradle.properties
@@ -0,0 +1,7 @@
+library_id = enchantments
+library_name = Enchantments
+library_description = Enchantments API and events.
+library_version = 0.1.0-alpha.1
+
+entrypoint_init = net.ornithemc.osl.enchantments.impl.EnchantmentsInit::init
+osl_dependencies = core:0.9.0,entrypoints:0.5.0,registries:0.4.0
diff --git a/libraries/registries/registries-mc12w18a-mc1.6.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc12w18a-mc1.6.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 4c9a0121f..929f07bd0 100644
--- a/libraries/registries/registries-mc12w18a-mc1.6.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc12w18a-mc1.6.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -1,6 +1,8 @@
package net.ornithemc.osl.registries.api.registry;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.entity.mob.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -19,6 +21,8 @@ public final class RegistryKeys {
public static final ResourceKey/*>>*/ BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey/*>>*/ ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 4c9a0121f..69794e338 100644
--- a/libraries/registries/registries-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc13w36a-mc14w26c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -1,6 +1,8 @@
package net.ornithemc.osl.registries.api.registry;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.entity.living.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -19,6 +21,8 @@ public final class RegistryKeys {
public static final ResourceKey/*>>*/ BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey/*>>*/ ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 4c9a0121f..69794e338 100644
--- a/libraries/registries/registries-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc14w27a-mc17w46a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -1,6 +1,8 @@
package net.ornithemc.osl.registries.api.registry;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.entity.living.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -19,6 +21,8 @@ public final class RegistryKeys {
public static final ResourceKey/*>>*/ BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey/*>>*/ ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 1897728b1..51f811932 100644
--- a/libraries/registries/registries-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc17w47a-mc18w31a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -2,7 +2,9 @@
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
+import net.minecraft.entity.living.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -21,6 +23,8 @@ public final class RegistryKeys {
public static final ResourceKey>> BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey>> ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 1897728b1..51f811932 100644
--- a/libraries/registries/registries-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc18w32a-mc1.13.2/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -2,7 +2,9 @@
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
+import net.minecraft.entity.living.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -21,6 +23,8 @@ public final class RegistryKeys {
public static final ResourceKey>> BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey>> ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 1897728b1..51f811932 100644
--- a/libraries/registries/registries-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mc18w43a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -2,7 +2,9 @@
import net.minecraft.block.Block;
import net.minecraft.block.entity.BlockEntityType;
+import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.EntityType;
+import net.minecraft.entity.living.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -21,6 +23,8 @@ public final class RegistryKeys {
public static final ResourceKey>> BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey>> ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/libraries/registries/registries-mca1.0.1_01-mc12w17a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mca1.0.1_01-mc12w17a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
index 4c9a0121f..929f07bd0 100644
--- a/libraries/registries/registries-mca1.0.1_01-mc12w17a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
+++ b/libraries/registries/registries-mca1.0.1_01-mc12w17a/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java
@@ -1,6 +1,8 @@
package net.ornithemc.osl.registries.api.registry;
import net.minecraft.block.Block;
+import net.minecraft.enchantment.Enchantment;
+import net.minecraft.entity.mob.effect.StatusEffect;
import net.minecraft.item.Item;
import net.minecraft.world.biome.Biome;
@@ -19,6 +21,8 @@ public final class RegistryKeys {
public static final ResourceKey/*>>*/ BLOCK_ENTITY_TYPE = from("block_entity_type");
public static final ResourceKey/*>>*/ ENTITY_TYPE = from("entity_type");
public static final ResourceKey> BIOME = from("biome");
+ public static final ResourceKey> ENCHANTMENT = from("enchantment");
+ public static final ResourceKey> STATUS_EFFECT = from("mob_effect");
/**
* Constructs a registry key with the default namespace and the given identifier.
diff --git a/settings.gradle b/settings.gradle
index 71db3fc33..fc0266334 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:enchantments'
+include ':libraries:enchantments:enchantments-mcb1.9-pre4-mc14w27b'
+include ':libraries:enchantments:enchantments-mc14w28a-mc1.8.9'
+include ':libraries:enchantments:enchantments-mc15w31a-mc18w31a'
+include ':libraries:enchantments:enchantments-mc18w32a-mc1.13.2'
+include ':libraries:enchantments:enchantments-mc18w43a-mc1.14.4'
+
include ':libraries:entities'
include ':libraries:entities:entities-mca1.0.1_01-mc11w48a'
include ':libraries:entities:entities-mc12w01a-mc1.8.2-pre4'