1.14.4 registering entities

Discussion in 'Spigot Plugin Development' started by palamud, Jan 7, 2020.

  1. Hello everyone i am struggulling with register and spawning my custom enities but i got errors and i am quite stuck right now and i need urgent help. i am using spigot 1.14.4

    this is my enum

    Code (Java):
    public enum CustomEntityType {

        ZOMBIE("MyZombie", EntityTypes.ZOMBIE, EntityZombie.class,Zombie.class);

        private String name;
        private EntityTypes<? extends EntityInsentient> entityType;
        private Class<? extends EntityInsentient> nmsClass;
        private Class<? extends EntityInsentient> customClass;

        private CustomEntityType(String name, EntityTypes<? extends EntityInsentient> entityType,
                Class<? extends EntityInsentient> nmsClass,
                Class<? extends EntityInsentient> customClass) {
            this.name = name;
            this.entityType = entityType;
            this.nmsClass = nmsClass;
            this.customClass = customClass;
        }

        public String getName() {
            return name;
        }

        public EntityTypes getEntityType() {
            return entityType;
        }

        public Class<? extends EntityInsentient> getNMSClass() {
            return nmsClass;
        }

        public Class<? extends EntityInsentient> getCustomClass() {
            return customClass;
        }

        /**
         * Register our entities.
         */

        public static void registerEntities() {
            for (CustomEntityType entity : values()) {
                // a(entity.getCustomClass(), entity.getName(), entity.getID());
                registerCustomEntity(entity);
            }
        }

        /**
         * Unregister our entities to prevent memory leaks. Call on disable.
         */

        @SuppressWarnings("unchecked")
        public static void unregisterEntities() {
            for (CustomEntityType entity : values()) {
                MinecraftKey minecraftKey = MinecraftKey.a(entity.getName());

                // Unsure if this works fully, but we should be fine...
                Map<Object, Type<?>> typeMap = (Map<Object, Type<?>>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(SharedConstants.a().getWorldVersion())).findChoiceType(DataConverterTypes.n).types();
                typeMap.remove(minecraftKey);
            }
        }

        @SuppressWarnings("unchecked")
        private static void registerCustomEntity(CustomEntityType type) {
            MinecraftKey minecraftKey = MinecraftKey.a(type.getName());

            Map<Object, Type<?>> typeMap = (Map<Object, Type<?>>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(SharedConstants.a().getWorldVersion())).findChoiceType(DataConverterTypes.n).types();
            typeMap.put(minecraftKey.toString(), typeMap.get(MinecraftKey.a(type.getName()).toString()));

            EntityTypes.a<Entity> mob = EntityTypes.a.a(Zombie::new, EnumCreatureType.CREATURE);
            IRegistry.a(IRegistry.ENTITY_TYPE, type.getName(), mob.a(type.getName()));
        }
    }
    and this is my zombie class

    Code (Java):
    public class Zombie extends EntityZombie{
       
       
        public Zombie(EntityTypes<? extends EntityZombie> entitytypes, World world) {
            super(entitytypes,world);
            clearPathFinders();
        }

        private void clearPathFinders() {

            this.goalSelector = new PathfinderGoalSelector(world.getMethodProfiler());
            this.targetSelector = new PathfinderGoalSelector(world.getMethodProfiler());
        }
       
    }
    this is the error

    java.lang.IllegalArgumentException: Not a choice type
    at com.mojang.datafixers.schemas.Schema.lambda$findChoiceType$4(Schema.java:115) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]
    at java.util.Optional.orElseThrow(Unknown Source) ~[?:1.8.0_221]
    at com.mojang.datafixers.schemas.Schema.findChoiceType(Schema.java:115) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]
    at org.berkealgul.mcplugin.CustomEntityType.registerCustomEntity(CustomEntityType.java:83) ~[?:?]
    at org.berkealgul.mcplugin.CustomEntityType.registerEntities(CustomEntityType.java:61) ~[?:?]
    at org.berkealgul.mcplugin.main.onEnable(main.java:16) ~[?:?]

    that line is this

    Code (Java):
            Map<Object, Type<?>> typeMap = (Map<Object, Type<?>>) DataConverterRegistry.a().getSchema(DataFixUtils.makeKey(SharedConstants.a().getWorldVersion())).findChoiceType(DataConverterTypes.n).types();
     
  2. Did you just copy that from somewhere?

    interresting, first time I'm seing such an error
     
  3. Nope that is from my terminal
     
  4. Do you have other idea to register entities
     
  5. I meant the code
     
  6. Not sure if you even need the data fixer. You should be able to spawn a custom entity without that and that is (if I'm not wrong) only important to save some additional data, probably persistent.

    Try if you can spawn your entity without the type map stuff
     
  7. Not sure but i think you can just spawn a custom entity without registering it.
    You only need to register it if you want it to persist.