Solved Changes in registering custom entities

Discussion in 'Spigot Plugin Development' started by Escad, Jan 29, 2020.

  1. I have this snippet of code that's worked for registering custom entities in 1.13 and 1.14 that looks something like this:
    Code (Java):
    // 1.13
    public void register() {
        Map<Object, Type<?>> dataTypes = (Map<Object, Type<?>>)
                DataConverterRegistry.a() // get datafixerupper
                .getSchema(DataFixUtils.makeKey(15190)) // get (presumably) DataConverterSchemaV705
                .findChoiceType(DataConverterTypes.n).types(); // get types map of choicetype "entity_tree"
        // add custom entity to entity tree types map
        dataTypes.put("minecraft:"+name, dataTypes.get());
        // finally, we get our custom EntityTypes instance, necessary for spawning
        entityType = EntityTypes.a(name, EntityTypes.a.a(petClass, maker));
    }

    // 1.14
    @SuppressWarnings("unchecked")
    private void register() {
        Map<Object, Type<?>> dataTypes = (Map<Object, Type<?>>)DataConverterRegistry.a()
                .getSchema(DataFixUtils.makeKey(SharedConstants.a().getWorldVersion()))
                .findChoiceType(DataConverterTypes.ENTITY).types();
        dataTypes.put("minecraft:"+name, dataTypes.get(entityType.f()));
        EntityTypes.a<EntityLiving> entity = EntityTypes.a.a(maker, EnumCreatureType.CREATURE);
        IRegistry.a(IRegistry.ENTITY_TYPE, name, entity.a(name));
    }
    The main difference between these two appears to be that 1.13 uses a custom EntityType while 1.14 uses the parent entity's EntityType instead of a new one. There's also a difference in the key used to get the proper schema which is what I'm lost on, since I'm still unable to figure out exactly where these values come from and how they're related.
    The 1.14 snippet seems that it would work fine on 1.15 if I could simply figure out the new value though. Hopefully somebody can help me figure it out - bonus points if they can tell me why it is what it is too :p

    Edit://
    okaaay, so i was silly and overlooked the fact that SharedConstants.a() was only renamed to SharedConstants.getGameVersion(). I have yet to test anything, but assuming that was the only change, it should work just fine. Solved!
     
    #1 Escad, Jan 29, 2020
    Last edited: Jan 30, 2020