├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── api ├── build.gradle └── src │ └── main │ └── java │ └── io │ └── github │ └── iltotore │ └── customentity │ ├── CreatureType.java │ ├── util │ ├── UnsupportedSpigotVersionException.java │ ├── ThrowingConsumer.java │ ├── SimpleBinding.java │ ├── SuppliedValue.java │ ├── ReflectUtil.java │ └── ServerVersion.java │ ├── NMSHandler.java │ ├── PersistentEntity.java │ ├── type │ ├── CompositeEntityRoot.java │ ├── DefaultEntityType.java │ ├── CustomEntityRoot.java │ ├── CustomEntityType.java │ └── CompositeEntityType.java │ ├── BukkitSpawnManager.java │ ├── CustomRegistry.java │ ├── HashCustomRegistry.java │ ├── SpawnManager.java │ └── BiomeSpawn.java ├── nms ├── 1_13_R1 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── iltotore │ │ └── customentity │ │ └── v1_13_R1 │ │ ├── NMSHandler.java │ │ ├── example │ │ ├── CustomZombieType.java │ │ └── CustomZombie.java │ │ ├── NMSSpawnManager.java │ │ └── NMSEntityRegistry.java ├── 1_13_R2 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── iltotore │ │ └── customentity │ │ └── v1_13_R2 │ │ ├── NMSHandler.java │ │ ├── example │ │ ├── CustomZombieType.java │ │ └── CustomZombie.java │ │ └── NMSEntityRegistry.java ├── 1_14_R1 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── iltotore │ │ └── customentity │ │ └── v1_14_R1 │ │ ├── example │ │ ├── CustomZombie.java │ │ └── CustomZombieType.java │ │ ├── NMSHandler.java │ │ └── NMSEntityRegistry.java ├── 1_15_R1 │ ├── build.gradle │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── iltotore │ │ └── customentity │ │ └── v1_15_R1 │ │ ├── NMSHandler.java │ │ ├── example │ │ ├── CustomZombieType.java │ │ └── CustomZombie.java │ │ └── NMSEntityRegistry.java └── 1_16_R1 │ ├── build.gradle │ └── src │ └── main │ └── java │ └── io │ └── github │ └── iltotore │ └── customentity │ └── v1_16_R1 │ ├── example │ ├── CustomZombieType.java │ └── CustomZombie.java │ ├── NMSHandler.java │ ├── NMSSpawnManager.java │ └── NMSEntityRegistry.java ├── .gitignore ├── README.md ├── src └── main │ └── java │ └── io │ └── github │ └── iltotore │ └── customentity │ ├── Plugin.java │ ├── CustomEntityAPI.java │ └── example │ └── CustomZombieRoot.java ├── gradlew.bat └── gradlew /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Iltotore/CustomEntityAPI/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'api', 'nms:1_13_R1', 'nms:1_13_R2', 'nms:1_14_R1', 'nms:1_15_R1', 'nms:1_16_R1' 2 | rootProject.name = 'CustomEntityAPI' -------------------------------------------------------------------------------- /api/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigotApi('1.16.1') 5 | } -------------------------------------------------------------------------------- /nms/1_13_R1/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigot('1.13') 5 | implementation project(':api') 6 | } -------------------------------------------------------------------------------- /nms/1_13_R2/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigot('1.13.2') 5 | implementation project(':api') 6 | } -------------------------------------------------------------------------------- /nms/1_14_R1/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigot('1.14.4') 5 | implementation project(':api') 6 | } -------------------------------------------------------------------------------- /nms/1_15_R1/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigot('1.15') 5 | implementation project(':api') 6 | } -------------------------------------------------------------------------------- /nms/1_16_R1/build.gradle: -------------------------------------------------------------------------------- 1 | import static fr.il_totore.manadrop.MinecraftDependencyHelper.* 2 | 3 | dependencies { 4 | compileOnly spigot('1.16.1') 5 | implementation project(':api') 6 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Jul 14 10:07:02 CEST 2020 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/CreatureType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | /** 4 | * The non-NMS equivalent of net.minecraft.server.EnumCreatureType. Used for spawn registering. 5 | */ 6 | public enum CreatureType { 7 | 8 | MONSTER, CREATURE, AMBIENT, WATER_CREATURE, MISC 9 | } 10 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/UnsupportedSpigotVersionException.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | public class UnsupportedSpigotVersionException extends RuntimeException { 4 | 5 | public UnsupportedSpigotVersionException(ServerVersion version){ 6 | super(version.getNMSVersion()); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | /** 4 | * Represent a custom NMS version root. All nms-based components should be only accessible from the asssociated NMSHandler. 5 | */ 6 | public interface NMSHandler { 7 | 8 | /** 9 | * Get the CustomRegistry for the used version. 10 | * @return the CustomRegistry of the used NMS version. 11 | */ 12 | CustomRegistry getRegistry(); 13 | 14 | SpawnManager getSpawnManager(); 15 | } 16 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/ThrowingConsumer.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | import java.util.function.Consumer; 4 | 5 | @FunctionalInterface 6 | public interface ThrowingConsumer extends Consumer { 7 | 8 | @Override 9 | default void accept(T t) { 10 | try { 11 | throwingAccept(t); 12 | } catch(Throwable e){ 13 | throw new RuntimeException(e); 14 | } 15 | } 16 | 17 | void throwingAccept(T t) throws Throwable; 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Project exclude paths 2 | .idea 3 | /.gradle/ 4 | /api/build/ 5 | /api/build/classes/java/main/ 6 | /build/ 7 | /build/classes/java/main/ 8 | /buildSrc/.gradle/ 9 | /buildSrc/build/ 10 | /buildSrc/build/classes/java/main/ 11 | /nms/1_13_R1/build/ 12 | /nms/1_13_R1/build/classes/java/main/ 13 | /nms/1_13_R2/build/ 14 | /nms/1_13_R2/build/classes/java/main/ 15 | /nms/1_14_R1/build/ 16 | /nms/1_14_R1/build/classes/java/main/ 17 | /nms/1_15_R1/build/ 18 | /nms/1_15_R1/build/classes/java/main/ 19 | /nms/1_16_R1/build/ 20 | /nms/1_16_R1/build/classes/java/main/ -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/PersistentEntity.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.entity.Entity; 5 | 6 | /** 7 | * Only used to pass the CustomEntityRoot instance. 8 | */ 9 | public interface PersistentEntity { 10 | 11 | /** 12 | * Pass the given CustomEntityRoot. Should be used for Entity persistence before 1.14. 13 | * @param type the type to pass. 14 | */ 15 | void setCustomType(CustomEntityRoot type); 16 | } 17 | -------------------------------------------------------------------------------- /nms/1_14_R1/src/main/java/io/github/iltotore/customentity/v1_14_R1/example/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_14_R1.example; 2 | 3 | import net.minecraft.server.v1_14_R1.*; 4 | import org.bukkit.Bukkit; 5 | 6 | public class CustomZombie extends EntityZombie{ 7 | 8 | public CustomZombie(EntityTypes entityTypes, World world) { 9 | super(entityTypes, world); 10 | } 11 | 12 | 13 | @Override 14 | public boolean C(Entity entity) { 15 | Bukkit.broadcastMessage("1.14.4 FOREVER"); 16 | return super.C(entity); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /nms/1_13_R1/src/main/java/io/github/iltotore/customentity/v1_13_R1/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R1; 2 | 3 | import io.github.iltotore.customentity.CustomRegistry; 4 | import io.github.iltotore.customentity.SpawnManager; 5 | 6 | public class NMSHandler implements io.github.iltotore.customentity.NMSHandler { 7 | 8 | private CustomRegistry registry = new NMSEntityRegistry(); 9 | 10 | @Override 11 | public CustomRegistry getRegistry() { 12 | return registry; 13 | } 14 | 15 | @Override 16 | public SpawnManager getSpawnManager() { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nms/1_13_R2/src/main/java/io/github/iltotore/customentity/v1_13_R2/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R2; 2 | 3 | import io.github.iltotore.customentity.CustomRegistry; 4 | import io.github.iltotore.customentity.SpawnManager; 5 | 6 | public class NMSHandler implements io.github.iltotore.customentity.NMSHandler { 7 | 8 | private CustomRegistry registry = new NMSEntityRegistry(); 9 | 10 | @Override 11 | public CustomRegistry getRegistry() { 12 | return registry; 13 | } 14 | 15 | @Override 16 | public SpawnManager getSpawnManager() { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nms/1_14_R1/src/main/java/io/github/iltotore/customentity/v1_14_R1/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_14_R1; 2 | 3 | import io.github.iltotore.customentity.CustomRegistry; 4 | import io.github.iltotore.customentity.SpawnManager; 5 | 6 | public class NMSHandler implements io.github.iltotore.customentity.NMSHandler { 7 | 8 | private CustomRegistry registry = new NMSEntityRegistry(); 9 | 10 | @Override 11 | public CustomRegistry getRegistry() { 12 | return registry; 13 | } 14 | 15 | @Override 16 | public SpawnManager getSpawnManager() { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nms/1_15_R1/src/main/java/io/github/iltotore/customentity/v1_15_R1/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_15_R1; 2 | 3 | import io.github.iltotore.customentity.CustomRegistry; 4 | import io.github.iltotore.customentity.SpawnManager; 5 | 6 | public class NMSHandler implements io.github.iltotore.customentity.NMSHandler { 7 | 8 | private CustomRegistry registry = new NMSEntityRegistry(); 9 | 10 | @Override 11 | public CustomRegistry getRegistry() { 12 | return registry; 13 | } 14 | 15 | @Override 16 | public SpawnManager getSpawnManager() { 17 | return null; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /nms/1_13_R1/src/main/java/io/github/iltotore/customentity/v1_13_R1/example/CustomZombieType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R1.example; 2 | 3 | import io.github.iltotore.customentity.type.DefaultEntityType; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Zombie; 6 | 7 | public class CustomZombieType implements DefaultEntityType { 8 | @Override 9 | public int getBaseID(ServerVersion version) { 10 | return 87; 11 | } 12 | 13 | @Override 14 | public Class getNMSClass(ServerVersion version) { 15 | return CustomZombie.class; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nms/1_13_R2/src/main/java/io/github/iltotore/customentity/v1_13_R2/example/CustomZombieType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R2.example; 2 | 3 | import io.github.iltotore.customentity.type.DefaultEntityType; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Zombie; 6 | 7 | public class CustomZombieType implements DefaultEntityType { 8 | @Override 9 | public int getBaseID(ServerVersion version) { 10 | return 87; 11 | } 12 | 13 | @Override 14 | public Class getNMSClass(ServerVersion version) { 15 | return CustomZombie.class; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nms/1_14_R1/src/main/java/io/github/iltotore/customentity/v1_14_R1/example/CustomZombieType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_14_R1.example; 2 | 3 | import io.github.iltotore.customentity.type.DefaultEntityType; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Zombie; 6 | 7 | public class CustomZombieType implements DefaultEntityType { 8 | @Override 9 | public int getBaseID(ServerVersion version) { 10 | return 94; 11 | } 12 | 13 | @Override 14 | public Class getNMSClass(ServerVersion version) { 15 | return CustomZombie.class; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nms/1_15_R1/src/main/java/io/github/iltotore/customentity/v1_15_R1/example/CustomZombieType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_15_R1.example; 2 | 3 | import io.github.iltotore.customentity.type.DefaultEntityType; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Zombie; 6 | 7 | public class CustomZombieType implements DefaultEntityType { 8 | @Override 9 | public int getBaseID(ServerVersion version) { 10 | return 95; 11 | } 12 | 13 | @Override 14 | public Class getNMSClass(ServerVersion version) { 15 | return CustomZombie.class; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /nms/1_16_R1/src/main/java/io/github/iltotore/customentity/v1_16_R1/example/CustomZombieType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_16_R1.example; 2 | 3 | import io.github.iltotore.customentity.type.DefaultEntityType; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Zombie; 6 | 7 | public class CustomZombieType implements DefaultEntityType { 8 | @Override 9 | public int getBaseID(ServerVersion version) { 10 | return 101; 11 | } 12 | 13 | @Override 14 | public Class getNMSClass(ServerVersion version) { 15 | return CustomZombie.class; 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/SimpleBinding.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.entity.Entity; 5 | import org.bukkit.event.entity.CreatureSpawnEvent; 6 | 7 | import java.util.Optional; 8 | import java.util.function.Function; 9 | 10 | public class SimpleBinding { 11 | 12 | public static Function>> apply(Class clazz, CustomEntityRoot root) { 13 | return event -> Optional.of(root) 14 | .filter(r -> clazz.isInstance(event.getEntity())); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/type/CompositeEntityRoot.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.type; 2 | 3 | import org.bukkit.entity.Entity; 4 | 5 | /** 6 | * A root equivalent of the CompositeEntityType. 7 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 8 | */ 9 | public abstract class CompositeEntityRoot extends CompositeEntityType implements CustomEntityRoot { 10 | 11 | private Object handle; 12 | 13 | @Override 14 | public Object getHandle() { 15 | return handle; 16 | } 17 | 18 | @Override 19 | public void setHandle(Object handle) { 20 | this.handle = handle; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /nms/1_16_R1/src/main/java/io/github/iltotore/customentity/v1_16_R1/NMSHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_16_R1; 2 | 3 | import io.github.iltotore.customentity.CustomRegistry; 4 | import io.github.iltotore.customentity.SpawnManager; 5 | 6 | public class NMSHandler implements io.github.iltotore.customentity.NMSHandler { 7 | 8 | private CustomRegistry registry = new NMSEntityRegistry(); 9 | private SpawnManager spawnManager = new NMSSpawnManager(); 10 | 11 | @Override 12 | public CustomRegistry getRegistry() { 13 | return registry; 14 | } 15 | 16 | @Override 17 | public SpawnManager getSpawnManager() { 18 | return spawnManager; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /nms/1_15_R1/src/main/java/io/github/iltotore/customentity/v1_15_R1/example/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_15_R1.example; 2 | 3 | import net.minecraft.server.v1_15_R1.*; 4 | import org.bukkit.Bukkit; 5 | 6 | public class CustomZombie extends EntityZombie { 7 | 8 | private EntityTypes type; 9 | 10 | public CustomZombie(EntityTypes entityTypes, World world) { 11 | super(EntityTypes.ZOMBIE, world); 12 | this.type = entityTypes; 13 | } 14 | 15 | @Override 16 | public boolean B(Entity entity) { 17 | Bukkit.broadcastMessage("1.15 FOREVER"); 18 | return super.B(entity); 19 | } 20 | 21 | 22 | @Override 23 | public EntityTypes getEntityType() { 24 | return type; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/type/DefaultEntityType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.type; 2 | 3 | import io.github.iltotore.customentity.BiomeSpawn; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Entity; 6 | 7 | import java.util.Collection; 8 | import java.util.Collections; 9 | 10 | /** 11 | * A CustomEntityType version where methods are not mandatory. 12 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 13 | */ 14 | public interface DefaultEntityType extends CustomEntityType{ 15 | 16 | @Override 17 | default int getBaseID(ServerVersion version){ 18 | return 0; 19 | } 20 | 21 | @Override 22 | default Collection getSpawns(ServerVersion version) { 23 | return Collections.emptySet(); 24 | } 25 | 26 | @Override 27 | default boolean isVanilla(ServerVersion version) { 28 | return false; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /nms/1_16_R1/src/main/java/io/github/iltotore/customentity/v1_16_R1/example/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_16_R1.example; 2 | 3 | import net.minecraft.server.v1_16_R1.Entity; 4 | import net.minecraft.server.v1_16_R1.EntityTypes; 5 | import net.minecraft.server.v1_16_R1.EntityZombie; 6 | import net.minecraft.server.v1_16_R1.World; 7 | import org.bukkit.Bukkit; 8 | 9 | public class CustomZombie extends EntityZombie { 10 | 11 | private EntityTypes type; 12 | 13 | public CustomZombie(EntityTypes entityTypes, World world) { 14 | super(EntityTypes.ZOMBIE, world); 15 | this.type = entityTypes; 16 | } 17 | 18 | @Override 19 | public boolean attackEntity(Entity entity) { 20 | Bukkit.broadcastMessage("1.16.1 FOREVER"); 21 | return super.attackEntity(entity); 22 | } 23 | 24 | @Override 25 | public EntityTypes getEntityType() { 26 | return type; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/BukkitSpawnManager.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.entity.Entity; 5 | import org.bukkit.event.entity.CreatureSpawnEvent; 6 | 7 | import java.util.Collection; 8 | import java.util.HashSet; 9 | import java.util.Optional; 10 | import java.util.Set; 11 | import java.util.function.Function; 12 | 13 | public abstract class BukkitSpawnManager implements SpawnManager { 14 | 15 | private Set>>> bindings = new HashSet<>(); 16 | 17 | @Override 18 | public void bindSpawnEvent(Function>> binding) { 19 | bindings.add(binding); 20 | } 21 | 22 | @Override 23 | public Collection>>> getBindings() { 24 | return bindings; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CustomEntityAPI 2 | Create custom cross-version entities. 3 | 4 | # Description 5 | CustomEntityAPI is a Spigot API extension allowing developers to create and spawn custom entities without 6 | worrying about the server version. 7 | 8 | # Features 9 | CustomEntityAPI includes: 10 | - Custom entity creation 11 | - NMS Support from 1.13 to 1.16.2 12 | - Custom entity persistence during restart 13 | - Custom entity behavior 14 | - Custom natural spawn selection 15 | 16 | See the [wiki](https://github.com/Iltotore/CustomEntityAPI/wiki) for more information. 17 | 18 | # Installation 19 | ## Developers 20 | You can import the library using the [release jar](https://github.com/CustomEntityAPI/releases) or a build tool like Gradle: 21 | ```gradle 22 | repositories { 23 | mavenCentral() 24 | } 25 | 26 | dependencies { 27 | implementation 'io.github.iltotore:customentity:version' 28 | } 29 | ``` 30 | 31 | ## Server 32 | You need to add the [release jar](https://github.com/CustomEntityAPI/releases) to your plugins. 33 | -------------------------------------------------------------------------------- /src/main/java/io/github/iltotore/customentity/Plugin.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.example.CustomZombieRoot; 4 | import org.bukkit.event.EventHandler; 5 | import org.bukkit.event.Listener; 6 | import org.bukkit.event.entity.CreatureSpawnEvent; 7 | import org.bukkit.plugin.java.JavaPlugin; 8 | 9 | public class Plugin extends JavaPlugin implements Listener { 10 | 11 | @Override 12 | public void onLoad() { 13 | getLogger().info("Registering entities..."); 14 | CustomEntityAPI.getAPI().getRegistry().register(new CustomZombieRoot()); //This is the example entity: a zombie saying " forever" when attacking. 15 | 16 | } 17 | 18 | @Override 19 | public void onEnable() { 20 | getServer().getPluginManager().registerEvents(this, this); 21 | } 22 | 23 | @EventHandler 24 | public void onSpawn(CreatureSpawnEvent event){ 25 | CustomEntityAPI.getAPI().getSpawnManager().onSpawn(event); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/type/CustomEntityRoot.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.type; 2 | 3 | import io.github.iltotore.customentity.CreatureType; 4 | import org.bukkit.entity.Entity; 5 | 6 | /** 7 | * Represent the root of a CustomEntityType. 8 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 9 | */ 10 | public interface CustomEntityRoot extends CustomEntityType { 11 | 12 | /** 13 | * Get the key of the vanilla mob. 14 | * @return the vanilla base's key. 15 | */ 16 | String getBaseKey(); 17 | 18 | /** 19 | * Get the new entity type's key. 20 | * @return the custom type's key, usable in /summon. 21 | */ 22 | String getKey(); 23 | 24 | /** 25 | * Get the entity's CreatureType. 26 | * @return the entity's CreatureType. Used to register spawns. 27 | */ 28 | CreatureType getCreatureType(); 29 | 30 | Object getHandle(); 31 | void setHandle(Object handle); 32 | } 33 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/CustomRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.entity.Entity; 5 | 6 | import java.util.Optional; 7 | 8 | public interface CustomRegistry { 9 | 10 | /** 11 | * Register the given entity type's root. 12 | * @param type the CustomEntityRoot to register. 13 | */ 14 | void register(CustomEntityRoot type); 15 | 16 | /** 17 | * Remove the desired entity type's root. 18 | * @param key the key used to retrieve the root to remove. 19 | */ 20 | void unregister(String key); 21 | 22 | /** 23 | * Get the CustomEntityRoot using the given key. 24 | * @param key the key of the desired CustomEntityRoot. 25 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 26 | * @return an Optional wrapping the possible CustomEntityRoot. 27 | */ 28 | Optional> getEntityType(String key); 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/HashCustomRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.entity.Entity; 5 | 6 | import java.util.HashSet; 7 | import java.util.Optional; 8 | import java.util.Set; 9 | 10 | public abstract class HashCustomRegistry implements CustomRegistry { 11 | 12 | private Set> registry = new HashSet<>(); 13 | 14 | @Override 15 | public void register(CustomEntityRoot type) { 16 | applyRegister(type); 17 | registry.add(type); 18 | } 19 | 20 | @Override 21 | public void unregister(String key) { 22 | registry.removeIf(type -> type.getKey().equals(key)); 23 | } 24 | 25 | @Override 26 | public Optional> getEntityType(String key) { 27 | return registry.stream().filter(type -> type.getKey().equals(key)).findAny(); 28 | } 29 | 30 | protected abstract void applyRegister(CustomEntityRoot type); 31 | } -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/SuppliedValue.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | import java.util.Optional; 4 | import java.util.function.Consumer; 5 | import java.util.function.Supplier; 6 | 7 | public class SuppliedValue implements Supplier> { 8 | 9 | private Supplier supplier; 10 | private Optional value = Optional.empty(); 11 | 12 | private SuppliedValue(Supplier supplier) { 13 | this.supplier = supplier; 14 | } 15 | 16 | @Override 17 | public Optional get() { 18 | if(!value.isPresent()) value = Optional.ofNullable(supplier.get()); 19 | return value; 20 | } 21 | 22 | public static SuppliedValue of(Supplier supplier){ 23 | return new SuppliedValue<>(supplier); 24 | } 25 | 26 | public static SuppliedValue of(Supplier supplier, Consumer sideEffect){ 27 | return of(() -> { 28 | T t = supplier.get(); 29 | sideEffect.accept(t); 30 | return t; 31 | }); 32 | } 33 | 34 | public static SuppliedValue empty(){ 35 | return new SuppliedValue<>(() -> null); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /nms/1_13_R1/src/main/java/io/github/iltotore/customentity/v1_13_R1/example/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R1.example; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import io.github.iltotore.customentity.PersistentEntity; 5 | import net.minecraft.server.v1_13_R1.Entity; 6 | import net.minecraft.server.v1_13_R1.EntityTypes; 7 | import net.minecraft.server.v1_13_R1.EntityZombie; 8 | import net.minecraft.server.v1_13_R1.World; 9 | import org.bukkit.Bukkit; 10 | 11 | public class CustomZombie extends EntityZombie implements PersistentEntity { 12 | 13 | private CustomEntityRoot type; 14 | 15 | public CustomZombie(World world) { 16 | super(world); 17 | } 18 | 19 | 20 | @Override 21 | public boolean B(Entity entity) { 22 | Bukkit.broadcastMessage("1.13 FOREVER !"); 23 | return super.B(entity); 24 | } 25 | 26 | @Override 27 | public void setCustomType(CustomEntityRoot type) { 28 | this.type = type; 29 | } 30 | 31 | @Override 32 | public EntityTypes P() { 33 | return (EntityTypes) type.getHandle(); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /nms/1_13_R2/src/main/java/io/github/iltotore/customentity/v1_13_R2/example/CustomZombie.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R2.example; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import io.github.iltotore.customentity.PersistentEntity; 5 | import net.minecraft.server.v1_13_R2.Entity; 6 | import net.minecraft.server.v1_13_R2.EntityTypes; 7 | import net.minecraft.server.v1_13_R2.EntityZombie; 8 | import net.minecraft.server.v1_13_R2.World; 9 | import org.bukkit.Bukkit; 10 | 11 | public class CustomZombie extends EntityZombie implements PersistentEntity { 12 | 13 | private CustomEntityRoot type; 14 | 15 | public CustomZombie(World world) { 16 | super(world); 17 | } 18 | 19 | 20 | @Override 21 | public boolean B(Entity entity) { 22 | Bukkit.broadcastMessage("1.13.2 FOREVER !"); 23 | return super.B(entity); 24 | } 25 | 26 | @Override 27 | public void setCustomType(CustomEntityRoot type) { 28 | this.type = type; 29 | } 30 | 31 | @Override 32 | public EntityTypes P() { 33 | return (EntityTypes) type.getHandle(); 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/SpawnManager.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.type.CustomEntityRoot; 4 | import org.bukkit.Location; 5 | import org.bukkit.entity.Entity; 6 | import org.bukkit.event.entity.CreatureSpawnEvent; 7 | 8 | import java.util.Collection; 9 | import java.util.Optional; 10 | import java.util.function.Function; 11 | 12 | public interface SpawnManager { 13 | 14 | Optional spawn(CustomEntityRoot type, Location location); 15 | 16 | void bindSpawnEvent(Function>> binding); 17 | 18 | Collection>>> getBindings(); 19 | 20 | default Optional> retrieve(CreatureSpawnEvent event) { 21 | return getBindings().stream() 22 | .map(function -> function.apply(event)) 23 | .filter(Optional::isPresent) 24 | .findAny().orElseGet(Optional::empty); 25 | } 26 | 27 | default void onSpawn(CreatureSpawnEvent event){ 28 | retrieve(event).ifPresent(type -> { 29 | event.setCancelled(true); 30 | spawn(type, event.getLocation()); 31 | }); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/ReflectUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | import java.lang.reflect.Field; 4 | import java.lang.reflect.Modifier; 5 | 6 | public class ReflectUtil { 7 | 8 | private static Field MODIFIER_FIELD; 9 | 10 | static { 11 | try { 12 | MODIFIER_FIELD = Field.class.getDeclaredField("modifiers"); 13 | MODIFIER_FIELD.setAccessible(true); 14 | } catch(NoSuchFieldException e) { 15 | e.printStackTrace(); 16 | } 17 | } 18 | 19 | /** 20 | * Change the field modifier 21 | * @param field the Field to edit. 22 | * @param modifiers the new modifier. 23 | */ 24 | public static void setFieldModifier(Field field, int modifiers){ 25 | try { 26 | MODIFIER_FIELD.setInt(field, modifiers); 27 | } catch(IllegalAccessException e) { 28 | e.printStackTrace(); 29 | } 30 | } 31 | 32 | /** 33 | * Set the given Field's final property. 34 | * @param field the Field to edit. 35 | * @param isFinal true to make the Field final. False otherwise. 36 | */ 37 | public static void setFinal(Field field, boolean isFinal){ 38 | setFieldModifier(field, field.getModifiers() & (isFinal ? Modifier.FINAL : ~Modifier.FINAL)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /nms/1_13_R1/src/main/java/io/github/iltotore/customentity/v1_13_R1/NMSSpawnManager.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R1; 2 | 3 | import io.github.iltotore.customentity.BukkitSpawnManager; 4 | import io.github.iltotore.customentity.type.CustomEntityRoot; 5 | import net.minecraft.server.v1_13_R1.EntityTypes; 6 | import net.minecraft.server.v1_13_R1.MinecraftKey; 7 | import net.minecraft.server.v1_13_R1.World; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_13_R1.CraftWorld; 10 | import org.bukkit.entity.Entity; 11 | import org.bukkit.event.entity.CreatureSpawnEvent; 12 | 13 | import java.util.Optional; 14 | 15 | public class NMSSpawnManager extends BukkitSpawnManager { 16 | 17 | @Override 18 | @SuppressWarnings("unchecked") 19 | public Optional spawn(CustomEntityRoot type, Location location) { 20 | World nmsWorld = ((CraftWorld)location.getWorld()).getHandle(); 21 | net.minecraft.server.v1_13_R1.Entity nmsEntity = EntityTypes.a(nmsWorld, MinecraftKey.a(type.getKey())); 22 | if(nmsEntity == null) return Optional.empty(); 23 | nmsEntity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); 24 | nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM); 25 | return (Optional) Optional.of(nmsEntity.getBukkitEntity()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /nms/1_16_R1/src/main/java/io/github/iltotore/customentity/v1_16_R1/NMSSpawnManager.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_16_R1; 2 | 3 | 4 | import io.github.iltotore.customentity.BukkitSpawnManager; 5 | import io.github.iltotore.customentity.type.CustomEntityRoot; 6 | import net.minecraft.server.v1_16_R1.EntityTypes; 7 | import net.minecraft.server.v1_16_R1.World; 8 | import org.bukkit.Location; 9 | import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; 10 | import org.bukkit.entity.Entity; 11 | import org.bukkit.event.entity.CreatureSpawnEvent; 12 | 13 | import java.util.Optional; 14 | 15 | public class NMSSpawnManager extends BukkitSpawnManager { 16 | 17 | @Override 18 | @SuppressWarnings("unchecked") 19 | public Optional spawn(CustomEntityRoot type, Location location) { 20 | World nmsWorld = ((CraftWorld) location.getWorld()).getHandle(); 21 | Optional nmsEntity = EntityTypes.a(type.getKey()) 22 | .map(nmsType -> nmsType.a(nmsWorld)); 23 | nmsEntity.ifPresent(entity -> { 24 | entity.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); 25 | nmsWorld.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM); 26 | }); 27 | return (Optional) nmsEntity.map(net.minecraft.server.v1_16_R1.Entity::getBukkitEntity); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/io/github/iltotore/customentity/CustomEntityAPI.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import io.github.iltotore.customentity.util.ServerVersion; 4 | import org.bukkit.Bukkit; 5 | 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | import java.util.TreeMap; 9 | import java.util.function.Supplier; 10 | 11 | public class CustomEntityAPI { 12 | 13 | private static NMSHandler api; 14 | private static Map> versions = new HashMap<>(); 15 | 16 | static { 17 | versions.put(ServerVersion.v1_13, io.github.iltotore.customentity.v1_13_R1.NMSHandler::new); 18 | versions.put(ServerVersion.v1_13_2, io.github.iltotore.customentity.v1_13_R2.NMSHandler::new); 19 | versions.put(ServerVersion.v1_14, io.github.iltotore.customentity.v1_14_R1.NMSHandler::new); 20 | versions.put(ServerVersion.v1_15, io.github.iltotore.customentity.v1_15_R1.NMSHandler::new); 21 | versions.put(ServerVersion.v1_16_1, io.github.iltotore.customentity.v1_16_R1.NMSHandler::new); 22 | } 23 | 24 | /** 25 | * Get the {@link NMSHandler} instance. 26 | * 27 | * @return the {@link NMSHandler} instance for the server's version 28 | */ 29 | public static NMSHandler getAPI(){ 30 | if(api == null){ 31 | ServerVersion version = ServerVersion.fromServer(Bukkit.getServer()); 32 | Bukkit.getLogger().info("[CustomEntityAPI] Loading version " + version.getNMSVersion()); 33 | api = versions.get(version).get(); 34 | } 35 | return api; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/type/CustomEntityType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.type; 2 | 3 | import io.github.iltotore.customentity.BiomeSpawn; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import org.bukkit.entity.Entity; 6 | 7 | import java.util.Collection; 8 | 9 | /** 10 | * A CustomEntityType represents information about mob id, appearance, and spawning. 11 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 12 | */ 13 | public interface CustomEntityType { 14 | 15 | /** 16 | * Get the overrode mob's numerical id. 17 | * @param version the version of the server. 18 | * @return the overrode mob's id depending of the current version. 19 | */ 20 | int getBaseID(ServerVersion version); 21 | 22 | /** 23 | * Get the custom entity class. 24 | * @param version the version of the server. 25 | * @return the custom entity NMS class depending of the current version. 26 | */ 27 | Class getNMSClass(ServerVersion version); 28 | 29 | /** 30 | * Get the spawn information. 31 | * @param version the version of the server. 32 | * @return a Collection of spawn information depending of the current version. 33 | */ 34 | Collection getSpawns(ServerVersion version); 35 | 36 | /** 37 | * Check if the custom entity should replace its vanilla base. 38 | * @param version the version of the server. 39 | * @return true if this custom entity should override vanilla spawns. 40 | */ 41 | boolean isVanilla(ServerVersion version); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/io/github/iltotore/customentity/example/CustomZombieRoot.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.example; 2 | 3 | import io.github.iltotore.customentity.BiomeSpawn; 4 | import io.github.iltotore.customentity.CreatureType; 5 | import io.github.iltotore.customentity.type.CompositeEntityRoot; 6 | import io.github.iltotore.customentity.util.ServerVersion; 7 | import org.bukkit.block.Biome; 8 | import org.bukkit.entity.Zombie; 9 | 10 | import java.util.Collection; 11 | import java.util.Collections; 12 | 13 | public class CustomZombieRoot extends CompositeEntityRoot { 14 | 15 | { 16 | setVersion(ServerVersion.v1_13, io.github.iltotore.customentity.v1_13_R1.example.CustomZombieType::new); 17 | setVersion(ServerVersion.v1_13_2, io.github.iltotore.customentity.v1_13_R2.example.CustomZombieType::new); 18 | setVersion(ServerVersion.v1_14, io.github.iltotore.customentity.v1_14_R1.example.CustomZombieType::new); 19 | setVersion(ServerVersion.v1_15, io.github.iltotore.customentity.v1_15_R1.example.CustomZombieType::new); 20 | setVersion(ServerVersion.v1_16_1, io.github.iltotore.customentity.v1_16_R1.example.CustomZombieType::new); 21 | } 22 | 23 | @Override 24 | public String getBaseKey() { 25 | return "zombie"; 26 | } 27 | 28 | @Override 29 | public String getKey() { 30 | return "custom_zombie"; 31 | } 32 | 33 | @Override 34 | public CreatureType getCreatureType() { 35 | return CreatureType.MONSTER; 36 | } 37 | 38 | @Override 39 | public boolean isVanilla(ServerVersion version) { 40 | return false; 41 | } 42 | 43 | @Override 44 | public Collection getSpawns(ServerVersion version) { 45 | return Collections.singleton( 46 | BiomeSpawn.builder() 47 | .in(Biome.THE_END, Biome.END_HIGHLANDS) 48 | .weighing(100) 49 | .withMaximum(4) 50 | .build() 51 | ); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/type/CompositeEntityType.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.type; 2 | 3 | import io.github.iltotore.customentity.BiomeSpawn; 4 | import io.github.iltotore.customentity.util.ServerVersion; 5 | import io.github.iltotore.customentity.util.SuppliedValue; 6 | import io.github.iltotore.customentity.util.UnsupportedSpigotVersionException; 7 | import org.bukkit.entity.Entity; 8 | 9 | import java.util.Collection; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.Optional; 13 | import java.util.function.Supplier; 14 | 15 | /** 16 | * A CompositeEntityType is a proxy for a CustomEntityType child by its version. 17 | * @param the Bukkit entity equivalent. Used to spawn the mob trough the API. 18 | */ 19 | public abstract class CompositeEntityType implements CustomEntityType { 20 | 21 | private Map>> children = new HashMap<>(); 22 | 23 | /** 24 | * Associate a child with the given version. 25 | * @param version the version used to retrieve the associated CustomEntityType. 26 | * @param type the custom child to associate with the given version. 27 | */ 28 | protected void setVersion(ServerVersion version, Supplier> type){ 29 | children.put(version, SuppliedValue.of(type)); 30 | } 31 | 32 | /** 33 | * Get the type child using the given version. 34 | * @param version the ServerVersion used to find the child CustomEntityType. 35 | * @return an Optional wrapping the possible returned CustomEntityType. 36 | */ 37 | public Optional> getType(ServerVersion version){ 38 | return children.getOrDefault(version, SuppliedValue.empty()).get(); 39 | } 40 | 41 | /** 42 | * Get the type child using the given version if exists. Throws an UnsupportedSpigotVersionException otherwise. 43 | * @param version the ServerVersion used to find the child CustomEntityType. 44 | * @return an Optional wrapping the possible returned CustomEntityType. 45 | */ 46 | public CustomEntityType getRawType(ServerVersion version){ 47 | return getType(version).orElseThrow(() -> new UnsupportedSpigotVersionException(version)); 48 | } 49 | 50 | @Override 51 | public int getBaseID(ServerVersion version) { 52 | return getRawType(version).getBaseID(version); 53 | } 54 | 55 | @Override 56 | public Class getNMSClass(ServerVersion version) { 57 | return getRawType(version).getNMSClass(version); 58 | } 59 | 60 | @Override 61 | public Collection getSpawns(ServerVersion version) { 62 | return getRawType(version).getSpawns(version); 63 | } 64 | 65 | @Override 66 | public boolean isVanilla(ServerVersion version) { 67 | return getRawType(version).isVanilla(version); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/BiomeSpawn.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity; 2 | 3 | import org.bukkit.block.Biome; 4 | 5 | import java.util.*; 6 | 7 | public class BiomeSpawn { 8 | 9 | private final Biome[] biomes; 10 | private final int weight, min, max; 11 | 12 | /** 13 | * Create a BiomeSpawn using the given spawn infos. 14 | * @see #builder() 15 | * @param biomes the biomes where spawning is possible. 16 | * @param weight the weight used in the randomized spawn. A better weight will increase the spawn chances over other mobs. 17 | * @param min the minimal number of mobs created by a single spawn. 18 | * @param max the maximal number of mobs created by a single spawn. 19 | */ 20 | public BiomeSpawn(Biome[] biomes, int weight, int min, int max) { 21 | this.biomes = biomes; 22 | this.weight = weight; 23 | this.min = min; 24 | this.max = max; 25 | } 26 | 27 | public Biome[] getBiomes() { 28 | return biomes; 29 | } 30 | 31 | public int getWeight() { 32 | return weight; 33 | } 34 | 35 | public int getMin() { 36 | return min; 37 | } 38 | 39 | public int getMax() { 40 | return max; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object o) { 45 | if(this == o) return true; 46 | if(!(o instanceof BiomeSpawn)) return false; 47 | BiomeSpawn that = (BiomeSpawn) o; 48 | return weight == that.weight && 49 | min == that.min && 50 | max == that.max && 51 | Arrays.equals(biomes, that.biomes); 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | int result = Objects.hash(weight, min, max); 57 | result = 31 * result + Arrays.hashCode(biomes); 58 | return result; 59 | } 60 | 61 | public static Builder builder(){ 62 | return new Builder(); 63 | } 64 | 65 | public static class Builder { 66 | 67 | private Set biomes = new HashSet<>(); 68 | private int weight, min = 1, max = 1; 69 | 70 | public Builder in(Collection biomes) { 71 | this.biomes.addAll(biomes); 72 | return this; 73 | } 74 | 75 | public Builder in(Biome... biomes) { 76 | return in(Arrays.asList(biomes)); 77 | } 78 | 79 | public Builder weighing(int weight) { 80 | this.weight = weight; 81 | return this; 82 | } 83 | 84 | public Builder withMinimum(int min) { 85 | this.min = min; 86 | return this; 87 | } 88 | 89 | public Builder withMaximum(int max){ 90 | this.max = max; 91 | return this; 92 | } 93 | 94 | public BiomeSpawn build(){ 95 | return new BiomeSpawn(biomes.toArray(new Biome[]{}), weight, min, max); 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /api/src/main/java/io/github/iltotore/customentity/util/ServerVersion.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.util; 2 | 3 | import org.bukkit.Server; 4 | 5 | public class ServerVersion implements Comparable { 6 | 7 | private String nmsVersion; 8 | 9 | /** 10 | * Create a new {@link ServerVersion} with the given NMS version 11 | * 12 | * @param nmsVersion the given NMS version with this pattern: 1_version_RreleaseVersion 13 | */ 14 | public ServerVersion(String nmsVersion){ 15 | this.nmsVersion = nmsVersion; 16 | } 17 | 18 | public String getNMSVersion(){ 19 | return nmsVersion; 20 | } 21 | 22 | @Override 23 | public int compareTo(ServerVersion o){ 24 | return doubleValue().compareTo(o.doubleValue()); 25 | } 26 | 27 | @Override 28 | public boolean equals(Object obj){ 29 | if(!(obj instanceof ServerVersion)) return false; 30 | return ((ServerVersion) obj).doubleValue().equals(doubleValue()); 31 | } 32 | 33 | @Override 34 | public int hashCode(){ 35 | return doubleValue().hashCode(); 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "ServerVersion{" + 41 | "nmsVersion='" + nmsVersion + '\'' + 42 | '}'; 43 | } 44 | 45 | /** 46 | * Get the NMS version as Double 47 | * @return the NMS version with this pattern: 1.version and release version. Example: 1_14_R1 → 1.141 48 | */ 49 | public Double doubleValue(){ 50 | return Double.parseDouble(nmsVersion.replaceFirst("_", ".").replace("_R", "").substring(1)); 51 | } 52 | 53 | /** 54 | * Get the {@link ServerVersion} from the Bukkit server 55 | * @param server the server instance 56 | * @return the {@link ServerVersion} created from the server's NMS version 57 | */ 58 | public static ServerVersion fromServer(Server server){ 59 | return new ServerVersion(server.getClass().getPackage().getName().split("\\.")[3]); 60 | } 61 | 62 | public static final ServerVersion v1_8 = new ServerVersion("v1_8_R1"); 63 | public static final ServerVersion v1_8_3 = new ServerVersion("v1_8_R2"); 64 | public static final ServerVersion v1_8_4 = new ServerVersion("v1_8_R3"); 65 | public static final ServerVersion v1_8_5 = new ServerVersion("v1_8_R3"); 66 | public static final ServerVersion v1_8_6 = new ServerVersion("v1_8_R3"); 67 | public static final ServerVersion v1_8_7 = new ServerVersion("v1_8_R3"); 68 | public static final ServerVersion v1_8_8 = new ServerVersion("v1_8_R3"); 69 | public static final ServerVersion v1_8_9 = new ServerVersion("v1_8_R3"); 70 | 71 | public static final ServerVersion v1_9 = new ServerVersion("v1_9_R1"); 72 | public static final ServerVersion v1_9_1 = new ServerVersion("v1_9_R1"); 73 | public static final ServerVersion v1_9_2 = new ServerVersion("v1_9_R1"); 74 | public static final ServerVersion v1_9_4 = new ServerVersion("v1_9_R2"); 75 | 76 | public static final ServerVersion v1_10 = new ServerVersion("v1_10_R1"); 77 | public static final ServerVersion v1_10_1 = new ServerVersion("v1_10_R1"); 78 | public static final ServerVersion v1_10_2 = new ServerVersion("v1_10_R1"); 79 | 80 | public static final ServerVersion v1_11 = new ServerVersion("v1_11_R1"); 81 | public static final ServerVersion v1_11_1 = new ServerVersion("v1_11_R1"); 82 | public static final ServerVersion v1_11_2 = new ServerVersion("v1_11_R1"); 83 | 84 | public static final ServerVersion v1_12 = new ServerVersion("v1_12_R1"); 85 | public static final ServerVersion v1_12_1 = new ServerVersion("v1_12_R1"); 86 | public static final ServerVersion v1_12_2 = new ServerVersion("v1_12_R1"); 87 | 88 | public static final ServerVersion v1_13 = new ServerVersion("v1_13_R1"); 89 | public static final ServerVersion v1_13_1 = new ServerVersion("v1_13_R2"); 90 | public static final ServerVersion v1_13_2 = new ServerVersion("v1_13_R2"); 91 | 92 | public static final ServerVersion v1_14 = new ServerVersion("v1_14_R1"); 93 | public static final ServerVersion v1_14_1 = new ServerVersion("v1_14_R1"); 94 | public static final ServerVersion v1_14_2 = new ServerVersion("v1_14_R1"); 95 | public static final ServerVersion v1_14_3 = new ServerVersion("v1_14_R1"); 96 | public static final ServerVersion v1_14_4 = new ServerVersion("v1_14_R1"); 97 | public static final ServerVersion v1_15 = new ServerVersion("v1_15_R1"); 98 | 99 | public static final ServerVersion v1_16_1 = new ServerVersion("v1_16_R1"); 100 | } 101 | -------------------------------------------------------------------------------- /nms/1_13_R2/src/main/java/io/github/iltotore/customentity/v1_13_R2/NMSEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R2; 2 | 3 | import com.mojang.datafixers.DataFixUtils; 4 | import com.mojang.datafixers.types.Type; 5 | import io.github.iltotore.customentity.BiomeSpawn; 6 | import io.github.iltotore.customentity.type.CustomEntityRoot; 7 | import io.github.iltotore.customentity.HashCustomRegistry; 8 | import io.github.iltotore.customentity.PersistentEntity; 9 | import io.github.iltotore.customentity.util.ReflectUtil; 10 | import io.github.iltotore.customentity.util.ServerVersion; 11 | import net.minecraft.server.v1_13_R2.*; 12 | import org.apache.commons.lang.Validate; 13 | import org.bukkit.block.Biome; 14 | import org.bukkit.entity.Entity; 15 | 16 | import java.lang.reflect.Constructor; 17 | import java.lang.reflect.Field; 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | import java.util.function.Function; 23 | import java.util.stream.Stream; 24 | 25 | public class NMSEntityRegistry extends HashCustomRegistry { 26 | 27 | private Map, Object> positionMap = null; 28 | private Field biomeEntityType; 29 | 30 | @SuppressWarnings("unchecked") 31 | public NMSEntityRegistry() { 32 | try { 33 | Field field = EntityPositionTypes.class.getDeclaredField("a"); 34 | field.setAccessible(true); 35 | this.positionMap = (Map, Object>) field.get(null); 36 | 37 | biomeEntityType = BiomeBase.BiomeMeta.class.getDeclaredField("b"); 38 | ReflectUtil.setFinal(biomeEntityType, false); 39 | } catch(NoSuchFieldException | IllegalAccessException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | 45 | @Override 46 | @SuppressWarnings("unchecked") 47 | public void applyRegister(CustomEntityRoot type) { 48 | //Creating a minecraft key with the name 49 | MinecraftKey baseKey = MinecraftKey.a(type.getBaseKey()); 50 | MinecraftKey minecraftKey = MinecraftKey.a(type.getKey()); 51 | Validate.notNull(minecraftKey, "Using an invalid name for registering a custom entity. Name: " + type.getKey()); 52 | 53 | if(IRegistry.ENTITY_TYPE.c(minecraftKey)) 54 | throw new IllegalArgumentException("Entity with key " + type.getKey() + " already exists !"); 55 | 56 | //Getting the data converter type for the default entity and adding that to the custom mob. 57 | Map> typeMap = (Map>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(1628)).findChoiceType(DataConverterTypes.n).types(); 58 | typeMap.put(minecraftKey.toString(), typeMap.get(baseKey)); 59 | try { 60 | Constructor constructor = (Constructor) type.getNMSClass(ServerVersion.v1_13_2).getConstructor(World.class); 61 | 62 | 63 | Function nmsCreator = world -> { 64 | EntityInsentient entity = null; 65 | try { 66 | entity = constructor.newInstance(world); 67 | } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { 68 | e.printStackTrace(); 69 | } 70 | if(entity instanceof PersistentEntity) ((PersistentEntity) entity).setCustomType(type); 71 | return entity; 72 | }; 73 | 74 | EnumCreatureType nmsCreatureType = EnumCreatureType.valueOf(type.getCreatureType().name()); 75 | 76 | EntityTypes customEntityNMSEntityType = EntityTypes.a.a((Class) type.getNMSClass(ServerVersion.v1_13_2), nmsCreator) 77 | .a(type.getKey()); 78 | 79 | IRegistry.ENTITY_TYPE.a(type.getBaseID(ServerVersion.v1_13_2), minecraftKey, customEntityNMSEntityType); 80 | 81 | //Is an insentient entity? Also copy the EntityPositionTypes value. 82 | if(type.getNMSClass(ServerVersion.v1_13_2).isAssignableFrom(EntityInsentient.class)) { 83 | Object entityInformation = positionMap.get(customEntityNMSEntityType); 84 | positionMap.put(customEntityNMSEntityType, entityInformation); 85 | } 86 | 87 | type.setHandle(customEntityNMSEntityType); 88 | if(type.isVanilla(ServerVersion.v1_13_2)) 89 | overrideSpawn(EnumCreatureType.valueOf(type.getCreatureType().name()), baseKey, customEntityNMSEntityType); 90 | 91 | for(BiomeSpawn spawn : type.getSpawns(ServerVersion.v1_16_1)) 92 | registerSpawn(nmsCreatureType, customEntityNMSEntityType, spawn); 93 | 94 | } catch(NoSuchMethodException e) { 95 | throw new RuntimeException(e); 96 | } 97 | } 98 | 99 | private void registerSpawn(EnumCreatureType creatureType, EntityTypes customType, BiomeSpawn spawn) { 100 | Stream.of(spawn.getBiomes()) 101 | .map(Biome::name) 102 | .map(String::toLowerCase) 103 | .map(MinecraftKey::a) 104 | .map(IRegistry.BIOME::get) 105 | .filter(Objects::nonNull) 106 | .forEach(biomeBase -> { 107 | List meta = biomeBase.getMobs(creatureType); 108 | if(meta == null) return; 109 | meta.add(new BiomeBase.BiomeMeta(customType, spawn.getWeight(), spawn.getMin(), spawn.getMax())); 110 | }); 111 | } 112 | 113 | @SuppressWarnings("unchecked") 114 | private void overrideSpawn(EnumCreatureType creatureType, MinecraftKey baseKey, EntityTypes customType) { 115 | IRegistry.BIOME.f() 116 | .map(biomeBase -> biomeBase.getMobs(creatureType)) 117 | .filter(Objects::nonNull) 118 | .flatMap(List::stream) 119 | .filter(meta -> Objects.equals(IRegistry.ENTITY_TYPE.getKey(meta.b), baseKey)) 120 | .forEach(meta -> meta.b = (EntityTypes) customType); 121 | } 122 | } -------------------------------------------------------------------------------- /nms/1_14_R1/src/main/java/io/github/iltotore/customentity/v1_14_R1/NMSEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_14_R1; 2 | 3 | import com.mojang.datafixers.DataFixUtils; 4 | import com.mojang.datafixers.types.Type; 5 | import io.github.iltotore.customentity.BiomeSpawn; 6 | import io.github.iltotore.customentity.type.CustomEntityRoot; 7 | import io.github.iltotore.customentity.HashCustomRegistry; 8 | import io.github.iltotore.customentity.util.ReflectUtil; 9 | import io.github.iltotore.customentity.util.ServerVersion; 10 | import io.github.iltotore.customentity.util.ThrowingConsumer; 11 | import net.minecraft.server.v1_14_R1.*; 12 | import org.apache.commons.lang.Validate; 13 | import org.bukkit.block.Biome; 14 | import org.bukkit.entity.Entity; 15 | 16 | import java.lang.reflect.Constructor; 17 | import java.lang.reflect.Field; 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | import java.util.stream.Stream; 23 | 24 | public class NMSEntityRegistry extends HashCustomRegistry { 25 | 26 | private Map, Object> positionMap = null; 27 | private Field biomeEntityType; 28 | 29 | @SuppressWarnings("unchecked") 30 | public NMSEntityRegistry() { 31 | try { 32 | Field field = EntityPositionTypes.class.getDeclaredField("a"); 33 | field.setAccessible(true); 34 | this.positionMap = (Map, Object>) field.get(null); 35 | 36 | biomeEntityType = BiomeBase.BiomeMeta.class.getDeclaredField("b"); 37 | ReflectUtil.setFinal(biomeEntityType, false); 38 | } catch(NoSuchFieldException | IllegalAccessException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | 44 | @Override 45 | @SuppressWarnings("unchecked") 46 | public void applyRegister(CustomEntityRoot type) { 47 | //Creating a minecraft key with the name 48 | MinecraftKey baseKey = MinecraftKey.a(type.getBaseKey()); 49 | MinecraftKey minecraftKey = MinecraftKey.a(type.getKey()); 50 | Validate.notNull(minecraftKey, "Using an invalid name for registering a custom entity. Name: " + type.getKey()); 51 | 52 | if(IRegistry.ENTITY_TYPE.getOptional(minecraftKey).isPresent()) 53 | throw new IllegalArgumentException("Entity with key " + type.getKey() + " already exists !"); 54 | 55 | //Getting the data converter type for the default entity and adding that to the custom mob. 56 | Map> typeMap = (Map>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(DataFixUtils.makeKey(SharedConstants.a().getWorldVersion()))).findChoiceType(DataConverterTypes.ENTITY).types(); 57 | typeMap.put(minecraftKey.toString(), typeMap.get(baseKey)); 58 | try { 59 | Constructor constructor = (Constructor) type.getNMSClass(ServerVersion.v1_14).getConstructor(EntityTypes.class, World.class); 60 | 61 | 62 | EntityTypes.b nmsCreator = (entityType, world) -> { 63 | net.minecraft.server.v1_14_R1.Entity entity = null; 64 | try { 65 | entity = constructor.newInstance(entityType, world); 66 | } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { 67 | e.printStackTrace(); 68 | } 69 | return entity; 70 | }; 71 | 72 | EnumCreatureType nmsCreatureType = EnumCreatureType.valueOf(type.getCreatureType().name()); 73 | 74 | EntityTypes customEntityNMSEntityType = EntityTypes.a.a(nmsCreator, nmsCreatureType) 75 | .a(type.getKey()); 76 | 77 | IRegistry.ENTITY_TYPE.a(type.getBaseID(ServerVersion.v1_14), minecraftKey, customEntityNMSEntityType); 78 | 79 | //Is an insentient entity? Also copy the EntityPositionTypes value. 80 | if(type.getNMSClass(ServerVersion.v1_14).isAssignableFrom(EntityInsentient.class)) { 81 | Object entityInformation = positionMap.get(customEntityNMSEntityType); 82 | positionMap.put(customEntityNMSEntityType, entityInformation); 83 | } 84 | 85 | type.setHandle(customEntityNMSEntityType); 86 | if(type.isVanilla(ServerVersion.v1_14)) overrideSpawn(nmsCreatureType, baseKey, customEntityNMSEntityType); 87 | 88 | for(BiomeSpawn spawn : type.getSpawns(ServerVersion.v1_16_1)) 89 | registerSpawn(nmsCreatureType, customEntityNMSEntityType, spawn); 90 | 91 | } catch(NoSuchMethodException e) { 92 | throw new RuntimeException(e); 93 | } 94 | } 95 | 96 | private void registerSpawn(EnumCreatureType creatureType, EntityTypes customType, BiomeSpawn spawn) { 97 | Stream.of(spawn.getBiomes()) 98 | .map(Biome::name) 99 | .map(String::toLowerCase) 100 | .map(MinecraftKey::a) 101 | .map(IRegistry.BIOME::get) 102 | .filter(Objects::nonNull) 103 | .forEach(biomeBase -> { 104 | List meta = biomeBase.getMobs(creatureType); 105 | if(meta == null) return; 106 | meta.add(new BiomeBase.BiomeMeta(customType, spawn.getWeight(), spawn.getMin(), spawn.getMax())); 107 | }); 108 | } 109 | 110 | private void overrideSpawn(EnumCreatureType creatureType, MinecraftKey baseKey, EntityTypes customType) { 111 | IRegistry.BIOME.d() 112 | .map(biomeBase -> biomeBase.getMobs(creatureType)) 113 | .filter(Objects::nonNull) 114 | .flatMap(List::stream) 115 | .filter(meta -> Objects.equals(((IRegistry>) IRegistry.ENTITY_TYPE).getKey(meta.b), baseKey)) 116 | .forEach((ThrowingConsumer) biomeMeta -> biomeEntityType.set(biomeMeta.b, customType)); 117 | } 118 | } -------------------------------------------------------------------------------- /nms/1_15_R1/src/main/java/io/github/iltotore/customentity/v1_15_R1/NMSEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_15_R1; 2 | 3 | import com.mojang.datafixers.DataFixUtils; 4 | import com.mojang.datafixers.types.Type; 5 | import io.github.iltotore.customentity.BiomeSpawn; 6 | import io.github.iltotore.customentity.type.CustomEntityRoot; 7 | import io.github.iltotore.customentity.HashCustomRegistry; 8 | import io.github.iltotore.customentity.util.ReflectUtil; 9 | import io.github.iltotore.customentity.util.ServerVersion; 10 | import io.github.iltotore.customentity.util.ThrowingConsumer; 11 | import net.minecraft.server.v1_15_R1.*; 12 | import org.apache.commons.lang.Validate; 13 | import org.bukkit.block.Biome; 14 | import org.bukkit.entity.Entity; 15 | 16 | import java.lang.reflect.Constructor; 17 | import java.lang.reflect.Field; 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | import java.util.stream.Stream; 23 | 24 | public class NMSEntityRegistry extends HashCustomRegistry { 25 | 26 | private Map, Object> positionMap = null; 27 | private Field biomeEntityType; 28 | 29 | @SuppressWarnings("unchecked") 30 | public NMSEntityRegistry() { 31 | try { 32 | Field field = EntityPositionTypes.class.getDeclaredField("a"); 33 | field.setAccessible(true); 34 | this.positionMap = (Map, Object>) field.get(null); 35 | 36 | biomeEntityType = BiomeBase.BiomeMeta.class.getDeclaredField("b"); 37 | ReflectUtil.setFinal(biomeEntityType, false); 38 | } catch(NoSuchFieldException | IllegalAccessException e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | 44 | @Override 45 | @SuppressWarnings("unchecked") 46 | public void applyRegister(CustomEntityRoot type) { 47 | //Creating a minecraft key with the name 48 | MinecraftKey baseKey = MinecraftKey.a(type.getBaseKey()); 49 | MinecraftKey minecraftKey = MinecraftKey.a(type.getKey()); 50 | Validate.notNull(minecraftKey, "Using an invalid name for registering a custom entity. Name: " + type.getKey()); 51 | 52 | if(IRegistry.ENTITY_TYPE.getOptional(minecraftKey).isPresent()) 53 | throw new IllegalArgumentException("Entity with key " + type.getKey() + " already exists !"); 54 | 55 | //Getting the data converter type for the default entity and adding that to the custom mob. 56 | Map> typeMap = (Map>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(DataFixUtils.makeKey(SharedConstants.getGameVersion().getWorldVersion()))).findChoiceType(DataConverterTypes.ENTITY).types(); 57 | typeMap.put(minecraftKey.toString(), typeMap.get(baseKey)); 58 | try { 59 | Constructor constructor = (Constructor) type.getNMSClass(ServerVersion.v1_15).getConstructor(EntityTypes.class, World.class); 60 | 61 | 62 | EntityTypes.b nmsCreator = (entityType, world) -> { 63 | net.minecraft.server.v1_15_R1.Entity entity = null; 64 | try { 65 | entity = constructor.newInstance(entityType, world); 66 | } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { 67 | e.printStackTrace(); 68 | } 69 | return entity; 70 | }; 71 | 72 | EnumCreatureType nmsCreatureType = EnumCreatureType.valueOf(type.getCreatureType().name()); 73 | 74 | EntityTypes customEntityNMSEntityType = EntityTypes.a.a(nmsCreator, nmsCreatureType) 75 | .a(type.getKey()); 76 | 77 | IRegistry.ENTITY_TYPE.a(type.getBaseID(ServerVersion.v1_15), minecraftKey, customEntityNMSEntityType); 78 | 79 | //Is an insentient entity? Also copy the EntityPositionTypes value. 80 | if(type.getNMSClass(ServerVersion.v1_15).isAssignableFrom(EntityInsentient.class)) { 81 | Object entityInformation = positionMap.get(customEntityNMSEntityType); 82 | positionMap.put(customEntityNMSEntityType, entityInformation); 83 | } 84 | 85 | type.setHandle(customEntityNMSEntityType); 86 | 87 | 88 | if(type.isVanilla(ServerVersion.v1_15)) overrideSpawn(nmsCreatureType, baseKey, customEntityNMSEntityType); 89 | 90 | for(BiomeSpawn spawn : type.getSpawns(ServerVersion.v1_16_1)) 91 | registerSpawn(nmsCreatureType, customEntityNMSEntityType, spawn); 92 | 93 | } catch(NoSuchMethodException e) { 94 | throw new RuntimeException(e); 95 | } 96 | } 97 | 98 | private void registerSpawn(EnumCreatureType creatureType, EntityTypes customType, BiomeSpawn spawn) { 99 | Stream.of(spawn.getBiomes()) 100 | .map(Biome::name) 101 | .map(String::toLowerCase) 102 | .map(MinecraftKey::a) 103 | .map(IRegistry.BIOME::get) 104 | .filter(Objects::nonNull) 105 | .forEach(biomeBase -> { 106 | List meta = biomeBase.getMobs(creatureType); 107 | if(meta == null) return; 108 | meta.add(new BiomeBase.BiomeMeta(customType, spawn.getWeight(), spawn.getMin(), spawn.getMax())); 109 | }); 110 | } 111 | 112 | private void overrideSpawn(EnumCreatureType creatureType, MinecraftKey baseKey, EntityTypes customType) { 113 | IRegistry.BIOME.d() 114 | .map(biomeBase -> biomeBase.getMobs(creatureType)) 115 | .filter(Objects::nonNull) 116 | .flatMap(List::stream) 117 | .filter(meta -> Objects.equals(((IRegistry>) IRegistry.ENTITY_TYPE).getKey(meta.b), baseKey)) 118 | .forEach((ThrowingConsumer) biomeMeta -> biomeEntityType.set(biomeMeta, customType)); 119 | } 120 | } -------------------------------------------------------------------------------- /nms/1_16_R1/src/main/java/io/github/iltotore/customentity/v1_16_R1/NMSEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_16_R1; 2 | 3 | import com.mojang.datafixers.DataFixUtils; 4 | import com.mojang.datafixers.types.Type; 5 | import io.github.iltotore.customentity.BiomeSpawn; 6 | import io.github.iltotore.customentity.type.CustomEntityRoot; 7 | import io.github.iltotore.customentity.HashCustomRegistry; 8 | import io.github.iltotore.customentity.util.ReflectUtil; 9 | import io.github.iltotore.customentity.util.ServerVersion; 10 | import io.github.iltotore.customentity.util.ThrowingConsumer; 11 | import net.minecraft.server.v1_16_R1.*; 12 | import org.apache.commons.lang.Validate; 13 | import org.bukkit.Bukkit; 14 | import org.bukkit.block.Biome; 15 | import org.bukkit.entity.Entity; 16 | 17 | import java.lang.reflect.Constructor; 18 | import java.lang.reflect.Field; 19 | import java.lang.reflect.InvocationTargetException; 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.Objects; 23 | import java.util.stream.Stream; 24 | 25 | public class NMSEntityRegistry extends HashCustomRegistry { 26 | 27 | private Map, Object> positionMap = null; 28 | private Field biomeEntityType; 29 | 30 | @SuppressWarnings("unchecked") 31 | public NMSEntityRegistry() { 32 | try { 33 | Field field = EntityPositionTypes.class.getDeclaredField("a"); 34 | field.setAccessible(true); 35 | this.positionMap = (Map, Object>) field.get(null); 36 | 37 | biomeEntityType = BiomeBase.BiomeMeta.class.getDeclaredField("c"); 38 | ReflectUtil.setFinal(biomeEntityType, false); 39 | } catch(NoSuchFieldException | IllegalAccessException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | 44 | 45 | @Override 46 | @SuppressWarnings("unchecked") 47 | public void applyRegister(CustomEntityRoot type) { 48 | //Creating a minecraft key with the name 49 | MinecraftKey baseKey = MinecraftKey.a(type.getBaseKey()); 50 | MinecraftKey minecraftKey = MinecraftKey.a(type.getKey()); 51 | Validate.notNull(minecraftKey, "Using an invalid name for registering a custom entity. Name: " + type.getKey()); 52 | 53 | if(IRegistry.ENTITY_TYPE.getOptional(minecraftKey).isPresent()) 54 | throw new IllegalArgumentException("Entity with key " + type.getKey() + " already exists !"); 55 | 56 | //Getting the data converter type for the default entity and adding that to the custom mob. 57 | Map> typeMap = (Map>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(DataFixUtils.makeKey(SharedConstants.getGameVersion().getWorldVersion()))).findChoiceType(DataConverterTypes.ENTITY).types(); 58 | if(!typeMap.containsKey(baseKey.toString())) Bukkit.getLogger().warning("Cannot find vanilla mob named " + baseKey); 59 | typeMap.put(minecraftKey.toString(), typeMap.get(baseKey.toString())); 60 | try { 61 | Constructor constructor = (Constructor) type.getNMSClass(ServerVersion.v1_16_1).getConstructor(EntityTypes.class, World.class); 62 | 63 | EntityTypes.b nmsCreator = (entityType, world) -> { 64 | try { 65 | return constructor.newInstance(entityType, world); 66 | } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { 67 | throw new RuntimeException(e); 68 | } 69 | }; 70 | 71 | EnumCreatureType nmsCreatureType = EnumCreatureType.valueOf(type.getCreatureType().name()); 72 | 73 | EntityTypes customEntityNMSEntityType = EntityTypes.Builder.a(nmsCreator, nmsCreatureType) 74 | .a(type.getKey()); 75 | 76 | IRegistry.a(IRegistry.ENTITY_TYPE, type.getBaseID(ServerVersion.v1_16_1), type.getKey(), customEntityNMSEntityType); 77 | 78 | //Is an insentient entity? Also copy the EntityPositionTypes value. 79 | if(type.getNMSClass(ServerVersion.v1_16_1).isAssignableFrom(EntityInsentient.class)) { 80 | Object entityInformation = positionMap.get(customEntityNMSEntityType); 81 | positionMap.put(customEntityNMSEntityType, entityInformation); 82 | } 83 | 84 | type.setHandle(customEntityNMSEntityType); 85 | 86 | if(type.isVanilla(ServerVersion.v1_16_1)) 87 | overrideSpawn(nmsCreatureType, baseKey, customEntityNMSEntityType); 88 | 89 | for(BiomeSpawn spawn : type.getSpawns(ServerVersion.v1_16_1)) 90 | registerSpawn(nmsCreatureType, customEntityNMSEntityType, spawn); 91 | 92 | } catch(NoSuchMethodException e) { 93 | throw new RuntimeException(e); 94 | } 95 | } 96 | 97 | private void registerSpawn(EnumCreatureType creatureType, EntityTypes customType, BiomeSpawn spawn) { 98 | Stream.of(spawn.getBiomes()) 99 | .map(Biome::name) 100 | .map(String::toLowerCase) 101 | .map(MinecraftKey::a) 102 | .map(IRegistry.BIOME::get) 103 | .filter(Objects::nonNull) 104 | .forEach(biomeBase -> { 105 | List meta = biomeBase.getMobs(creatureType); 106 | if(meta == null) return; 107 | meta.add(new BiomeBase.BiomeMeta(customType, spawn.getWeight(), spawn.getMin(), spawn.getMax())); 108 | }); 109 | } 110 | 111 | private void overrideSpawn(EnumCreatureType creatureType, MinecraftKey baseKey, EntityTypes customType) { 112 | IRegistry.BIOME.e() 113 | .map(biomeBase -> biomeBase.getMobs(creatureType)) 114 | .filter(Objects::nonNull) 115 | .flatMap(List::stream) 116 | .filter(meta -> Objects.equals(((IRegistry>) IRegistry.ENTITY_TYPE).getKey(meta.c), baseKey)) 117 | .forEach((ThrowingConsumer) biomeMeta -> biomeEntityType.set(biomeMeta, customType)); 118 | } 119 | } -------------------------------------------------------------------------------- /nms/1_13_R1/src/main/java/io/github/iltotore/customentity/v1_13_R1/NMSEntityRegistry.java: -------------------------------------------------------------------------------- 1 | package io.github.iltotore.customentity.v1_13_R1; 2 | 3 | import com.mojang.datafixers.DataFixUtils; 4 | import com.mojang.datafixers.types.Type; 5 | import io.github.iltotore.customentity.BiomeSpawn; 6 | import io.github.iltotore.customentity.HashCustomRegistry; 7 | import io.github.iltotore.customentity.PersistentEntity; 8 | import io.github.iltotore.customentity.type.CustomEntityRoot; 9 | import io.github.iltotore.customentity.util.ReflectUtil; 10 | import io.github.iltotore.customentity.util.ServerVersion; 11 | import net.minecraft.server.v1_13_R1.*; 12 | import org.apache.commons.lang.Validate; 13 | import org.bukkit.block.Biome; 14 | import org.bukkit.entity.Entity; 15 | 16 | import java.lang.reflect.Constructor; 17 | import java.lang.reflect.Field; 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Objects; 22 | import java.util.function.Function; 23 | import java.util.stream.Stream; 24 | import java.util.stream.StreamSupport; 25 | 26 | public class NMSEntityRegistry extends HashCustomRegistry { 27 | 28 | private Map, Object> positionMap = null; 29 | private Field biomeEntityType; 30 | 31 | @SuppressWarnings("unchecked") 32 | public NMSEntityRegistry() { 33 | try { 34 | Field field = EntityPositionTypes.class.getDeclaredField("a"); 35 | field.setAccessible(true); 36 | this.positionMap = (Map, Object>) field.get(null); 37 | 38 | biomeEntityType = BiomeBase.BiomeMeta.class.getDeclaredField("b"); 39 | ReflectUtil.setFinal(biomeEntityType, false); 40 | } catch(NoSuchFieldException | IllegalAccessException e) { 41 | e.printStackTrace(); 42 | } 43 | } 44 | 45 | 46 | @Override 47 | @SuppressWarnings("unchecked") 48 | public void applyRegister(CustomEntityRoot type) { 49 | //Creating a minecraft key with the name 50 | MinecraftKey baseKey = MinecraftKey.a(type.getBaseKey()); 51 | MinecraftKey minecraftKey = MinecraftKey.a(type.getKey()); 52 | Validate.notNull(minecraftKey, "Using an invalid name for registering a custom entity. Name: " + type.getKey()); 53 | 54 | if(EntityTypes.REGISTRY.d(minecraftKey)) 55 | throw new IllegalArgumentException("Entity with key " + type.getKey() + " already exists !"); 56 | 57 | //Getting the data converter type for the default entity and adding that to the custom mob. 58 | Map> typeMap = (Map>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(1628)).findChoiceType(DataConverterTypes.n).types(); 59 | typeMap.put(minecraftKey.toString(), typeMap.get(baseKey)); 60 | 61 | try { 62 | Constructor constructor = (Constructor) type.getNMSClass(ServerVersion.v1_13).getConstructor(World.class); 63 | 64 | 65 | Function nmsCreator = world -> { 66 | EntityInsentient entity = null; 67 | try { 68 | entity = constructor.newInstance(world); 69 | } catch(InstantiationException | IllegalAccessException | InvocationTargetException e) { 70 | e.printStackTrace(); 71 | } 72 | if(entity instanceof PersistentEntity) ((PersistentEntity) entity).setCustomType(type); 73 | return entity; 74 | }; 75 | 76 | EnumCreatureType nmsCreatureType = EnumCreatureType.valueOf(type.getCreatureType().name()); 77 | 78 | EntityTypes customEntityNMSEntityType = EntityTypes.a.a((Class) type.getNMSClass(ServerVersion.v1_13), nmsCreator) 79 | .a(type.getKey()); 80 | 81 | EntityTypes.REGISTRY.a(type.getBaseID(ServerVersion.v1_13), minecraftKey, customEntityNMSEntityType); 82 | 83 | //Is an insentient entity? Also copy the EntityPositionTypes value. 84 | if(type.getNMSClass(ServerVersion.v1_13).isAssignableFrom(EntityInsentient.class)) { 85 | Object entityInformation = positionMap.get(customEntityNMSEntityType); 86 | positionMap.put(customEntityNMSEntityType, entityInformation); 87 | } 88 | 89 | type.setHandle(customEntityNMSEntityType); 90 | if(type.isVanilla(ServerVersion.v1_13)) 91 | overrideSpawn(EnumCreatureType.valueOf(type.getCreatureType().name()), baseKey, customEntityNMSEntityType); 92 | 93 | for(BiomeSpawn spawn : type.getSpawns(ServerVersion.v1_16_1)) 94 | registerSpawn(nmsCreatureType, customEntityNMSEntityType, spawn); 95 | 96 | } catch(NoSuchMethodException e) { 97 | throw new RuntimeException(e); 98 | } 99 | } 100 | 101 | private void registerSpawn(EnumCreatureType creatureType, EntityTypes customType, BiomeSpawn spawn) { 102 | Stream.of(spawn.getBiomes()) 103 | .map(Biome::name) 104 | .map(String::toLowerCase) 105 | .map(MinecraftKey::a) 106 | .map(BiomeBase.REGISTRY_ID::get) 107 | .filter(Objects::nonNull) 108 | .forEach(biomeBase -> { 109 | List meta = biomeBase.getMobs(creatureType); 110 | if(meta == null) return; 111 | meta.add(new BiomeBase.BiomeMeta(customType, spawn.getWeight(), spawn.getMin(), spawn.getMax())); 112 | }); 113 | } 114 | 115 | @SuppressWarnings("unchecked") 116 | private void overrideSpawn(EnumCreatureType creatureType, MinecraftKey baseKey, EntityTypes customType) { 117 | StreamSupport.stream(BiomeBase.REGISTRY_ID.spliterator(), false) 118 | .map(biomeBase -> biomeBase.getMobs(creatureType)) 119 | .filter(Objects::nonNull) 120 | .flatMap(List::stream) 121 | .filter(meta -> Objects.equals(EntityTypes.REGISTRY.b(meta.b), baseKey)) 122 | .forEach(meta -> meta.b = (EntityTypes) customType); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # 4 | # Copyright 2015 the original author or authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | ## 21 | ## Gradle start up script for UN*X 22 | ## 23 | ############################################################################## 24 | 25 | # Attempt to set APP_HOME 26 | # Resolve links: $0 may be a link 27 | PRG="$0" 28 | # Need this for relative symlinks. 29 | while [ -h "$PRG" ] ; do 30 | ls=`ls -ld "$PRG"` 31 | link=`expr "$ls" : '.*-> \(.*\)$'` 32 | if expr "$link" : '/.*' > /dev/null; then 33 | PRG="$link" 34 | else 35 | PRG=`dirname "$PRG"`"/$link" 36 | fi 37 | done 38 | SAVED="`pwd`" 39 | cd "`dirname \"$PRG\"`/" >/dev/null 40 | APP_HOME="`pwd -P`" 41 | cd "$SAVED" >/dev/null 42 | 43 | APP_NAME="Gradle" 44 | APP_BASE_NAME=`basename "$0"` 45 | 46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 48 | 49 | # Use the maximum available, or set MAX_FD != -1 to use that value. 50 | MAX_FD="maximum" 51 | 52 | warn () { 53 | echo "$*" 54 | } 55 | 56 | die () { 57 | echo 58 | echo "$*" 59 | echo 60 | exit 1 61 | } 62 | 63 | # OS specific support (must be 'true' or 'false'). 64 | cygwin=false 65 | msys=false 66 | darwin=false 67 | nonstop=false 68 | case "`uname`" in 69 | CYGWIN* ) 70 | cygwin=true 71 | ;; 72 | Darwin* ) 73 | darwin=true 74 | ;; 75 | MINGW* ) 76 | msys=true 77 | ;; 78 | NONSTOP* ) 79 | nonstop=true 80 | ;; 81 | esac 82 | 83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 84 | 85 | # Determine the Java command to use to start the JVM. 86 | if [ -n "$JAVA_HOME" ] ; then 87 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 88 | # IBM's JDK on AIX uses strange locations for the executables 89 | JAVACMD="$JAVA_HOME/jre/sh/java" 90 | else 91 | JAVACMD="$JAVA_HOME/bin/java" 92 | fi 93 | if [ ! -x "$JAVACMD" ] ; then 94 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 95 | 96 | Please set the JAVA_HOME variable in your environment to match the 97 | location of your Java installation." 98 | fi 99 | else 100 | JAVACMD="java" 101 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 102 | 103 | Please set the JAVA_HOME variable in your environment to match the 104 | location of your Java installation." 105 | fi 106 | 107 | # Increase the maximum file descriptors if we can. 108 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 109 | MAX_FD_LIMIT=`ulimit -H -n` 110 | if [ $? -eq 0 ] ; then 111 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 112 | MAX_FD="$MAX_FD_LIMIT" 113 | fi 114 | ulimit -n $MAX_FD 115 | if [ $? -ne 0 ] ; then 116 | warn "Could not set maximum file descriptor limit: $MAX_FD" 117 | fi 118 | else 119 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 120 | fi 121 | fi 122 | 123 | # For Darwin, add options to specify how the application appears in the dock 124 | if $darwin; then 125 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 126 | fi 127 | 128 | # For Cygwin or MSYS, switch paths to Windows format before running java 129 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then 130 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 131 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 132 | JAVACMD=`cygpath --unix "$JAVACMD"` 133 | 134 | # We build the pattern for arguments to be converted via cygpath 135 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 136 | SEP="" 137 | for dir in $ROOTDIRSRAW ; do 138 | ROOTDIRS="$ROOTDIRS$SEP$dir" 139 | SEP="|" 140 | done 141 | OURCYGPATTERN="(^($ROOTDIRS))" 142 | # Add a user-defined pattern to the cygpath arguments 143 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 144 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 145 | fi 146 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 147 | i=0 148 | for arg in "$@" ; do 149 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 150 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 151 | 152 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 153 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 154 | else 155 | eval `echo args$i`="\"$arg\"" 156 | fi 157 | i=`expr $i + 1` 158 | done 159 | case $i in 160 | 0) set -- ;; 161 | 1) set -- "$args0" ;; 162 | 2) set -- "$args0" "$args1" ;; 163 | 3) set -- "$args0" "$args1" "$args2" ;; 164 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;; 165 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 166 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 167 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 168 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 169 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 170 | esac 171 | fi 172 | 173 | # Escape application args 174 | save () { 175 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 176 | echo " " 177 | } 178 | APP_ARGS=`save "$@"` 179 | 180 | # Collect all arguments for the java command, following the shell quoting and substitution rules 181 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 182 | 183 | exec "$JAVACMD" "$@" 184 | --------------------------------------------------------------------------------