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

Started by The1GiantWalrus on Thu, 03/11/2021 - 16:48

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:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How do I use the player's skin for a mob?
Thu, 03/11/2021 - 16:48

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:
  • Tracker tickets:
  • 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 18:55, 25. Feb 2022
Joined Mar 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 00:06, 28. May 2022
Joined Mar 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • 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 00:29, 25. May 2022
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 00:29, 25. May 2022
Joined Dec 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
I know im using this in my…
Sat, 05/01/2021 - 14:13

I know im using this in my mod