Jump to content

[1.16.3] Can't register Entity with Deferred Register


Recommended Posts

Posted

I'm quite new at modding so bear with me here,

I'm trying to register my Entity using the DeferredRegister but I keep getting the error

"The type DeerEntity does not define DeerEntity(EntityType<T>, World) that is applicable here"

 

// RegistryHandler.java

public static final DeferredRegister<EntityType<?>> ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.ENTITIES,
            HuntingUpdate.MOD_ID);

public static final RegistryObject<EntityType<DeerEntity>> DEER = ENTITY_TYPES.register("deer",
            () -> EntityType.Builder.create(DeerEntity::new, EntityClassification.CREATURE)
                    .size(1.0f, 1.0f)
                    .build(new ResourceLocation(HuntingUpdate.MOD_ID, "deer").toString()));
// DeerEntity.java

public class DeerEntity extends AnimalEntity {

    public static final Ingredient TEMPTATION_ITEMS = Ingredient.fromItems(Items.APPLE, Items.CARROT,
            Items.CARROT_ON_A_STICK, Items.BEETROOT);

    private EatGrassGoal eatGrassGoal;
    private int deerTimer;

    protected DeerEntity(EntityType<? extends DeerEntity> type, World worldIn) {
        super(type, worldIn);
        // TODO Auto-generated constructor stub
    }

    public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return AnimalEntity.func_233666_p_().func_233815_a_(Attributes.field_233818_a_, 10.0D) // Max Health
                .func_233815_a_(Attributes.field_233821_d_, 0.3D); // Movement Speed
    }

    @Override
    protected void registerGoals() {
        super.registerGoals();

        this.goalSelector.addGoal(0, new SwimGoal(this));
        this.goalSelector.addGoal(1, new PanicGoal(this, 1.5D));
        this.goalSelector.addGoal(2, new BreedGoal(this, 1.0D));
        this.goalSelector.addGoal(3, new TemptGoal(this, 0.5D, TEMPTATION_ITEMS, true));
        this.goalSelector.addGoal(4, new FollowParentGoal(this, 1.1D));
        this.goalSelector.addGoal(5, eatGrassGoal);
        this.goalSelector.addGoal(6, new AvoidEntityGoal<>(this, PlayerEntity.class, 15.0F, 1.25D, 0.5D));
        this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 0.7D));
        this.goalSelector.addGoal(8, new LookAtGoal(this, PlayerEntity.class, 10.0F));
        this.goalSelector.addGoal(9, new LookRandomlyGoal(this));
    }

    @Override
    public AgeableEntity func_241840_a(ServerWorld p_241840_1_, AgeableEntity p_241840_2_) {
        return RegistryHandler.DEER.get().create(this.world);
    }

    @Override
    protected int getExperiencePoints(PlayerEntity player) {
        return 1 + this.world.rand.nextInt(4);
    }

    @Override
    protected SoundEvent getAmbientSound() {
        return SoundEvents.ENTITY_SQUID_AMBIENT;
    }

    @Override
    protected SoundEvent getDeathSound() {
        return SoundEvents.ENTITY_SQUID_DEATH;
    }

    @Override
    protected SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return SoundEvents.ENTITY_SQUID_HURT;
    }

    @Override
    protected void playStepSound(BlockPos pos, BlockState blockIn) {
        this.playSound(SoundEvents.ENTITY_SQUID_SQUIRT, 0.15F, 1.0F);
    }

    @Override
    protected void updateAITasks() {
        this.deerTimer = this.eatGrassGoal.getEatingGrassTimer();
        super.updateAITasks();
    }

    @Override
    public void livingTick() {
        if (this.world.isRemote) {
            this.deerTimer = Math.max(0, this.deerTimer - 1);
        }
        super.livingTick();
    }

    @OnlyIn(Dist.CLIENT)
    public void handleStatusUpdate(byte id) {
        if (id == 10) {
            this.deerTimer = 40;
        } else {
            super.handleStatusUpdate(id);
        }
    }
}

 

Any help would be greatly appreciated!

Posted

Your DeerEntity(EntityType<? extends DeerEntity> type, World worldIn) is protected, it should be public.

I'm also pretty sure it needs to be DeerEntity(EntityType<T> type, World worldIn) as indicated by the error.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
1 minute ago, Draco18s said:

Your DeerEntity(EntityType<? extends DeerEntity> type, World worldIn) is protected, it should be public.

Thanks so much! That fixed it for me.

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.