Minecraft Crashes (Custom Entity)

Discussion in 'Plugin Development' started by Chintzi, Jul 14, 2016.

Thread Status:
Not open for further replies.
  1. Offline


    So i have literally been looking around on google the whole day and i looked at every Custom entities creation tutorial and they don't seem to work for me they all are outdated and theres always something that needs to be changed but im not sure what to change, anyways i found someones code they posted on github and it crashes my server and minecraft when i attept to spawn it:

    AncientGladiator.java (Custom entity class) (open)

    package craftextra.entities;
    import net.minecraft.server.v1_10_R1.EntitySkeleton;
    import net.minecraft.server.v1_10_R1.GenericAttributes;
    import net.minecraft.server.v1_10_R1.World;
    import org.bukkit.Location;
    import org.bukkit.craftbukkit.v1_10_R1.CraftWorld;
    import org.bukkit.craftbukkit.v1_10_R1.entity.CraftLivingEntity;
    import org.bukkit.craftbukkit.v1_10_R1.entity.CraftSkeleton;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
    public class AncientGladiator extends EntitySkeleton {
        public AncientGladiator(World world) {
        protected void initAttributes() {
        public static Skeleton spawn(Location location) {
            World mcWorld = (World) ((CraftWorld) location.getWorld()).getHandle();
            final AncientGladiator customEntity = new AncientGladiator(mcWorld);
            customEntity.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
            ((CraftLivingEntity) customEntity.getBukkitEntity()).setRemoveWhenFarAway(false);
            mcWorld.addEntity(customEntity, SpawnReason.CUSTOM);
            return (CraftSkeleton) customEntity.getBukkitEntity();

    NMSUtils.java (open)

    package craftextra.entities;
    import net.minecraft.server.v1_10_R1.EntityInsentient;
    import net.minecraft.server.v1_10_R1.EntityTypes;
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Map;
    public class NMSUtils {
        public void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass) {
            try {
                * First, we make a list of all HashMap's in the EntityTypes class
                * by looping through all fields. I am using reflection here so we
                * have no problems later when minecraft changes the field's name.
                * By creating a list of these maps we can easily modify them later
                * on.
                List<Map<?, ?>> dataMaps = new ArrayList<Map<?, ?>>();
                for (Field f : EntityTypes.class.getDeclaredFields()) {
                    if (f.getType().getSimpleName().equals(Map.class.getSimpleName())) {
                        dataMaps.add((Map<?, ?>) f.get(null));
                * since minecraft checks if an id has already been registered, we
                * have to remove the old entity class before we can register our
                * custom one
                * map 0 is the map with names and map 2 is the map with ids
                if (dataMaps.get(2).containsKey(id)) {
                * now we call the method which adds the entity to the lists in the
                * EntityTypes class, now we are actually 'registering' our entity
                Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.invoke(null, customClass, name, id);
            } catch (Exception e) {

    Spawn method (open)
    Skeleton ancientGladiator = AncientGladiator.spawn(player.getLocation());

    Registering it (open)
    new NMSUtils().registerEntity("AncientGladiator", 65, EntityBat.class, AncientGladiator.class);
  2. Offline


    It crashes because you use the entity ID of Bats, but your custom class extends Skeleton.
Thread Status:
Not open for further replies.

Share This Page