Jump to content

(1.8.1) How do I spawn a mob with an item equipped?


yeetsche420

Recommended Posts

Basically the title. For my mob class, I have the following 2 methods overridden:

   @Override
    protected void populateDefaultEquipmentSlots(DifficultyInstance difficultyInstance) {
        this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(ModItems.COMICALLY_LARGE_SPOON.get()));
    }

    @Nullable
    @Override
    public SpawnGroupData finalizeSpawn(ServerLevelAccessor serverLevelAccessor, DifficultyInstance difficultyInstance, MobSpawnType mobSpawnType, @Nullable SpawnGroupData spawnGroupData, @Nullable CompoundTag compoundTag) {
        SpawnGroupData spawnGroupDataToReturn = super.finalizeSpawn(serverLevelAccessor, difficultyInstance, mobSpawnType, spawnGroupData, compoundTag);
        this.populateDefaultEquipmentSlots(difficultyInstance);
        return spawnGroupDataToReturn;
    }

I've already tested the item separately, so I know it works fine. However, I still can't get my  mob to spawn with the item equipped. Is there anything else I have to do for this?

Link to comment
Share on other sites

That might be it. My Renderer currently extends MobRenderer. It looks like the following:

public class MyMobRenderer<Type extends MyMob> extends MobRenderer<Type, MyMobModel<Type>> {
    private static final ResourceLocation TEXTURE =
            new ResourceLocation(Main.MOD_ID, "textures/entities/my_mob.png");

    public MyMobRenderer(EntityRendererProvider.Context context) {
        super(context, new MyMobModel<>(context.bakeLayer(MyMobModel.LAYER_LOCATION)), 0.5f);
    }

    @Override
    public ResourceLocation getTextureLocation(MyMob entity) {
        return TEXTURE;
    }
}

I'll try extending HumanoidMobRenderer to see if that works.

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
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.