Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Registering Entities (1.16.5)


tal124
 Share

Recommended Posts

I thought that registering Entities would be similar to the other ways I have registered Items or Fluids, The tutorials I have seen to do this are both easier, and more difficult than the DeferredRegister's way in 1.16. I have created a Slime Entity called EntityChocolateSlime, but I am unsure as to how I should register it

 

public class ModEntities{

    public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, chocolate.MODID);

    //Attaches the deferred register to the event bus
    public static void init() {
        ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }




    public static final EntityType<?> CHOCOLATE_SLIME =
            ENTITIES.register("chocolate_slime", EntityType.Builder.<EntityChocolateSlime>create(EntityChocolateSlime::new,
                    EntityClassification.MONSTER).size(2.04F, 2.04F).trackingRange(8));


}

 

The error message I get is 

error: method register in class DeferredRegister<T> cannot be applied to given types;
ENTITIES.register("chocolate_cube", EntityType.Builder.<EntityChocolateSlime>create(EntityChocolateSlime::new,
^

Why can it not be applied?

Link to comment
Share on other sites

Posted (edited)
58 minutes ago, poopoodice said:

The register method takes a supplier.

I have registered the Entity but the game doesn't recognize it, however I can start it up, and I have created both the required renderer and model for my Entity called Chocolate_Slime

 

However it gives me the error "MCP Entity class missing World constructor now"

 

I have tried copying and pasting and changing the magma cubes to match my chocolate slime however it still gives me this error, I have since reverted it back to what I had originally.

 

What am I missing?

 

Entity.PNG

Edited by tal124
Link to comment
Share on other sites

public class ModEntities{

    public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, chocolate.MODID);

    //Attaches the deferred register to the event bus
    public static void init() {
        ENTITIES.register(FMLJavaModLoadingContext.get().getModEventBus());
    }


    public static final EntityType<EntityChocolateSlime> CHOCOLATE_SLIME = make(EntityNames.CHOCOLATE_SLIME, EntityChocolateSlime::new,
            EntityClassification.MONSTER, 2.04F, 2.04F);



    @SuppressWarnings("unchecked")
    private static <E extends Entity> EntityType<E> build(ResourceLocation id, EntityType.Builder<E> builder) {
        boolean cache = SharedConstants.useDatafixers;
        SharedConstants.useDatafixers = false;
        EntityType<E> ret = (EntityType<E>) builder.build(id.toString()).setRegistryName(id);
        SharedConstants.useDatafixers = cache;
        return ret;
    }

    private static <E extends Entity> EntityType<E> make(ResourceLocation id, EntityType.IFactory<E> factory, EntityClassification classification, float width, float height) {
        return build(id, makeBuilder(factory, classification).size(width, height));
    }
    

    private static <E extends Entity> EntityType.Builder<E> makeBuilder(EntityType.IFactory<E> factory, EntityClassification classification) {
        return EntityType.Builder.create(factory, classification).
                size(0.6F, 1.8F).
                setTrackingRange(80).
                setUpdateInterval(3).
                setShouldReceiveVelocityUpdates(true);
    }


}
public class EntityChocolateSlime extends SlimeEntity {
    public EntityChocolateSlime(EntityType<? extends EntityChocolateSlime> type, World worldIn) {
        super((EntityType<? extends SlimeEntity>) ModEntities.CHOCOLATE_SLIME, worldIn);
    }




    public static AttributeModifierMap.MutableAttribute func_234294_m_() {
        return MonsterEntity.func_234295_eP_().createMutableAttribute(Attributes.MOVEMENT_SPEED, (double)0.2F);
    }
    public static boolean func_223367_b(EntityType<EntityChocolateSlime> p_223367_0_, IWorld p_223367_1_, SpawnReason p_223367_2_, BlockPos p_223367_3_, Random p_223367_4_) {
        return p_223367_1_.getDifficulty() != Difficulty.PEACEFUL;
    }

    public boolean isNotColliding(IWorldReader worldIn) {
        return worldIn.checkNoEntityCollision(this) && !worldIn.containsAnyLiquid(this.getBoundingBox());
    }
    public EntityType<? extends EntityChocolateSlime> getType() {
        return (EntityType<? extends EntityChocolateSlime>)super.getType();
    }

    protected void setSlimeSize(int size, boolean resetHealth) {
        super.setSlimeSize(size, resetHealth);
        this.getAttribute(Attributes.ARMOR).setBaseValue((double)(size * 3));
    }
    protected int getJumpDelay() {
        return super.getJumpDelay() * 4;
    }

    protected void alterSquishAmount() {
        this.squishAmount *= 0.9F;
    }

    protected void jump() {
        Vector3d vector3d = this.getMotion();
        this.setMotion(vector3d.x, (double)(this.getJumpUpwardsMotion() + (float)this.getSlimeSize() * 0.1F), vector3d.z);
        this.isAirBorne = true;
        net.minecraftforge.common.ForgeHooks.onLivingJump(this);
    }
    protected void handleFluidJump(ITag<Fluid> fluidTag) {
        if (fluidTag == FluidTags.LAVA) {
            Vector3d vector3d = this.getMotion();
            this.setMotion(vector3d.x, (double)(0.22F + (float)this.getSlimeSize() * 0.05F), vector3d.z);
            this.isAirBorne = true;
        } else {
            super.handleFluidJump(fluidTag);
        }

    }
    protected boolean canDamagePlayer() {
        return this.isServerWorld();
    }

    protected float func_225512_er_() {
        return super.func_225512_er_() + 2.0F;
    }

    protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return this.isSmallSlime() ? SoundEvents.ENTITY_MAGMA_CUBE_HURT_SMALL : SoundEvents.ENTITY_MAGMA_CUBE_HURT;
    }

    protected SoundEvent getDeathSound() {
        return this.isSmallSlime() ? SoundEvents.ENTITY_MAGMA_CUBE_DEATH_SMALL : SoundEvents.ENTITY_MAGMA_CUBE_DEATH;
    }

    protected SoundEvent getSquishSound() {
        return this.isSmallSlime() ? SoundEvents.ENTITY_MAGMA_CUBE_SQUISH_SMALL : SoundEvents.ENTITY_MAGMA_CUBE_SQUISH;
    }

    protected SoundEvent getJumpSound() {
        return SoundEvents.ENTITY_MAGMA_CUBE_JUMP;
    }
}

