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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now


×
×
  • Create New...

Important Information

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