diff --git a/libraries/entities-rendering/README.md b/libraries/entities-rendering/README.md new file mode 100644 index 00000000..58128c07 --- /dev/null +++ b/libraries/entities-rendering/README.md @@ -0,0 +1,26 @@ +# Entities Rendering API + +The Entities Rendering API provides events and utilities for registering and working with entity renderers. + +## Registering Custom Entity Renderers + +Entity renderer registration should be done in a listener to the `REGISTER_ENTITY_RENDERERS` event. + +An example is shown below. + +```java +package com.example; + +import net.ornithemc.osl.entities.api.client.EntityRenderingEvents; +import net.ornithemc.osl.entrypoints.api.client.ClientModInitializer; + +public class ExampleInitializer implements ClientModInitializer { + + @Override + public void initClient() { + EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.register(registry -> { + registry.register(CookieMonsterEntity.class, CookieMonsterRenderer::new); + }); + } +} +``` diff --git a/libraries/entities-rendering/build.gradle b/libraries/entities-rendering/build.gradle new file mode 100644 index 00000000..e98ba2c6 --- /dev/null +++ b/libraries/entities-rendering/build.gradle @@ -0,0 +1 @@ +setUpLibrary(project) diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/build.gradle b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/gradle.properties b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/gradle.properties new file mode 100644 index 00000000..bc56517e --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/gradle.properties @@ -0,0 +1,5 @@ +environment = client +min_mc_version = 14w05a +max_mc_version = 1.14.4 + +minecraft_version = 1.12.2 diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java new file mode 100644 index 00000000..e3fa0b53 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java @@ -0,0 +1,24 @@ +package net.ornithemc.osl.entities.api.client; + +import java.util.function.Function; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; + +/** + * A wrapper around the {@linkplain EntityRenderDispatcher} renderers map. + */ +@FunctionalInterface +public interface EntityRendererRegistry { + + /** + * Registers the given entity renderer for the given entity type. + * + * @param the entity type for which to register the renderer. + * @param type the entity type class. + * @param factory the factory for the entity renderer to register. + */ + void register(Class type, Function> factory); + +} diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java new file mode 100644 index 00000000..af74dc62 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api.client; + +import java.util.function.Consumer; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities rendering lifecycle. + */ +public final class EntityRenderingEvents { + + /** + * This event is invoked upon client start-up, after Vanilla entity renderer registration is finished. + * + *

+ * Custom entity renderer registration should be done in a listener of this event. + * + *

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

