How do I use the player's skin for a mob?

Started by The1GiantWalrus on

Topic category: Help with modding (Java Edition)

Last seen on 14:47, 12. Mar 2021
Joined Sep 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I use the player's skin for a mob?

I want to make a mob that disguises itself as a player. I've got its AI pretty much done, but I want it to copy the skin of the player. How would I go about doing this? (A tutorial would be appreciated)

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it can be done but requires…
Fri, 03/12/2021 - 13:01

it can be done but requires you to edit code of your entity (around 30+ lines of code to manually add)

Last seen on 01:09, 29. Aug 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Can you post an example of…
Fri, 03/12/2021 - 17:06

Can you post an example of how to do this, Ahznb?

Last seen on 01:27, 24. Jan 2023
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Just Go To Blockbench Then…
Sat, 03/13/2021 - 02:47

Just Go To Blockbench Then Click the Minecraft Skin Button Choose The Mob You Want

You Can Add Some Parts To It And Change The Texture Because It Does Not Have Any Color

When You Are Done Click On File And Click Convert Project

Convert It To A Modded Entity

Click On File Again Hover On Export And Export it As A Java Entity

Then Save The File

Go To The MCreator Workspace

Click On Import Java 3D Model

Go To Your Mod Element And Change The Entity Model To Your Imported Java Entity

Add Your Texture

And There Done 

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
first, add an AI goal to…
Sat, 03/13/2021 - 07:24

first, add an AI goal to your entity "watch closest entity in radius [x] of type [EntityPlayer]", no conditions. save and build.

next, edit the code of your mod entity. this will open the source code editor.

you will need to create a server to client sync data field in your entity class. find your entity's class and add a data sync field to send player id data from server to client, register the data field, and create methods to get/set the data. then override the new added AI goal to set the player id to the player this entity is looking at:

public static class CustomEntity extends MonsterEntity {
    private static final DataParameter<Integer> PLAYER_ID = EntityDataManager.<Integer>createKey(CustomEntity.class, DataSerializers.VARINT);

    public CustomEntity(FMLPlayMessages.SpawnEntity packet, World world) {
        this(entity, world);
    }

    ...

    @Override
    protected void registerData() {
        super.registerData();
        this.getDataManager().register(PLAYER_ID, 0);
    }

    public int getPlayerId() {
        return this.dataManager.get(PLAYER_ID);
    }

    public void setPlayerId(PlayerEntity player) {
        this.dataManager.set(PLAYER_ID, player.getEntityId());
    }

    ...

    @Override
    protected void registerGoals() {
        super.registerGoals();
        ...
        this.goalSelector.addGoal(2, new LookAtGoal(this, PlayerEntity.class, (float) 50) {
            @Override
            public void tick() {
                super.tick();
                if (CustomEntity.this.getPlayerId() < 0 && this.closestEntity instanceof PlayerEntity && !((PlayerEntity)this.closestEntity).isCreative()) {
                    CustomEntity.this.setPlayerId((PlayerEntity)this.closestEntity);
                    this.entity.setCustomName(this.closestEntity.getName());
                }					
            }
        });
        ...
    }

next you will need to modify the custom renderer for so that it will check if a player id is set. if so, change the texture to the player's texture. Note: you will also need to do some other modifications like changing the texture size of the model to 64x64 and the change the model scale, since player textures are 64x64. here's an example:

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public void registerModels(ModelRegistryEvent event) {
    RenderingRegistry.registerEntityRenderingHandler(entity, renderManager -> {
    BipedRenderer customRender = new BipedRenderer(renderManager, new CustomModel(), 0.5f) {
        @Override
        public ResourceLocation getEntityTexture(Entity entityIn) {
            int playerId = ((CustomEntity)entityIn).getPlayerId();
            if (playerId >= 0 && ((LivingEntity)entityIn).getHealth() > 0f) {
                Entity player = entityIn.world.getEntityByID(playerId);
                if (player instanceof AbstractClientPlayerEntity)
                    return ((AbstractClientPlayerEntity)player).getLocationSkin();
            }
            return new ResourceLocation("...");
        }
        @Override
        protected void preRenderCallback(LivingEntity entityIn, MatrixStack matrixStackIn, float partialTickTime) {
            matrixStackIn.scale(0.9375F, 0.9375F, 0.9375F);
        }				
    };
    ...
}

public static class CustomModel extends BipedModel<CustomEntity> {
    public CustomModel() {
        super(0f, 0f, 64, 64);
    }
}

Note: make sure you change your entity's model texture to 64x64 as well. mcreator defaults to using the 64x32 biped model.

now see if it works!

Last seen on 05:29, 31. Jan 2022
Joined Nov 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
made a mistake. change one…
Sat, 03/13/2021 - 07:35

made a mistake. change one line:

this.getDataManager().register(PLAYER_ID, 0);

to: 

this.getDataManager().register(PLAYER_ID, -1);

 

Last seen on 14:09, 25. Oct 2023
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
This is so great! I need all…
Sat, 05/01/2021 - 13:05

This is so great! I need all of this, but I have a question, where do I find all of this code? 

Last seen on 14:09, 25. Oct 2023
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
To clarify more, where would…
Sat, 05/01/2021 - 13:26

To clarify more, where would I go to find this in the code? Would I just create a "custom element" with Mcreator or do I have to go in some source files or something specific?

Last seen on 23:41, 3. Jun 2021
Joined Dec 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I know im using this in my…
Sat, 05/01/2021 - 14:13

I know im using this in my mod

Last seen on 03:37, 27. Feb 2024
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
. . . what? how when what…
Sun, 08/06/2023 - 14:52

. . . what? how when what code how add and what

 

Last seen on 12:53, 15. Sep 2023
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
yeah im trying to get this…
Mon, 08/07/2023 - 20:44

yeah im trying to get this to work but am so confused

Last seen on 12:53, 15. Sep 2023
Joined Mar 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
so if someone could help me…
Mon, 08/07/2023 - 20:44

so if someone could help me that would be great my discord is pancakes3

Last seen on 06:30, 25. Feb 2024
Joined Aug 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I also would like…
Wed, 12/27/2023 - 05:06

I also would like clarification on this, It wasn't explained too well...