Here is my Entity Code, And nothing is wrong with my spawnegg either, I changed it from my mod entity to a regular slime and it worked fine

 

I'm just a little confused and looking at what other mod creators have done with 1.16 entities is a little bit hard since all of them are incredibly more proficient at modding than me.

Link to comment
Share on other sites

public chocolate() {

        ModFluids.init();
        ModBlocks.init();
        ModItems.init();
        ModEntities.init();
        MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, OreGeneration::generateOres);
        MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, FluidGeneration::generateFluids);

        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the enqueueIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        // Register the processIMC method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);



    }

Right here

Link to comment
Share on other sites

I am getting the MCP entity class missing world constructor for some reason and no matter what I do, I can't get it to go away, even straight ripping off the Magma slime entity won't get rid of it.

Link to comment
Share on other sites

Posted (edited)
3 minutes ago, diesieben07 said:

The code you posted does not even compile. After commenting out the data generator code that didn't compile, the game crashes with a null pointer exception in your registration code.

I may have committed the wrong code as I just put it into github a couple of hours ago to organize the mod a bit, Try my test branch and see if that works better, I just committed to it what I currently have.

Edited by tal124
Link to comment
Share on other sites

So what code should I use instead? I know you probably want me to figure this out on my own, but I've been looking at this code for almost a week now while working on other parts of the mod as well.

Link to comment
Share on other sites

public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, chocolate.MODID);
  
  
  public static final RegistryObject<Block> CHOCOLATE_ORE = BLOCKS.register("chocolate_ore", () ->
            new Block(AbstractBlock.Properties.create(Material.ROCK).hardnessAndResistance(3.0F, 3.0F)
            .sound(SoundType.STONE).harvestLevel(1).harvestTool(ToolType.PICKAXE))
        );

This is how I register them, 

 

public static final DeferredRegister<EntityType<?>> ENTITIES = DeferredRegister.create(ForgeRegistries.ENTITIES, chocolate.MODID);

public static final EntityType<EntityChocolateSlime> CHOCOLATE_SLIME = ENTITIES.register("chocolate_slime", ()->
       /*right here*/     );

Its simple with the blocks as you can define a new Block(properties), but new EntityType<> doesn't work the right way either, is there something im missing?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.