+	 * {@code
+	 * EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.register(registry -> {
+	 * 	registry.register(CookieMonsterEntity.class, CookieMonsterRenderer::new);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityRendererRegistry + */ + public static final Event> REGISTER_ENTITY_RENDERERS = Event.consumer(); + +} diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesRenderingMixinPlugin.java b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesRenderingMixinPlugin.java new file mode 100644 index 00000000..2f14636f --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesRenderingMixinPlugin.java @@ -0,0 +1,52 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import net.ornithemc.osl.core.impl.util.MinecraftVersion; + +public class EntitiesRenderingMixinPlugin implements IMixinConfigPlugin { + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if ("net.ornithemc.osl.entities.impl.mixin.client.EntityRenderDispatcherMixinNew".equals(mixinClassName)) { + return MinecraftVersion.resolve().compareTo("18w50a") >= 0; + } + if ("net.ornithemc.osl.entities.impl.mixin.client.EntityRenderDispatcherMixinOld".equals(mixinClassName)) { + return MinecraftVersion.resolve().compareTo("18w50a") < 0; + } + + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinNew.java b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinNew.java new file mode 100644 index 00000000..483bf82e --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinNew.java @@ -0,0 +1,38 @@ +package net.ornithemc.osl.entities.impl.mixin.client; + +import java.util.function.Function; + +import org.spongepowered.asm.mixin.Mixin; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.api.client.EntityRenderingEvents; + +@Mixin(EntityRenderDispatcher.class) +public class EntityRenderDispatcherMixinNew { + + @Shadow + private void m_74922622(Class type, EntityRenderer renderer) { } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private void osl$entities$registerEntityRenderers(CallbackInfo ci) { + EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.invoker().accept(this::register); + } + + @Unique + private void register(Class type, Function> factory) { + this.m_74922622(type, factory.apply((EntityRenderDispatcher) (Object) this)); + } +} diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinOld.java b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinOld.java new file mode 100644 index 00000000..e30891c2 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixinOld.java @@ -0,0 +1,40 @@ +package net.ornithemc.osl.entities.impl.mixin.client; + +import java.util.Map; +import java.util.function.Function; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.api.client.EntityRenderingEvents; + +@Mixin(EntityRenderDispatcher.class) +public class EntityRenderDispatcherMixinOld { + + @Shadow @Final + private Map, EntityRenderer> renderers; + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private void osl$entities$registerEntityRenderers(CallbackInfo ci) { + EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.invoker().accept(this::register); + } + + @Unique + private void register(Class type, Function> factory) { + this.renderers.put(type, factory.apply((EntityRenderDispatcher) (Object) this)); + } +} diff --git a/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/fabric.mod.json b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..3ad32c07 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/fabric.mod.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 1, + "id": "osl-entities-rendering", + "version": "0.1.0+mc14w05a-mc1.14.4", + "environment": "client", + "mixins": [ + "osl.entities-rendering.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.8-alpha.14.5.a \u003c\u003d1.14.4", + "osl-core": "\u003e\u003d0.9.0", + "osl-entrypoints": "\u003e\u003d0.5.0" + }, + "name": "OSL Entities Rendering", + "description": "Entities Rendering 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/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/osl.entities-rendering.mixins.json b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/osl.entities-rendering.mixins.json new file mode 100644 index 00000000..32057071 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mc14w05a-mc1.14.4/src/main/resources/osl.entities-rendering.mixins.json @@ -0,0 +1,18 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.osl.entities.impl.EntitiesRenderingMixinPlugin", + "mixins": [ + ], + "client": [ + "client.EntityRenderDispatcherMixinNew", + "client.EntityRenderDispatcherMixinOld" + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/build.gradle b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/gradle.properties b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/gradle.properties new file mode 100644 index 00000000..406c9774 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/gradle.properties @@ -0,0 +1,8 @@ +environment = client +min_mc_version = a1.0.1_01 +max_mc_version = 14w04b + +minecraft_version = 1.7.2 +raven_build = 1 +sparrow_build = 1 +nests_build = 3 diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java new file mode 100644 index 00000000..d293b8f9 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRendererRegistry.java @@ -0,0 +1,24 @@ +package net.ornithemc.osl.entities.api.client; + +import java.util.function.Supplier; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; + +/** + * A wrapper around the {@linkplain EntityRenderDispatcher} renderers map. + */ +@FunctionalInterface +public interface EntityRendererRegistry { + + /** + * Registers the given entity renderer for the given entity type. + * + * @param the entity type for which to register the renderer. + * @param type the entity type class. + * @param factory the factory for the entity renderer to register. + */ + void register(Class type, Supplier> factory); + +} diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java new file mode 100644 index 00000000..af74dc62 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/api/client/EntityRenderingEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api.client; + +import java.util.function.Consumer; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities rendering lifecycle. + */ +public final class EntityRenderingEvents { + + /** + * This event is invoked upon client start-up, after Vanilla entity renderer registration is finished. + * + *

+ * Custom entity renderer registration should be done in a listener of this event. + * + *

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

+	 * {@code
+	 * EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.register(registry -> {
+	 * 	registry.register(CookieMonsterEntity.class, CookieMonsterRenderer::new);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityRendererRegistry + */ + public static final Event> REGISTER_ENTITY_RENDERERS = Event.consumer(); + +} diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixin.java b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixin.java new file mode 100644 index 00000000..24369cfa --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/client/EntityRenderDispatcherMixin.java @@ -0,0 +1,41 @@ +package net.ornithemc.osl.entities.impl.mixin.client; + +import java.util.Map; +import java.util.function.Supplier; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +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.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.render.entity.EntityRenderDispatcher; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.api.client.EntityRenderingEvents; + +@Mixin(EntityRenderDispatcher.class) +public class EntityRenderDispatcherMixin { + + @Shadow @Final + private Map, EntityRenderer> renderers; + + @Inject( + method = "", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;values()Ljava/util/Collection;" + ) + ) + private void osl$entities$registerEntityRenderers(CallbackInfo ci) { + EntityRenderingEvents.REGISTER_ENTITY_RENDERERS.invoker().accept(this::register); + } + + @Unique + private void register(Class type, Supplier> factory) { + this.renderers.put(type, factory.get()); + } +} diff --git a/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/fabric.mod.json b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..497fc5e1 --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/fabric.mod.json @@ -0,0 +1,26 @@ +{ + "schemaVersion": 1, + "id": "osl-entities-rendering", + "version": "0.1.0+mca1.0.1_01-mc14w04b", + "environment": "client", + "mixins": [ + "osl.entities-rendering.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.0.0-alpha.0.1.1 \u003c\u003d1.8-alpha.14.4.b", + "osl-core": "\u003e\u003d0.9.0", + "osl-entrypoints": "\u003e\u003d0.5.0" + }, + "name": "OSL Entities Rendering", + "description": "Entities Rendering 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/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/osl.entities-rendering.mixins.json b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/osl.entities-rendering.mixins.json new file mode 100644 index 00000000..5e8354bf --- /dev/null +++ b/libraries/entities-rendering/entities-rendering-mca1.0.1_01-mc14w04b/src/main/resources/osl.entities-rendering.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + ], + "client": [ + "client.EntityRenderDispatcherMixin" + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities-rendering/gradle.properties b/libraries/entities-rendering/gradle.properties new file mode 100644 index 00000000..87d4295c --- /dev/null +++ b/libraries/entities-rendering/gradle.properties @@ -0,0 +1,6 @@ +library_id = entities-rendering +library_name = Entities Rendering +library_description = Entities Rendering API and events. +library_version = 0.1.0 + +osl_dependencies = core:0.9.0,entrypoints:0.5.0 diff --git a/libraries/entities/README.md b/libraries/entities/README.md new file mode 100644 index 00000000..c01fa49e --- /dev/null +++ b/libraries/entities/README.md @@ -0,0 +1,43 @@ +# Entities API + +The Entities API provides events and utilities for registering and working with entities. + +## Registering Custom Entity Types + +Entity type registration should be done in a listener to the `REGISTER_ENTITY_TYPES` event. The `EntityTypeRegistry` class provides utility methods for registering entity types. + +An example is shown below. + +```java +package com.example; + +import net.ornithemc.osl.entities.api.EntityEvents; +import net.ornithemc.osl.entrypoints.api.ModInitializer; + +public class ExampleInitializer implements ModInitializer { + + @Override + public void init() { + EntityEvents.REGISTER_ENTITY_TYPES.register(ExampleEntityTypes::init); + } +} +``` + +```java +package com.example; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.living.MobCategory; + +import net.ornithemc.osl.entities.api.EntityTypeRegistry; +import net.ornithemc.osl.entities.api.EntityTypes; +import net.ornithemc.osl.core.util.NamespacedIdentifiers; + +public final class ExampleEntityTypes { + + public static final EntityType COOKIE_MONSTER = EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), EntityTypes.builder(CookieMonsterEntity::new, MobCategory.MISC)); + + public static void init() { + } +} +``` diff --git a/libraries/entities/build.gradle b/libraries/entities/build.gradle new file mode 100644 index 00000000..e98ba2c6 --- /dev/null +++ b/libraries/entities/build.gradle @@ -0,0 +1 @@ +setUpLibrary(project) diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/build.gradle b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/gradle.properties b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/gradle.properties new file mode 100644 index 00000000..27ea8651 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 1.8.2-pre5 +max_mc_version = 1.10.2 + +minecraft_version = 1.8.9 diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..d7c80c74 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), CookieMonsterEntity.class);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..174ac7f3 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,148 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(Class type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(Class type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(Class type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the legacy {@code String} key assigned to the given entity type. + */ + public static String getLegacyKey(Class type) { + return EntityTypeRegistryImpl.getLegacyKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static Class getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static Class getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static Class getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return the entity type mapped to the given legacy {@code String} key. + */ + public static Class getEntityType(String legacyKey) { + return EntityTypeRegistryImpl.getEntityType(legacyKey); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @return a set containing all legacy {@code String} keys in the registry. + */ + public static Set legacyKeySet() { + return EntityTypeRegistryImpl.legacyKeySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(NamespacedIdentifier identifier, Class type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(ResourceKey> key, Class type) { + return EntityTypeRegistryImpl.register(key, type); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param identifier the identifier of the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(identifier, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param key the resource key of the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(key, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param type the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(type, baseColor, spotsColor); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java new file mode 100644 index 00000000..f9fdef4d --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java @@ -0,0 +1,56 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import net.ornithemc.osl.core.impl.util.MinecraftVersion; + +public class EntitiesMixinPlugin implements IMixinConfigPlugin { + + public static final boolean SPAWN_EGGS_BY_ID = MinecraftVersion.resolve().compareTo("15w33a") < 0; + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixin_15w32c".equals(mixinClassName) + || "net.ornithemc.osl.entities.impl.mixin.common.SpawnEggDataAccessOld".equals(mixinClassName)) { + return SPAWN_EGGS_BY_ID; + } + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixin_15w33a".equals(mixinClassName) + || "net.ornithemc.osl.entities.impl.mixin.common.SpawnEggDataAccessNew".equals(mixinClassName)) { + return !SPAWN_EGGS_BY_ID; + } + + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..da39bb37 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,113 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final WrappedEntityTypeRegistry REGISTRY = RegistriesImpl.register(RegistryKeys.ENTITY_TYPE, new WrappedEntityTypeRegistry(RegistryKeys.ENTITY_TYPE.identifier()), () -> Entities.KEY_TO_TYPE.getClass()); + /* + * Entities.SPAWN_EGG_DATA changes key type from Integer to String in 15w33a so we can't reference it directly. + */ + public static SpawnEggDataRegistry SPAWN_EGG_DATA_REGISTRY; + + private static boolean locked = true; + + public static int getId(Class type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(Class type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(Class type) { + return REGISTRY.getKey(type); + } + + public static String getLegacyKey(Class type) { + return REGISTRY.getLegacyKey(type); + } + + public static Class getEntityType(int id) { + return REGISTRY.get(id); + } + + public static Class getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static Class getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Class getEntityType(String legacyKey) { + return REGISTRY.get(legacyKey); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static Set legacyKeySet() { + return REGISTRY.legacyKeySet(); + } + + public static Class register(NamespacedIdentifier identifier, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type); + } + } + + public static Class register(ResourceKey> key, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type); + } + } + + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(identifier), baseColor, spotsColor); + } + + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(key), baseColor, spotsColor); + } + + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + SPAWN_EGG_DATA_REGISTRY.register(type, baseColor, spotsColor); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/SpawnEggDataRegistry.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/SpawnEggDataRegistry.java new file mode 100644 index 00000000..3cac80d8 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/SpawnEggDataRegistry.java @@ -0,0 +1,10 @@ +package net.ornithemc.osl.entities.impl; + +import net.minecraft.entity.Entity; + +@FunctionalInterface +public interface SpawnEggDataRegistry { + + void register(Class type, int baseColor, int spotsColor); + +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java new file mode 100644 index 00000000..b0a5bebc --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.entities.impl; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +final class VanillaEntityTypes { + + static final BiMap IDENTIFIERS = HashBiMap.create(); + + static { + IDENTIFIERS.put("Item", "item"); + IDENTIFIERS.put("XPOrb", "xp_orb"); + IDENTIFIERS.put("AreaEffectCloud", "area_effect_cloud"); + IDENTIFIERS.put("ThrownEgg", "egg"); + IDENTIFIERS.put("LeashKnot", "leash_knot"); + IDENTIFIERS.put("Painting", "painting"); + IDENTIFIERS.put("Arrow", "arrow"); + IDENTIFIERS.put("Snowball", "snowball"); + IDENTIFIERS.put("Fireball", "fireball"); + IDENTIFIERS.put("SmallFireball", "small_fireball"); + IDENTIFIERS.put("ThrownEnderPearl", "ender_pearl"); + IDENTIFIERS.put("EyeOfEnderSignal", "eye_of_ender_signal"); + IDENTIFIERS.put("ThrowPotion", "potion"); + IDENTIFIERS.put("ThrownExpBottle", "xp_bottle"); + IDENTIFIERS.put("ItemFrame", "item_frame"); + IDENTIFIERS.put("WitherSkull", "wither_skull"); + IDENTIFIERS.put("PrimedTNT", "tnt"); + IDENTIFIERS.put("FallingSand", "falling_block"); + IDENTIFIERS.put("FireworksRocketEntity", "fireworks_rocket"); + IDENTIFIERS.put("SpectralArrow", "spectral_arrow"); + IDENTIFIERS.put("ShulkerBullet", "shulker_bullet"); + IDENTIFIERS.put("DragonFireball", "dragon_fireball"); + IDENTIFIERS.put("ArmorStand", "armor_stand"); + IDENTIFIERS.put("Boat", "boat"); + IDENTIFIERS.put("MinecartRideable", "minecart"); + IDENTIFIERS.put("MinecartChest", "chest_minecart"); + IDENTIFIERS.put("MinecartFurnace", "furnace_minecart"); + IDENTIFIERS.put("MinecartTNT", "tnt_minecart"); + IDENTIFIERS.put("MinecartSpawner", "spawner_minecart"); + IDENTIFIERS.put("MinecartHopper", "hopper_minecart"); + IDENTIFIERS.put("MinecartCommandBlock", "commandblock_minecart"); + IDENTIFIERS.put("Mob", "mob"); + IDENTIFIERS.put("Monster", "monster"); + IDENTIFIERS.put("Creeper", "creeper"); + IDENTIFIERS.put("Skeleton", "skeleton"); + IDENTIFIERS.put("Spider", "spider"); + IDENTIFIERS.put("Giant", "giant"); + IDENTIFIERS.put("Zombie", "zombie"); + IDENTIFIERS.put("Slime", "slime"); + IDENTIFIERS.put("Ghast", "ghast"); + IDENTIFIERS.put("PigZombie", "zombie_pigman"); + IDENTIFIERS.put("Enderman", "enderman"); + IDENTIFIERS.put("CaveSpider", "cave_spider"); + IDENTIFIERS.put("Silverfish", "silverfish"); + IDENTIFIERS.put("Blaze", "blaze"); + IDENTIFIERS.put("LavaSlime", "magma_cube"); + IDENTIFIERS.put("EnderDragon", "ender_dragon"); + IDENTIFIERS.put("WitherBoss", "wither"); + IDENTIFIERS.put("Bat", "bat"); + IDENTIFIERS.put("Witch", "witch"); + IDENTIFIERS.put("Endermite", "endermite"); + IDENTIFIERS.put("Guardian", "guardian"); + IDENTIFIERS.put("Shulker", "shulker"); + IDENTIFIERS.put("Pig", "pig"); + IDENTIFIERS.put("Sheep", "sheep"); + IDENTIFIERS.put("Cow", "cow"); + IDENTIFIERS.put("Chicken", "chicken"); + IDENTIFIERS.put("Squid", "squid"); + IDENTIFIERS.put("Wolf", "wolf"); + IDENTIFIERS.put("MushroomCow", "mooshroom"); + IDENTIFIERS.put("SnowMan", "snowman"); + IDENTIFIERS.put("Ozelot", "ocelot"); + IDENTIFIERS.put("VillagerGolem", "villager_golem"); + IDENTIFIERS.put("EntityHorse", "horse"); + IDENTIFIERS.put("Rabbit", "rabbit"); + IDENTIFIERS.put("PolarBear", "polar_bear"); + IDENTIFIERS.put("Villager", "villager"); + IDENTIFIERS.put("EnderCrystal", "ender_crystal"); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java new file mode 100644 index 00000000..c6643492 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java @@ -0,0 +1,125 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +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 WrappedEntityTypeRegistry extends SimpleRegistry> { + + private final BiMap legacyKeys = HashBiMap.create(); + + private boolean skipEntitiesRegister; + + WrappedEntityTypeRegistry(NamespacedIdentifier identifier) { + super(identifier); + } + + public void register(int id, String legacyKey, Class type) { + NamespacedIdentifier identifier = this.constructIdentifier(legacyKey); + ResourceKey> key = ResourceKeys.from(this.identifier(), identifier); + + this.skipEntitiesRegister = true; + this.register(id, key, type); + this.skipEntitiesRegister = false; + } + + @Override + public > V register(int id, ResourceKey> key, V type) { + type = super.register(id, key, type); + + if (!this.skipEntitiesRegister) { + NamespacedIdentifier identifier = key.identifier(); + String legacyKey = this.constructLegacyKey(identifier); + + if (Entities.KEY_TO_TYPE.containsKey(legacyKey)) { + throw new IllegalStateException("Duplicate legacy Entity type key " + legacyKey); + } + + Entities.KEY_TO_TYPE.put(legacyKey, type); + Entities.TYPE_TO_KEY.put(type, legacyKey); + Entities.ID_TO_TYPE.put(id, type); + Entities.TYPE_TO_ID.put(type, id); + Entities.KEY_TO_ID.put(legacyKey, id); + } + + return type; + } + + private String constructLegacyKey(NamespacedIdentifier identifier) { + return this.legacyKeys.computeIfAbsent(identifier, key -> { + if (identifier.namespace().equals(NamespacedIdentifiers.DEFAULT_NAMESPACE)) { + String legacyKey = VanillaEntityTypes.IDENTIFIERS.inverse().get(identifier.identifier()); + + if (legacyKey != null) { + return legacyKey; + } + } + + return identifier.toString(); + }); + } + + private NamespacedIdentifier constructIdentifier(String legacyKey) { + return this.legacyKeys.inverse().computeIfAbsent(legacyKey, key -> { + String identifier = VanillaEntityTypes.IDENTIFIERS.get(legacyKey); + + if (identifier != null) { + return NamespacedIdentifiers.from(identifier); + } + + StringBuilder sb = new StringBuilder(); + + // convert PascalCase to snake_case + for (int i = 0; i < legacyKey.length(); i++) { + char chr = legacyKey.charAt(i); + + if (Character.isUpperCase(chr)) { + chr = Character.toLowerCase(chr); + + if (i != 0) { + sb.append('_'); + } + } + + sb.append(chr); + } + + return NamespacedIdentifiers.from(sb.toString()); + }); + } + + public Class get(String legacyKey) { + NamespacedIdentifier identifier = this.legacyKeys.inverse().get(legacyKey); + return identifier == null ? null : this.get(identifier); + } + + public String getLegacyKey(Class type) { + NamespacedIdentifier identifier = this.getIdentifier(type); + return identifier == null ? null : this.legacyKeys.get(identifier); + } + + public Set legacyKeySet() { + return this.legacyKeys.values(); + } + + @Override + public void clear() { + super.clear(); + + Entities.KEY_TO_TYPE.clear(); + Entities.TYPE_TO_KEY.clear(); + Entities.ID_TO_TYPE.clear(); + Entities.TYPE_TO_ID.clear(); + Entities.KEY_TO_ID.clear(); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java new file mode 100644 index 00000000..2bef3a81 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java @@ -0,0 +1,68 @@ +package net.ornithemc.osl.entities.impl.entity; + +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; + +import it.unimi.dsi.fastutil.ints.Int2IntFunction; + +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.entities.impl.mixin.common.SpawnEggDataAccessOld; +import net.ornithemc.osl.registries.api.registry.sync.IdMapper; +import net.ornithemc.osl.registries.api.registry.sync.RegistryMappings; + +public class SpawnEggDataMapper implements IdMapper { + + public static SpawnEggDataMapper of(Map spawnEggData) { + return new SpawnEggDataMapper(spawnEggData); + } + + private final Map spawnEggData; + private final Set missing; + + private boolean applied; + + private SpawnEggDataMapper(Map spawnEggData) { + this.spawnEggData = spawnEggData; + this.missing = Collections.newSetFromMap(new IdentityHashMap<>()); + } + + @Override + public void apply(RegistryMappings mappings) { + this.missing.clear(); + this.fixSpawnEggData(mappings::remap, true); + + this.applied = true; + } + + @Override + public void undo(RegistryMappings mappings) { + if (this.applied) { + this.fixSpawnEggData(mappings::unmap, false); + this.missing.clear(); + } + + this.applied = false; + } + + private void fixSpawnEggData(Int2IntFunction mapper, boolean storeMissing) { + for (SpawnEggData spawnEgg : this.spawnEggData.values()) { + if (this.missing.contains(spawnEgg)) { + continue; + } + + SpawnEggDataAccessOld spawnEggAccess = (SpawnEggDataAccessOld) spawnEgg; + + int oldId = spawnEgg.id; + int newId = mapper.applyAsInt(oldId); + + if (newId >= 0) { + spawnEggAccess.setId(newId); + } else if (storeMissing) { + this.missing.add(spawnEgg); + } + } + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java new file mode 100644 index 00000000..35aef159 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java @@ -0,0 +1,45 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixin { + + @Inject( + method = "register", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$register(Class type, String legacyKey, int id, CallbackInfo ci) { + EntityTypeRegistryImpl.REGISTRY.register(id, legacyKey, type); + } + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w32c.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w32c.java new file mode 100644 index 00000000..b4b21d83 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w32c.java @@ -0,0 +1,63 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import java.util.Map; + +import org.objectweb.asm.Opcodes; + +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.At.Shift; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.entities.api.EntityTypeRegistry; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.entities.impl.entity.SpawnEggDataMapper; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; + +@Mixin(Entities.class) +public class EntitiesMixin_15w32c { + + @Shadow + public static Map SPAWN_EGG_DATA; + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/Entities;SPAWN_EGG_DATA:Ljava/util/Map;", + opcode = Opcodes.PUTSTATIC, + shift = Shift.AFTER + ) + ) + private static void osl$entities$registerSpawnEggDataRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.SPAWN_EGG_DATA_REGISTRY = (type, baseColor, spotsColor) -> { + int id = EntityTypeRegistry.getId(type); + + if (id < 0) { + throw new IllegalArgumentException("Entity type " + type.getSimpleName() + " is not registered!"); + } + if (!SPAWN_EGG_DATA.containsKey(id)) { + throw new IllegalArgumentException("Duplicate entity type ID " + id + " in spawn egg data registry!"); + } + + SPAWN_EGG_DATA.put(id, new SpawnEggData(id, baseColor, spotsColor)); + }; + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerSpawnEggDataMapper(CallbackInfo ci) { + SyncedRegistries.registerMapper(RegistryKeys.ENTITY_TYPE, NamespacedIdentifiers.from("entity_type/spawn_egg_data"), SpawnEggDataMapper.of(SPAWN_EGG_DATA)); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w33a.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w33a.java new file mode 100644 index 00000000..6b9f9695 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_15w33a.java @@ -0,0 +1,49 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import java.util.Map; + +import org.objectweb.asm.Opcodes; + +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.At.Shift; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.entities.api.EntityTypeRegistry; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixin_15w33a { + + @Shadow + public static Map SPAWN_EGG_DATA; + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/Entities;SPAWN_EGG_DATA:Ljava/util/Map;", + opcode = Opcodes.PUTSTATIC, + shift = Shift.AFTER + ) + ) + private static void osl$entities$registerSpawnEggDataRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.SPAWN_EGG_DATA_REGISTRY = (type, baseColor, spotsColor) -> { + String legacyKey = EntityTypeRegistry.getLegacyKey(type); + + if (legacyKey == null) { + throw new IllegalArgumentException("Entity type " + type.getSimpleName() + " is not registered!"); + } + if (!SPAWN_EGG_DATA.containsKey(legacyKey)) { + throw new IllegalArgumentException("Duplicate entity type legacy key " + legacyKey + " in spawn egg data registry!"); + } + + SPAWN_EGG_DATA.put(legacyKey, SpawnEggDataAccessNew.of(legacyKey, baseColor, spotsColor)); + }; + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessNew.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessNew.java new file mode 100644 index 00000000..1299e82f --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessNew.java @@ -0,0 +1,15 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +import net.minecraft.entity.Entities.SpawnEggData; + +@Mixin(SpawnEggData.class) +public interface SpawnEggDataAccessNew { + + @Invoker("") + static SpawnEggData of(String legacyKey, int baseColor, int spotsColor) { + throw new UnsupportedOperationException(); + } +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessOld.java b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessOld.java new file mode 100644 index 00000000..b0946ed0 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccessOld.java @@ -0,0 +1,16 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.entity.Entities.SpawnEggData; + +@Mixin(SpawnEggData.class) +public interface SpawnEggDataAccessOld { + + @Mutable + @Accessor("id") + void setId(int id); + +} diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..ba66966f --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/fabric.mod.json @@ -0,0 +1,38 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc1.8.2-pre5-mc1.10.2", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "accessWidener": "osl.entities.classtweaker", + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.8.2-rc.5 \u003c\u003d1.10.2", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.classtweaker b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.classtweaker new file mode 100644 index 00000000..c8fa22c6 --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.classtweaker @@ -0,0 +1,9 @@ +classTweaker v1 named + +accessible field net/minecraft/entity/Entities KEY_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_KEY Ljava/util/Map; +accessible field net/minecraft/entity/Entities ID_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_ID Ljava/util/Map; +accessible field net/minecraft/entity/Entities KEY_TO_ID Ljava/util/Map; +accessible field net/minecraft/entity/Entities SPAWN_EGG_DATA Ljava/util/Map; + diff --git a/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..da81152e --- /dev/null +++ b/libraries/entities/entities-mc1.8.2-pre5-mc1.10.2/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,21 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.osl.entities.impl.EntitiesMixinPlugin", + "mixins": [ + "common.EntitiesMixin", + "common.EntitiesMixin_15w32c", + "common.EntitiesMixin_15w33a", + "common.SpawnEggDataAccessNew", + "common.SpawnEggDataAccessOld" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/build.gradle b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/gradle.properties b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/gradle.properties new file mode 100644 index 00000000..6e8b2630 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/gradle.properties @@ -0,0 +1,7 @@ +min_mc_version = 12w01a +max_mc_version = 1.8.2-pre4 + +minecraft_version = 1.7.2 +raven_build = 1 +sparrow_build = 1 +nests_build = 3 diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..d7c80c74 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), CookieMonsterEntity.class);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..7bc698fb --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,148 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(Class type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(Class type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(Class type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the legacy {@code String} key assigned to the given entity type. + */ + public static String getLegacyKey(Class type) { + return EntityTypeRegistryImpl.getLegacyKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static Class getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static Class getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static Class getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return the entity type mapped to the given legacy {@code String} key. + */ + public static Class getEntityType(String legacyKey) { + return EntityTypeRegistryImpl.getEntityType(legacyKey); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @return a set containing all legacy {@code String} keys in the registry. + */ + public static Set legacyKeySet() { + return EntityTypeRegistryImpl.legacyKeySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(NamespacedIdentifier identifier, Class type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(ResourceKey> key, Class type) { + return EntityTypeRegistryImpl.register(key, type); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param identifier the identifier of entity type for which to register the spawn egg data + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(identifier, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param key the resource key of entity type for which to register the spawn egg data + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(key, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param type the entity type for which to register the spawn egg data + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(type, baseColor, spotsColor); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java new file mode 100644 index 00000000..80df3d33 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java @@ -0,0 +1,52 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import net.ornithemc.osl.core.impl.util.MinecraftVersion; + +public class EntitiesMixinPlugin implements IMixinConfigPlugin { + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixin_1_7_10".equals(mixinClassName)) { + return MinecraftVersion.resolve().compareTo("1.7.10") <= 0; + } + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixin_14w02a".equals(mixinClassName)) { + return MinecraftVersion.resolve().compareTo("14w02a") >= 0; + } + + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..b9a808c0 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,124 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Map; +import java.util.Set; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final WrappedEntityTypeRegistry REGISTRY = RegistriesImpl.register(RegistryKeys.ENTITY_TYPE, new WrappedEntityTypeRegistry(RegistryKeys.ENTITY_TYPE.identifier()), () -> Entities.KEY_TO_TYPE.getClass()); + /* + * Entities.SPAWN_EGG_DATA changes type from HashMap to Map in 14w02a so we can't reference it directly. + */ + public static Map SPAWN_EGG_DATA; + + private static boolean locked = true; + + public static int getId(Class type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(Class type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(Class type) { + return REGISTRY.getKey(type); + } + + public static String getLegacyKey(Class type) { + return REGISTRY.getLegacyKey(type); + } + + public static Class getEntityType(int id) { + return REGISTRY.get(id); + } + + public static Class getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static Class getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Class getEntityType(String legacyKey) { + return REGISTRY.get(legacyKey); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static Set legacyKeySet() { + return REGISTRY.legacyKeySet(); + } + + public static Class register(NamespacedIdentifier identifier, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type); + } + } + + public static Class register(ResourceKey> key, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type); + } + } + + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(identifier), baseColor, spotsColor); + } + + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(key), baseColor, spotsColor); + } + + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + int id = getId(type); + + if (id < 0) { + throw new IllegalArgumentException("Entity type " + type.getSimpleName() + " is not registered!"); + } + if (!SPAWN_EGG_DATA.containsKey(id)) { + throw new IllegalArgumentException("Duplicate entity type ID " + id + " in spawn egg data registry!"); + } + + SPAWN_EGG_DATA.put(id, new SpawnEggData(id, baseColor, spotsColor)); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java new file mode 100644 index 00000000..b0a5bebc --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.entities.impl; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +final class VanillaEntityTypes { + + static final BiMap IDENTIFIERS = HashBiMap.create(); + + static { + IDENTIFIERS.put("Item", "item"); + IDENTIFIERS.put("XPOrb", "xp_orb"); + IDENTIFIERS.put("AreaEffectCloud", "area_effect_cloud"); + IDENTIFIERS.put("ThrownEgg", "egg"); + IDENTIFIERS.put("LeashKnot", "leash_knot"); + IDENTIFIERS.put("Painting", "painting"); + IDENTIFIERS.put("Arrow", "arrow"); + IDENTIFIERS.put("Snowball", "snowball"); + IDENTIFIERS.put("Fireball", "fireball"); + IDENTIFIERS.put("SmallFireball", "small_fireball"); + IDENTIFIERS.put("ThrownEnderPearl", "ender_pearl"); + IDENTIFIERS.put("EyeOfEnderSignal", "eye_of_ender_signal"); + IDENTIFIERS.put("ThrowPotion", "potion"); + IDENTIFIERS.put("ThrownExpBottle", "xp_bottle"); + IDENTIFIERS.put("ItemFrame", "item_frame"); + IDENTIFIERS.put("WitherSkull", "wither_skull"); + IDENTIFIERS.put("PrimedTNT", "tnt"); + IDENTIFIERS.put("FallingSand", "falling_block"); + IDENTIFIERS.put("FireworksRocketEntity", "fireworks_rocket"); + IDENTIFIERS.put("SpectralArrow", "spectral_arrow"); + IDENTIFIERS.put("ShulkerBullet", "shulker_bullet"); + IDENTIFIERS.put("DragonFireball", "dragon_fireball"); + IDENTIFIERS.put("ArmorStand", "armor_stand"); + IDENTIFIERS.put("Boat", "boat"); + IDENTIFIERS.put("MinecartRideable", "minecart"); + IDENTIFIERS.put("MinecartChest", "chest_minecart"); + IDENTIFIERS.put("MinecartFurnace", "furnace_minecart"); + IDENTIFIERS.put("MinecartTNT", "tnt_minecart"); + IDENTIFIERS.put("MinecartSpawner", "spawner_minecart"); + IDENTIFIERS.put("MinecartHopper", "hopper_minecart"); + IDENTIFIERS.put("MinecartCommandBlock", "commandblock_minecart"); + IDENTIFIERS.put("Mob", "mob"); + IDENTIFIERS.put("Monster", "monster"); + IDENTIFIERS.put("Creeper", "creeper"); + IDENTIFIERS.put("Skeleton", "skeleton"); + IDENTIFIERS.put("Spider", "spider"); + IDENTIFIERS.put("Giant", "giant"); + IDENTIFIERS.put("Zombie", "zombie"); + IDENTIFIERS.put("Slime", "slime"); + IDENTIFIERS.put("Ghast", "ghast"); + IDENTIFIERS.put("PigZombie", "zombie_pigman"); + IDENTIFIERS.put("Enderman", "enderman"); + IDENTIFIERS.put("CaveSpider", "cave_spider"); + IDENTIFIERS.put("Silverfish", "silverfish"); + IDENTIFIERS.put("Blaze", "blaze"); + IDENTIFIERS.put("LavaSlime", "magma_cube"); + IDENTIFIERS.put("EnderDragon", "ender_dragon"); + IDENTIFIERS.put("WitherBoss", "wither"); + IDENTIFIERS.put("Bat", "bat"); + IDENTIFIERS.put("Witch", "witch"); + IDENTIFIERS.put("Endermite", "endermite"); + IDENTIFIERS.put("Guardian", "guardian"); + IDENTIFIERS.put("Shulker", "shulker"); + IDENTIFIERS.put("Pig", "pig"); + IDENTIFIERS.put("Sheep", "sheep"); + IDENTIFIERS.put("Cow", "cow"); + IDENTIFIERS.put("Chicken", "chicken"); + IDENTIFIERS.put("Squid", "squid"); + IDENTIFIERS.put("Wolf", "wolf"); + IDENTIFIERS.put("MushroomCow", "mooshroom"); + IDENTIFIERS.put("SnowMan", "snowman"); + IDENTIFIERS.put("Ozelot", "ocelot"); + IDENTIFIERS.put("VillagerGolem", "villager_golem"); + IDENTIFIERS.put("EntityHorse", "horse"); + IDENTIFIERS.put("Rabbit", "rabbit"); + IDENTIFIERS.put("PolarBear", "polar_bear"); + IDENTIFIERS.put("Villager", "villager"); + IDENTIFIERS.put("EnderCrystal", "ender_crystal"); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java new file mode 100644 index 00000000..a5d44d93 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java @@ -0,0 +1,132 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.core.impl.util.MinecraftVersion; +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 WrappedEntityTypeRegistry extends SimpleRegistry> { + + private static final boolean VANILLA_TRACKS_KEY_TO_ID = MinecraftVersion.resolve().compareTo("12w06a") >= 0; + + private final BiMap legacyKeys = HashBiMap.create(); + + private boolean skipEntitiesRegister; + + WrappedEntityTypeRegistry(NamespacedIdentifier identifier) { + super(identifier); + } + + public void register(int id, String legacyKey, Class type) { + NamespacedIdentifier identifier = this.constructIdentifier(legacyKey); + ResourceKey> key = ResourceKeys.from(this.identifier(), identifier); + + this.skipEntitiesRegister = true; + this.register(id, key, type); + this.skipEntitiesRegister = false; + } + + @Override + public > V register(int id, ResourceKey> key, V type) { + type = super.register(id, key, type); + + if (!this.skipEntitiesRegister) { + NamespacedIdentifier identifier = key.identifier(); + String legacyKey = this.constructLegacyKey(identifier); + + if (Entities.KEY_TO_TYPE.containsKey(legacyKey)) { + throw new IllegalStateException("Duplicate legacy Entity type key " + legacyKey); + } + + Entities.KEY_TO_TYPE.put(legacyKey, type); + Entities.TYPE_TO_KEY.put(type, legacyKey); + Entities.ID_TO_TYPE.put(id, type); + Entities.TYPE_TO_ID.put(type, id); + if (VANILLA_TRACKS_KEY_TO_ID) { + Entities.KEY_TO_ID.put(legacyKey, id); + } + } + + return type; + } + + private String constructLegacyKey(NamespacedIdentifier identifier) { + return this.legacyKeys.computeIfAbsent(identifier, key -> { + if (identifier.namespace().equals(NamespacedIdentifiers.DEFAULT_NAMESPACE)) { + String legacyKey = VanillaEntityTypes.IDENTIFIERS.inverse().get(identifier.identifier()); + + if (legacyKey != null) { + return legacyKey; + } + } + + return identifier.toString(); + }); + } + + private NamespacedIdentifier constructIdentifier(String legacyKey) { + return this.legacyKeys.inverse().computeIfAbsent(legacyKey, key -> { + String identifier = VanillaEntityTypes.IDENTIFIERS.get(legacyKey); + + if (identifier != null) { + return NamespacedIdentifiers.from(identifier); + } + + StringBuilder sb = new StringBuilder(); + + // convert PascalCase to snake_case + for (int i = 0; i < legacyKey.length(); i++) { + char chr = legacyKey.charAt(i); + + if (Character.isUpperCase(chr)) { + chr = Character.toLowerCase(chr); + + if (i != 0) { + sb.append('_'); + } + } + + sb.append(chr); + } + + return NamespacedIdentifiers.from(sb.toString()); + }); + } + + public Class get(String legacyKey) { + NamespacedIdentifier identifier = this.legacyKeys.inverse().get(legacyKey); + return identifier == null ? null : this.get(identifier); + } + + public String getLegacyKey(Class type) { + NamespacedIdentifier identifier = this.getIdentifier(type); + return identifier == null ? null : this.legacyKeys.get(identifier); + } + + public Set legacyKeySet() { + return this.legacyKeys.values(); + } + + @Override + public void clear() { + super.clear(); + + Entities.KEY_TO_TYPE.clear(); + Entities.TYPE_TO_KEY.clear(); + Entities.ID_TO_TYPE.clear(); + Entities.TYPE_TO_ID.clear(); + if (VANILLA_TRACKS_KEY_TO_ID) { + Entities.KEY_TO_ID.clear(); + } + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java new file mode 100644 index 00000000..d78d9858 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/entity/SpawnEggDataMapper.java @@ -0,0 +1,68 @@ +package net.ornithemc.osl.entities.impl.entity; + +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Map; +import java.util.Set; + +import it.unimi.dsi.fastutil.ints.Int2IntFunction; + +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.entities.impl.mixin.common.SpawnEggDataAccess; +import net.ornithemc.osl.registries.api.registry.sync.IdMapper; +import net.ornithemc.osl.registries.api.registry.sync.RegistryMappings; + +public class SpawnEggDataMapper implements IdMapper { + + public static SpawnEggDataMapper of(Map spawnEggData) { + return new SpawnEggDataMapper(spawnEggData); + } + + private final Map spawnEggData; + private final Set missing; + + private boolean applied; + + private SpawnEggDataMapper(Map spawnEggData) { + this.spawnEggData = spawnEggData; + this.missing = Collections.newSetFromMap(new IdentityHashMap<>()); + } + + @Override + public void apply(RegistryMappings mappings) { + this.missing.clear(); + this.fixSpawnEggData(mappings::remap, true); + + this.applied = true; + } + + @Override + public void undo(RegistryMappings mappings) { + if (this.applied) { + this.fixSpawnEggData(mappings::unmap, false); + this.missing.clear(); + } + + this.applied = false; + } + + private void fixSpawnEggData(Int2IntFunction mapper, boolean storeMissing) { + for (SpawnEggData spawnEgg : this.spawnEggData.values()) { + if (this.missing.contains(spawnEgg)) { + continue; + } + + SpawnEggDataAccess spawnEggAccess = (SpawnEggDataAccess) spawnEgg; + + int oldId = spawnEgg.id; + int newId = mapper.applyAsInt(oldId); + + if (newId >= 0) { + spawnEggAccess.setId(newId); + } else if (storeMissing) { + this.missing.add(spawnEgg); + } + } + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java new file mode 100644 index 00000000..35aef159 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java @@ -0,0 +1,45 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixin { + + @Inject( + method = "register", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$register(Class type, String legacyKey, int id, CallbackInfo ci) { + EntityTypeRegistryImpl.REGISTRY.register(id, legacyKey, type); + } + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_14w02a.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_14w02a.java new file mode 100644 index 00000000..ae6d98bb --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_14w02a.java @@ -0,0 +1,51 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import java.util.Map; + +import org.objectweb.asm.Opcodes; + +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.At.Shift; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.entities.impl.entity.SpawnEggDataMapper; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; + +@Mixin(Entities.class) +public class EntitiesMixin_14w02a { + + @Shadow + public static Map f_06564953; // SPAWN_EGG_DATA + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/Entities;f_06564953:Ljava/util/Map;", + opcode = Opcodes.PUTSTATIC, + shift = Shift.AFTER + ) + ) + private static void osl$entities$registerSpawnEggDataRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.SPAWN_EGG_DATA = f_06564953; + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerSpawnEggDataMapper(CallbackInfo ci) { + SyncedRegistries.registerMapper(RegistryKeys.ENTITY_TYPE, NamespacedIdentifiers.from("entity_type/spawn_egg_data"), SpawnEggDataMapper.of(f_06564953)); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_1_7_10.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_1_7_10.java new file mode 100644 index 00000000..c0239ef8 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin_1_7_10.java @@ -0,0 +1,51 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import java.util.HashMap; + +import org.objectweb.asm.Opcodes; + +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.At.Shift; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.entities.impl.entity.SpawnEggDataMapper; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; + +@Mixin(Entities.class) +public class EntitiesMixin_1_7_10 { + + @Shadow + public static HashMap SPAWN_EGG_DATA; + + @Inject( + method = "", + at = @At( + value = "FIELD", + target = "Lnet/minecraft/entity/Entities;SPAWN_EGG_DATA:Ljava/util/HashMap;", + opcode = Opcodes.PUTSTATIC, + shift = Shift.AFTER + ) + ) + private static void osl$entities$registerSpawnEggDataRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.SPAWN_EGG_DATA = SPAWN_EGG_DATA; + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerSpawnEggDataMapper(CallbackInfo ci) { + SyncedRegistries.registerMapper(RegistryKeys.ENTITY_TYPE, NamespacedIdentifiers.from("entity_type/spawn_egg_data"), SpawnEggDataMapper.of(SPAWN_EGG_DATA)); + } +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccess.java b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccess.java new file mode 100644 index 00000000..a1fa3215 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/SpawnEggDataAccess.java @@ -0,0 +1,16 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Mutable; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.entity.Entities.SpawnEggData; + +@Mixin(SpawnEggData.class) +public interface SpawnEggDataAccess { + + @Mutable + @Accessor("id") + void setId(int id); + +} diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..7c1b7888 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/fabric.mod.json @@ -0,0 +1,38 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc12w01a-mc1.8.2-pre4", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "accessWidener": "osl.entities.classtweaker", + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.1-alpha.12.1.a \u003c\u003d1.8.2-rc.4", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.classtweaker b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.classtweaker new file mode 100644 index 00000000..b82c7fda --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.classtweaker @@ -0,0 +1,7 @@ +classTweaker v1 named + +accessible field net/minecraft/entity/Entities KEY_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_KEY Ljava/util/Map; +accessible field net/minecraft/entity/Entities ID_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_ID Ljava/util/Map; +accessible field net/minecraft/entity/Entities KEY_TO_ID Ljava/util/Map; diff --git a/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..baf41bd9 --- /dev/null +++ b/libraries/entities/entities-mc12w01a-mc1.8.2-pre4/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,20 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.osl.entities.impl.EntitiesMixinPlugin", + "mixins": [ + "common.EntitiesMixin", + "common.EntitiesMixin_1_7_10", + "common.EntitiesMixin_14w02a", + "common.SpawnEggDataAccess" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/build.gradle b/libraries/entities/entities-mc16w32a-mc18w01a/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/gradle.properties b/libraries/entities/entities-mc16w32a-mc18w01a/gradle.properties new file mode 100644 index 00000000..6dc628d9 --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/gradle.properties @@ -0,0 +1,6 @@ +min_mc_version = 16w32a +max_mc_version = 18w01a + +minecraft_version = 1.12.2 +raven_build = 1 +sparrow_build = 1 diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..d7c80c74 --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), CookieMonsterEntity.class);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..be1c69ba --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,127 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(Class type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(Class type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(Class type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static Class getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static Class getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static Class getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(NamespacedIdentifier identifier, Class type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(ResourceKey> key, Class type) { + return EntityTypeRegistryImpl.register(key, type); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param identifier the identifier of the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(identifier, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param key the resource key of the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(key, baseColor, spotsColor); + } + + /** + * Registers spawn egg data for the specified entity type. + * + * @param type the entity type for which to register the spawn egg data. + * @param baseColor the base color of the spawn egg. + * @param spotsColor the color of the spots on the spawn egg. + */ + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + EntityTypeRegistryImpl.registerSpawnEggData(type, baseColor, spotsColor); + } +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java new file mode 100644 index 00000000..1583ed03 --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java @@ -0,0 +1,20 @@ +package net.ornithemc.osl.entities.impl; + +import net.minecraft.entity.Entity; +import net.minecraft.resource.Identifier; +import net.minecraft.util.registry.IdRegistry; + +/** + * The entity type registry is created and populated in Entities's class initializer. + * This breaks OSL's usual pattern of registering the registry in the API entrypoint but + * triggering registry population during bootstrapping, since OSL has to wrap the Vanilla + * registry which is not possible without triggering Entities class load and registry + * population. + * The solution: move the Vanilla registry to another class and replace the IdRegistry + * reference in Entities with this one. + */ +public final class EntityTypeIdRegistry { + + public static final IdRegistry> REGISTRY = new IdRegistry<>(); + +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..4480a0a6 --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,108 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entities.SpawnEggData; +import net.minecraft.entity.Entity; +import net.minecraft.resource.Identifier; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final Registry> REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENTITY_TYPE, EntityTypeIdRegistry.REGISTRY, () -> Entities.REGISTRY); + + private static boolean locked = true; + + public static int getId(Class type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(Class type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(Class type) { + return REGISTRY.getKey(type); + } + + public static Class getEntityType(int id) { + return REGISTRY.get(id); + } + + public static Class getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static Class getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static Class register(NamespacedIdentifier identifier, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type); + } + } + + public static Class register(ResourceKey> key, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type); + } + } + + public static void registerSpawnEggData(NamespacedIdentifier identifier, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(identifier), baseColor, spotsColor); + } + + public static void registerSpawnEggData(ResourceKey> key, int baseColor, int spotsColor) { + registerSpawnEggData(getEntityType(key), baseColor, spotsColor); + } + + public static void registerSpawnEggData(Class type, int baseColor, int spotsColor) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + Identifier identifier = EntityTypeIdRegistry.REGISTRY.getKey(type); + + if (identifier == null) { + throw new IllegalArgumentException("Entity type " + type.getSimpleName() + " is not registered!"); + } + if (!Entities.SPAWN_EGG_DATA.containsKey(identifier)) { + throw new IllegalArgumentException("Duplicate entity type identifier " + identifier + " in spawn egg data registry!"); + } + + Entities.SPAWN_EGG_DATA.put(identifier, new SpawnEggData(identifier, baseColor, spotsColor)); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java new file mode 100644 index 00000000..4c4c226a --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java @@ -0,0 +1,64 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import java.util.List; + +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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; +import net.minecraft.resource.Identifier; +import net.minecraft.util.registry.IdRegistry; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +import net.ornithemc.osl.entities.impl.EntityTypeIdRegistry; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.RegistryKeys; +import net.ornithemc.osl.registries.api.registry.SyncedRegistries; +import net.ornithemc.osl.registries.api.registry.sync.ListMapper; + +@Mixin(Entities.class) +public class EntitiesMixin { + + @Shadow + private static List NAMES; + + @Redirect( + method = "", + at = @At( + value = "NEW", + target = "net/minecraft/util/registry/IdRegistry" + ) + ) + private static IdRegistry> osl$entities$replaceIdRegistry() { + // this allows us to register the entity type registry in the + // API entrypoint without triggering an Entities class load + return EntityTypeIdRegistry.REGISTRY; + } + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + + SyncedRegistries.registerMapper(RegistryKeys.ENTITY_TYPE, NamespacedIdentifiers.from("entity_type/name"), ListMapper.of(NAMES)); + } +} diff --git a/libraries/entities/entities-mc16w32a-mc18w01a/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..6bf8f2bf --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc16w32a-mc18w01a", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.11-alpha.16.32.a \u003c\u003d1.13-alpha.18.1.a", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc16w32a-mc18w01a/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..06faea95 --- /dev/null +++ b/libraries/entities/entities-mc16w32a-mc18w01a/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.EntitiesMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/build.gradle b/libraries/entities/entities-mc18w19a-mc18w31a/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/gradle.properties b/libraries/entities/entities-mc18w19a-mc18w31a/gradle.properties new file mode 100644 index 00000000..a9026982 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 18w19a +max_mc_version = 18w31a + +minecraft_version = 1.13 diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..e5741534 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), EntityTypes.builder(CookieMonsterEntity.class, CookieMonsterEntity::new));
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..2bfaaa72 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,95 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(EntityType type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(EntityType type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(EntityType type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static EntityType getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static EntityType getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(key, type); + } +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java new file mode 100644 index 00000000..9610e068 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java @@ -0,0 +1,20 @@ +package net.ornithemc.osl.entities.api; + +import java.util.function.Function; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.world.World; + +/** + * Utilities for constructing and modifying entity types. + */ +public final class EntityTypes { + + /** + * @return a new entity type builder with the given entity type class and entity factory. + */ + public static EntityType.Builder builder(Class type, Function factory) { + return EntityType.Builder.of(type, factory); + } +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java new file mode 100644 index 00000000..0d5e8984 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeIdRegistry.java @@ -0,0 +1,20 @@ +package net.ornithemc.osl.entities.impl; + +import net.minecraft.entity.EntityType; +import net.minecraft.resource.Identifier; +import net.minecraft.util.registry.IdRegistry; + +/** + * The entity type registry is created and populated in EntityType's class initializer. + * This breaks OSL's usual pattern of registering the registry in the API entrypoint but + * triggering registry population during bootstrapping, since OSL has to wrap the Vanilla + * registry which is not possible without triggering EntityType class load and registry + * population. + * The solution: move the Vanilla registry to another class and replace the IdRegistry + * reference in EntityType with this one. + */ +public final class EntityTypeIdRegistry { + + public static final IdRegistry> REGISTRY = new IdRegistry<>(); + +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..aee89541 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,81 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final Registry> REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENTITY_TYPE, EntityTypeIdRegistry.REGISTRY, () -> EntityType.REGISTRY); + + private static boolean locked = true; + + public static int getId(EntityType type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(EntityType type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(EntityType type) { + return REGISTRY.getKey(type); + } + + public static EntityType getEntityType(int id) { + return REGISTRY.get(id); + } + + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static EntityType getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type.build(null)); + } + } + + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type.build(null)); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java new file mode 100644 index 00000000..2f79e367 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java @@ -0,0 +1,51 @@ +package net.ornithemc.osl.entities.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.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.EntityType; +import net.minecraft.resource.Identifier; +import net.minecraft.util.registry.IdRegistry; + +import net.ornithemc.osl.entities.impl.EntityTypeIdRegistry; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(EntityType.class) +public class EntityTypeMixin { + + @Redirect( + method = "", + at = @At( + value = "NEW", + target = "net/minecraft/util/registry/IdRegistry" + ) + ) + private static IdRegistry> osl$entities$replaceIdRegistry() { + // this allows us to register the entity type registry in the + // API entrypoint without triggering an EntityType class load + return EntityTypeIdRegistry.REGISTRY; + } + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mc18w19a-mc18w31a/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..9d55e3a0 --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc18w19a-mc18w31a", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.13-alpha.18.19.a \u003c\u003d1.13.1-alpha.18.31.a", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc18w19a-mc18w31a/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..515a97de --- /dev/null +++ b/libraries/entities/entities-mc18w19a-mc18w31a/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.EntityTypeMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/build.gradle b/libraries/entities/entities-mc18w32a-mc19w04b/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/gradle.properties b/libraries/entities/entities-mc18w32a-mc19w04b/gradle.properties new file mode 100644 index 00000000..1c1cbede --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 18w32a +max_mc_version = 19w04b + +minecraft_version = 1.13.2 diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..e5741534 --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), EntityTypes.builder(CookieMonsterEntity.class, CookieMonsterEntity::new));
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..2cca2a1d --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,95 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Block Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(EntityType type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(EntityType type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(EntityType type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static EntityType getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static EntityType getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(key, type); + } +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java new file mode 100644 index 00000000..9610e068 --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java @@ -0,0 +1,20 @@ +package net.ornithemc.osl.entities.api; + +import java.util.function.Function; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.world.World; + +/** + * Utilities for constructing and modifying entity types. + */ +public final class EntityTypes { + + /** + * @return a new entity type builder with the given entity type class and entity factory. + */ + public static EntityType.Builder builder(Class type, Function factory) { + return EntityType.Builder.of(type, factory); + } +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..5d2dceae --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final Registry> REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENTITY_TYPE, net.minecraft.util.registry.Registry.ENTITY_TYPE); + + private static boolean locked = true; + + public static int getId(EntityType type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(EntityType type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(EntityType type) { + return REGISTRY.getKey(type); + } + + public static EntityType getEntityType(int id) { + return REGISTRY.get(id); + } + + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static EntityType getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type.build(null)); + } + } + + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type.build(null)); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java new file mode 100644 index 00000000..cac88003 --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(EntityType.class) +public class EntityTypeMixin { + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mc18w32a-mc19w04b/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..11147a3d --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc18w32a-mc19w04b", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.13.1-alpha.18.32.a \u003c\u003d1.14-alpha.19.4.b", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc18w32a-mc19w04b/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..515a97de --- /dev/null +++ b/libraries/entities/entities-mc18w32a-mc19w04b/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.EntityTypeMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/build.gradle b/libraries/entities/entities-mc19w08a-mc1.14.4/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/gradle.properties b/libraries/entities/entities-mc19w08a-mc1.14.4/gradle.properties new file mode 100644 index 00000000..e7132cde --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/gradle.properties @@ -0,0 +1,4 @@ +min_mc_version = 19w08a +max_mc_version = 1.14.4 + +minecraft_version = 1.14.4 diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..bf0a5d01 --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), EntityTypes.builder(CookieMonsterEntity::new, MobCategory.MISC));
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..2bfaaa72 --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,95 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(EntityType type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(EntityType type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(EntityType type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static EntityType getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static EntityType getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the builder for the entity type to register. + * @return the registered entity type. + */ + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + return EntityTypeRegistryImpl.register(key, type); + } +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java new file mode 100644 index 00000000..9dab8a51 --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/api/EntityTypes.java @@ -0,0 +1,18 @@ +package net.ornithemc.osl.entities.api; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.living.mob.MobCategory; + +/** + * Utilities for constructing and modifying entity types. + */ +public final class EntityTypes { + + /** + * @return a new entity type builder with the given entity factory and mob category. + */ + public static EntityType.Builder builder(EntityType.C_34376702 factory, MobCategory category) { + return EntityType.Builder.of(factory, category); + } +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..9376b9c1 --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,81 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final Registry> REGISTRY = VanillaRegistries.registerSimple(RegistryKeys.ENTITY_TYPE, net.minecraft.util.registry.Registry.ENTITY_TYPE); + + private static boolean locked = true; + + public static int getId(EntityType type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(EntityType type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(EntityType type) { + return REGISTRY.getKey(type); + } + + public static EntityType getEntityType(int id) { + return REGISTRY.get(id); + } + + public static EntityType getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static EntityType getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static EntityType register(NamespacedIdentifier identifier, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type.build(null)); + } + } + + public static EntityType register(ResourceKey> key, EntityType.Builder type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type.build(null)); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java new file mode 100644 index 00000000..cac88003 --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntityTypeMixin.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.EntityType; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(EntityType.class) +public class EntityTypeMixin { + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/resources/fabric.mod.json b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..fcab965f --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/resources/fabric.mod.json @@ -0,0 +1,37 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mc19w08a-mc1.14.4", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.14-alpha.19.8.a \u003c\u003d1.14.4", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mc19w08a-mc1.14.4/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..515a97de --- /dev/null +++ b/libraries/entities/entities-mc19w08a-mc1.14.4/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "common.EntityTypeMixin" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/build.gradle b/libraries/entities/entities-mca1.0.1_01-mc11w48a/build.gradle new file mode 100644 index 00000000..0a350fdb --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/build.gradle @@ -0,0 +1 @@ +setUpModule(project) diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/gradle.properties b/libraries/entities/entities-mca1.0.1_01-mc11w48a/gradle.properties new file mode 100644 index 00000000..6caf1817 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/gradle.properties @@ -0,0 +1,7 @@ +min_mc_version = a1.0.1_01 +max_mc_version = 11w48a + +minecraft_version = 11w48a +client_nests_build = 11 +server_nests_build = 6 + diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java new file mode 100644 index 00000000..d7c80c74 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityEvents.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.api; + +import net.ornithemc.osl.core.api.events.Event; + +/** + * Events related to the entities lifecycle. + */ +public final class EntityEvents { + + /** + * This event is invoked upon game start-up, after Vanilla entity registration is finished. + * + *

+ * Custom entity type registration should be done in a listener of this event. + * Helper methods for registering entity types can be found in the {@linkplain + * EntityTypeRegistry} class. + * + *

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

+	 * {@code
+	 * EntityEvents.REGISTER_ENTITY_TYPES.register(() -> {
+	 * 	EntityTypeRegistry.register(NamespacedIdentifiers.from("example", "cookie_monster"), CookieMonsterEntity.class);
+	 * });
+	 * }
+	 * 
+ * + * @see EntityTypeRegistry + */ + public static final Event REGISTER_ENTITY_TYPES = Event.runnable(); + +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java new file mode 100644 index 00000000..c188c356 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/api/EntityTypeRegistry.java @@ -0,0 +1,115 @@ +package net.ornithemc.osl.entities.api; + +import java.util.Set; + +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; +import net.ornithemc.osl.registries.api.registry.Registry; +import net.ornithemc.osl.registries.api.registry.ResourceKey; + +/** + * Public access to the Entity Types registry. + */ +public final class EntityTypeRegistry { + + public static final Registry> REGISTRY = EntityTypeRegistryImpl.REGISTRY; + + /** + * @return the numerical ID assigned to the given entity type. + */ + public static int getId(Class type) { + return EntityTypeRegistryImpl.getId(type); + } + + /** + * @return the namespaced ID assigned to the given entity type. + */ + public static NamespacedIdentifier getIdentifier(Class type) { + return EntityTypeRegistryImpl.getIdentifier(type); + } + + /** + * @return the resource key assigned to the given entity type. + */ + public static ResourceKey> getKey(Class type) { + return EntityTypeRegistryImpl.getKey(type); + } + + /** + * @return the legacy {@code String} key assigned to the given entity type. + */ + public static String getLegacyKey(Class type) { + return EntityTypeRegistryImpl.getLegacyKey(type); + } + + /** + * @return the entity type mapped to the given numerical ID. + */ + public static Class getEntityType(int id) { + return EntityTypeRegistryImpl.getEntityType(id); + } + + /** + * @return the entity type mapped to the given namespaced ID. + */ + public static Class getEntityType(NamespacedIdentifier identifier) { + return EntityTypeRegistryImpl.getEntityType(identifier); + } + + /** + * @return the entity type mapped to the given resource key. + */ + public static Class getEntityType(ResourceKey> key) { + return EntityTypeRegistryImpl.getEntityType(key); + } + + /** + * @return the entity type mapped to the given legacy {@code String} key. + */ + public static Class getEntityType(String legacyKey) { + return EntityTypeRegistryImpl.getEntityType(legacyKey); + } + + /** + * @return a set containing all namespaced IDs in the registry. + */ + public static Set identifierSet() { + return EntityTypeRegistryImpl.identifierSet(); + } + + /** + * @return a set containing all resource keys in the registry. + */ + public static Set>> keySet() { + return EntityTypeRegistryImpl.keySet(); + } + + /** + * @return a set containing all legacy {@code String} keys in the registry. + */ + public static Set legacyKeySet() { + return EntityTypeRegistryImpl.legacyKeySet(); + } + + /** + * @param the entity type. + * @param identifier the namespaced ID of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(NamespacedIdentifier identifier, Class type) { + return EntityTypeRegistryImpl.register(identifier, type); + } + + /** + * @param the entity type. + * @param key the resource key of the entity type. + * @param type the entity type to register. + * @return the registered entity type. + */ + public static Class register(ResourceKey> key, Class type) { + return EntityTypeRegistryImpl.register(key, type); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java new file mode 100644 index 00000000..9ed7bb12 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntitiesMixinPlugin.java @@ -0,0 +1,59 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.List; +import java.util.Set; + +import org.objectweb.asm.tree.ClassNode; + +import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; +import org.spongepowered.asm.mixin.extensibility.IMixinInfo; + +import net.fabricmc.api.EnvType; +import net.fabricmc.loader.api.FabricLoader; + +import net.ornithemc.osl.core.impl.util.MinecraftVersion; + +public class EntitiesMixinPlugin implements IMixinConfigPlugin { + + public static final boolean VANILLA_ENTITY_TYPES_HAVE_IDS = (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) + ? MinecraftVersion.resolve().compareTo("a1.0.17") >= 0 + : MinecraftVersion.resolve().compareTo("a0.1.4") >= 0; + + @Override + public void onLoad(String mixinPackage) { + } + + @Override + public String getRefMapperConfig() { + return null; + } + + @Override + public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixinNew".equals(mixinClassName)) { + return VANILLA_ENTITY_TYPES_HAVE_IDS; + } + if ("net.ornithemc.osl.entities.impl.mixin.common.EntitiesMixinOld".equals(mixinClassName)) { + return !VANILLA_ENTITY_TYPES_HAVE_IDS; + } + + return true; + } + + @Override + public void acceptTargets(Set myTargets, Set otherTargets) { + } + + @Override + public List getMixins() { + return null; + } + + @Override + public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } + + @Override + public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java new file mode 100644 index 00000000..d17e999e --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/EntityTypeRegistryImpl.java @@ -0,0 +1,93 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.entities.api.EntityEvents; +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 EntityTypeRegistryImpl { + + public static final WrappedEntityTypeRegistry REGISTRY = RegistriesImpl.register(RegistryKeys.ENTITY_TYPE, new WrappedEntityTypeRegistry(RegistryKeys.ENTITY_TYPE.identifier()), () -> Entities.KEY_TO_TYPE.getClass()); + + private static boolean locked = true; + + public static int getId(Class type) { + return REGISTRY.getId(type); + } + + public static NamespacedIdentifier getIdentifier(Class type) { + return REGISTRY.getIdentifier(type); + } + + public static ResourceKey> getKey(Class type) { + return REGISTRY.getKey(type); + } + + public static String getLegacyKey(Class type) { + return REGISTRY.getLegacyKey(type); + } + + public static Class getEntityType(int id) { + return REGISTRY.get(id); + } + + public static Class getEntityType(NamespacedIdentifier identifier) { + return REGISTRY.get(identifier); + } + + public static Class getEntityType(ResourceKey> key) { + return REGISTRY.get(key); + } + + public static Class getEntityType(String legacyKey) { + return REGISTRY.get(legacyKey); + } + + public static Set identifierSet() { + return REGISTRY.identifierSet(); + } + + public static Set>> keySet() { + return REGISTRY.keySet(); + } + + public static Set legacyKeySet() { + return REGISTRY.legacyKeySet(); + } + + public static Class register(NamespacedIdentifier identifier, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, identifier, type); + } + } + + public static Class register(ResourceKey> key, Class type) { + if (locked) { + throw new IllegalStateException("register called too early: registry locked!"); + } else { + return Registry.register(REGISTRY, key, type); + } + } + + public static void init() { + SyncedRegistries.register(RegistryKeys.ENTITY_TYPE); + } + + public static void unlock() { + locked = false; + } + + public static void registerEntityTypes() { + EntityEvents.REGISTER_ENTITY_TYPES.invoker().run(); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java new file mode 100644 index 00000000..b0a5bebc --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/VanillaEntityTypes.java @@ -0,0 +1,80 @@ +package net.ornithemc.osl.entities.impl; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +final class VanillaEntityTypes { + + static final BiMap IDENTIFIERS = HashBiMap.create(); + + static { + IDENTIFIERS.put("Item", "item"); + IDENTIFIERS.put("XPOrb", "xp_orb"); + IDENTIFIERS.put("AreaEffectCloud", "area_effect_cloud"); + IDENTIFIERS.put("ThrownEgg", "egg"); + IDENTIFIERS.put("LeashKnot", "leash_knot"); + IDENTIFIERS.put("Painting", "painting"); + IDENTIFIERS.put("Arrow", "arrow"); + IDENTIFIERS.put("Snowball", "snowball"); + IDENTIFIERS.put("Fireball", "fireball"); + IDENTIFIERS.put("SmallFireball", "small_fireball"); + IDENTIFIERS.put("ThrownEnderPearl", "ender_pearl"); + IDENTIFIERS.put("EyeOfEnderSignal", "eye_of_ender_signal"); + IDENTIFIERS.put("ThrowPotion", "potion"); + IDENTIFIERS.put("ThrownExpBottle", "xp_bottle"); + IDENTIFIERS.put("ItemFrame", "item_frame"); + IDENTIFIERS.put("WitherSkull", "wither_skull"); + IDENTIFIERS.put("PrimedTNT", "tnt"); + IDENTIFIERS.put("FallingSand", "falling_block"); + IDENTIFIERS.put("FireworksRocketEntity", "fireworks_rocket"); + IDENTIFIERS.put("SpectralArrow", "spectral_arrow"); + IDENTIFIERS.put("ShulkerBullet", "shulker_bullet"); + IDENTIFIERS.put("DragonFireball", "dragon_fireball"); + IDENTIFIERS.put("ArmorStand", "armor_stand"); + IDENTIFIERS.put("Boat", "boat"); + IDENTIFIERS.put("MinecartRideable", "minecart"); + IDENTIFIERS.put("MinecartChest", "chest_minecart"); + IDENTIFIERS.put("MinecartFurnace", "furnace_minecart"); + IDENTIFIERS.put("MinecartTNT", "tnt_minecart"); + IDENTIFIERS.put("MinecartSpawner", "spawner_minecart"); + IDENTIFIERS.put("MinecartHopper", "hopper_minecart"); + IDENTIFIERS.put("MinecartCommandBlock", "commandblock_minecart"); + IDENTIFIERS.put("Mob", "mob"); + IDENTIFIERS.put("Monster", "monster"); + IDENTIFIERS.put("Creeper", "creeper"); + IDENTIFIERS.put("Skeleton", "skeleton"); + IDENTIFIERS.put("Spider", "spider"); + IDENTIFIERS.put("Giant", "giant"); + IDENTIFIERS.put("Zombie", "zombie"); + IDENTIFIERS.put("Slime", "slime"); + IDENTIFIERS.put("Ghast", "ghast"); + IDENTIFIERS.put("PigZombie", "zombie_pigman"); + IDENTIFIERS.put("Enderman", "enderman"); + IDENTIFIERS.put("CaveSpider", "cave_spider"); + IDENTIFIERS.put("Silverfish", "silverfish"); + IDENTIFIERS.put("Blaze", "blaze"); + IDENTIFIERS.put("LavaSlime", "magma_cube"); + IDENTIFIERS.put("EnderDragon", "ender_dragon"); + IDENTIFIERS.put("WitherBoss", "wither"); + IDENTIFIERS.put("Bat", "bat"); + IDENTIFIERS.put("Witch", "witch"); + IDENTIFIERS.put("Endermite", "endermite"); + IDENTIFIERS.put("Guardian", "guardian"); + IDENTIFIERS.put("Shulker", "shulker"); + IDENTIFIERS.put("Pig", "pig"); + IDENTIFIERS.put("Sheep", "sheep"); + IDENTIFIERS.put("Cow", "cow"); + IDENTIFIERS.put("Chicken", "chicken"); + IDENTIFIERS.put("Squid", "squid"); + IDENTIFIERS.put("Wolf", "wolf"); + IDENTIFIERS.put("MushroomCow", "mooshroom"); + IDENTIFIERS.put("SnowMan", "snowman"); + IDENTIFIERS.put("Ozelot", "ocelot"); + IDENTIFIERS.put("VillagerGolem", "villager_golem"); + IDENTIFIERS.put("EntityHorse", "horse"); + IDENTIFIERS.put("Rabbit", "rabbit"); + IDENTIFIERS.put("PolarBear", "polar_bear"); + IDENTIFIERS.put("Villager", "villager"); + IDENTIFIERS.put("EnderCrystal", "ender_crystal"); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java new file mode 100644 index 00000000..4c5f7faf --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/WrappedEntityTypeRegistry.java @@ -0,0 +1,139 @@ +package net.ornithemc.osl.entities.impl; + +import java.util.Set; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.core.api.util.NamespacedIdentifier; +import net.ornithemc.osl.core.api.util.NamespacedIdentifiers; +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 WrappedEntityTypeRegistry extends SimpleRegistry> { + + private static final boolean VANILLA_TRACKS_IDS = EntitiesMixinPlugin.VANILLA_ENTITY_TYPES_HAVE_IDS; + + private final BiMap legacyKeys = HashBiMap.create(); + + private boolean skipEntitiesRegister; + + WrappedEntityTypeRegistry(NamespacedIdentifier identifier) { + super(identifier); + } + + public void register(String legacyKey, Class type) { + this.register(-1, legacyKey, type); + } + + public void register(int id, String legacyKey, Class type) { + NamespacedIdentifier identifier = this.constructIdentifier(legacyKey); + ResourceKey> key = ResourceKeys.from(this.identifier(), identifier); + + this.skipEntitiesRegister = true; + + if (id < 0) { + this.register(key, type); + } else { + this.register(id, key, type); + } + + this.skipEntitiesRegister = false; + } + + @Override + public > V register(int id, ResourceKey> key, V type) { + type = super.register(id, key, type); + + if (!this.skipEntitiesRegister) { + NamespacedIdentifier identifier = key.identifier(); + String legacyKey = this.constructLegacyKey(identifier); + + if (Entities.KEY_TO_TYPE.containsKey(legacyKey)) { + throw new IllegalStateException("Duplicate legacy Entity type key " + legacyKey); + } + + Entities.KEY_TO_TYPE.put(legacyKey, type); + Entities.TYPE_TO_KEY.put(type, legacyKey); + if (VANILLA_TRACKS_IDS) { + Entities.ID_TO_TYPE.put(id, type); + Entities.TYPE_TO_ID.put(type, id); + } + } + + return type; + } + + private String constructLegacyKey(NamespacedIdentifier identifier) { + return this.legacyKeys.computeIfAbsent(identifier, key -> { + if (identifier.namespace().equals(NamespacedIdentifiers.DEFAULT_NAMESPACE)) { + String legacyKey = VanillaEntityTypes.IDENTIFIERS.inverse().get(identifier.identifier()); + + if (legacyKey != null) { + return legacyKey; + } + } + + return identifier.toString(); + }); + } + + private NamespacedIdentifier constructIdentifier(String legacyKey) { + return this.legacyKeys.inverse().computeIfAbsent(legacyKey, key -> { + String identifier = VanillaEntityTypes.IDENTIFIERS.get(legacyKey); + + if (identifier != null) { + return NamespacedIdentifiers.from(identifier); + } + + StringBuilder sb = new StringBuilder(); + + // convert PascalCase to snake_case + for (int i = 0; i < legacyKey.length(); i++) { + char chr = legacyKey.charAt(i); + + if (Character.isUpperCase(chr)) { + chr = Character.toLowerCase(chr); + + if (i != 0) { + sb.append('_'); + } + } + + sb.append(chr); + } + + return NamespacedIdentifiers.from(sb.toString()); + }); + } + + public Class get(String legacyKey) { + NamespacedIdentifier identifier = this.legacyKeys.inverse().get(legacyKey); + return identifier == null ? null : this.get(identifier); + } + + public String getLegacyKey(Class type) { + NamespacedIdentifier identifier = this.getIdentifier(type); + return identifier == null ? null : this.legacyKeys.get(identifier); + } + + public Set legacyKeySet() { + return this.legacyKeys.values(); + } + + @Override + public void clear() { + super.clear(); + + Entities.KEY_TO_TYPE.clear(); + Entities.TYPE_TO_KEY.clear(); + if (VANILLA_TRACKS_IDS) { + Entities.ID_TO_TYPE.clear(); + Entities.TYPE_TO_ID.clear(); + } + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java new file mode 100644 index 00000000..c7c89dff --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixin.java @@ -0,0 +1,34 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixin { + + @Inject( + method = "", + at = @At( + value = "HEAD" + ) + ) + private static void osl$entities$unlockEntityTypeRegistry(CallbackInfo ci) { + EntityTypeRegistryImpl.unlock(); + } + + @Inject( + method = "", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$registerEntityTypes(CallbackInfo ci) { + EntityTypeRegistryImpl.registerEntityTypes(); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinNew.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinNew.java new file mode 100644 index 00000000..f256d352 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinNew.java @@ -0,0 +1,25 @@ +package net.ornithemc.osl.entities.impl.mixin.common; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixinNew { + + @Inject( + method = "register", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$register(Class type, String legacyKey, int id, CallbackInfo ci) { + EntityTypeRegistryImpl.REGISTRY.register(id, legacyKey, type); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinOld.java b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinOld.java new file mode 100644 index 00000000..e762afe4 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/java/net/ornithemc/osl/entities/impl/mixin/common/EntitiesMixinOld.java @@ -0,0 +1,27 @@ +package net.ornithemc.osl.entities.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 com.llamalad7.mixinextras.sugar.Local; + +import net.minecraft.entity.Entities; +import net.minecraft.entity.Entity; + +import net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl; + +@Mixin(Entities.class) +public class EntitiesMixinOld { + + @Inject( + method = "register", + at = @At( + value = "TAIL" + ) + ) + private static void osl$entities$register(CallbackInfo ci, @Local Class type, @Local String legacyKey) { + EntityTypeRegistryImpl.REGISTRY.register(legacyKey, type); + } +} diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/fabric.mod.json b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..18fe41a1 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/fabric.mod.json @@ -0,0 +1,38 @@ +{ + "schemaVersion": 1, + "id": "osl-entities", + "version": "0.1.0+mca1.0.1_01-mc11w48a", + "environment": "*", + "entrypoints": { + "init": [ + "net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init" + ] + }, + "mixins": [ + "osl.entities.mixins.json" + ], + "accessWidener": "osl.entities.classtweaker", + "depends": { + "fabricloader": "\u003e\u003d0.18.0", + "minecraft": "\u003e\u003d1.0.0-alpha.0.1.1 \u003c\u003d1.1-alpha.11.48.a", + "osl-core": "\u003e\u003d0.9.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.10.0", + "osl-networking-impl": "\u003e\u003d0.2.0", + "osl-registries": "\u003e\u003d0.1.0" + }, + "name": "OSL Entities", + "description": "Entities 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/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.classtweaker b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.classtweaker new file mode 100644 index 00000000..331f2be2 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.classtweaker @@ -0,0 +1,7 @@ +classTweaker v1 named + +accessible field net/minecraft/entity/Entities KEY_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_KEY Ljava/util/Map; +accessible field net/minecraft/entity/Entities ID_TO_TYPE Ljava/util/Map; +accessible field net/minecraft/entity/Entities TYPE_TO_ID Ljava/util/Map; + diff --git a/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.mixins.json b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.mixins.json new file mode 100644 index 00000000..6f4295a5 --- /dev/null +++ b/libraries/entities/entities-mca1.0.1_01-mc11w48a/src/main/resources/osl.entities.mixins.json @@ -0,0 +1,19 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "net.ornithemc.osl.entities.impl.mixin", + "compatibilityLevel": "JAVA_8", + "plugin": "net.ornithemc.osl.entities.impl.EntitiesMixinPlugin", + "mixins": [ + "common.EntitiesMixin", + "common.EntitiesMixinNew", + "common.EntitiesMixinOld" + ], + "client": [ + ], + "server": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/libraries/entities/gradle.properties b/libraries/entities/gradle.properties new file mode 100644 index 00000000..aeb2dc27 --- /dev/null +++ b/libraries/entities/gradle.properties @@ -0,0 +1,7 @@ +library_id = entities +library_name = Entities +library_description = Entities API and events. +library_version = 0.1.0 + +entrypoint_init = net.ornithemc.osl.entities.impl.EntityTypeRegistryImpl::init +osl_dependencies = core:0.9.0,entrypoints:0.5.0,registries:0.1.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 87d5b78a..5479e0b7 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,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * 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 87d5b78a..5479e0b7 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,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * 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 87d5b78a..5479e0b7 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,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * 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 87d5b78a..3414b1bd 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 @@ -1,6 +1,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * 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 87d5b78a..3414b1bd 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 @@ -1,6 +1,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * Constructs a registry key with the default namespace and the given identifier. diff --git a/libraries/registries/registries-mc18w43a-mc19w03c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc18w43a-mc19w03c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java index 87d5b78a..3414b1bd 100644 --- a/libraries/registries/registries-mc18w43a-mc19w03c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java +++ b/libraries/registries/registries-mc18w43a-mc19w03c/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java @@ -1,6 +1,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * Constructs a registry key with the default namespace and the given identifier. diff --git a/libraries/registries/registries-mc19w04a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java b/libraries/registries/registries-mc19w04a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java index 87d5b78a..3414b1bd 100644 --- a/libraries/registries/registries-mc19w04a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java +++ b/libraries/registries/registries-mc19w04a-mc1.14.4/src/main/java/net/ornithemc/osl/registries/api/registry/RegistryKeys.java @@ -1,6 +1,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * 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 87d5b78a..5479e0b7 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,7 @@ package net.ornithemc.osl.registries.api.registry; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; import net.minecraft.item.Item; import net.ornithemc.osl.core.api.util.NamespacedIdentifier; @@ -15,6 +16,7 @@ public final class RegistryKeys { public static final ResourceKey> BLOCK = from("block"); public static final ResourceKey> ITEM = from("item"); + public static final ResourceKey>> ENTITY_TYPE = from("entity_type"); /** * Constructs a registry key with the default namespace and the given identifier. diff --git a/settings.gradle b/settings.gradle index e53df069..fd5cd679 100644 --- a/settings.gradle +++ b/settings.gradle @@ -46,6 +46,19 @@ include ':libraries:config:config-mc14w27a-mc15w39c' include ':libraries:config:config-mc15w40a-mc1.12.2' include ':libraries:config:config-mc17w43a-mc1.13.2' +include ':libraries:entities' +include ':libraries:entities:entities-mca1.0.1_01-mc11w48a' +include ':libraries:entities:entities-mc12w01a-mc1.8.2-pre4' +include ':libraries:entities:entities-mc1.8.2-pre5-mc1.10.2' +include ':libraries:entities:entities-mc16w32a-mc18w01a' +include ':libraries:entities:entities-mc18w19a-mc18w31a' +include ':libraries:entities:entities-mc18w32a-mc19w04b' +include ':libraries:entities:entities-mc19w08a-mc1.14.4' + +include ':libraries:entities-rendering' +include ':libraries:entities-rendering:entities-rendering-mca1.0.1_01-mc14w04b' +include ':libraries:entities-rendering:entities-rendering-mc14w05a-mc1.14.4' + include ':libraries:entrypoints' include ':libraries:entrypoints:entrypoints-mcin-20091223-1459-mc1.5.2' include ':libraries:entrypoints:entrypoints-mc13w16a-mc1.14.4'