Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.12.2] Player replace ModelRenderer


Recommended Posts

Hi, I'm trying to manipulate the player model yet again, but now it's in 1.12.2.

This time I wanted to try to replace the player's ModelBiped ModelRenderers, so I did. I replaced only the bipedBody variable but now the player's body part is not being rendered at all. From what I've seen the ModelRenderer contains no methods that actually render the model, which is why I thought that I could just replace it with a different model and still have it render just as before. Here is the code I have so far:

	private boolean initialized = false;
	private static final ResourceLocation rl = new ResourceLocation("examplemod", "models/boxbody.png");
	
	ModelBase bodyModel = null;
	ModelRenderer body = null;
	
	@SubscribeEvent
	public void RenderPlayerEvent(RenderPlayerEvent.Pre event)
	{
		if (!initialized)
		{
			bodyModel = new ModelBody();
			body = new ModelRenderer(bodyModel);
			event.getRenderer().getMainModel().bipedBody = body;
			initialized = true;
		}
		
		Minecraft.getMinecraft().renderEngine.bindTexture(rl);
	}
public class ModelBody extends ModelBase
{
	private final ModelRenderer body;
	
	public ModelBody()
	{
		textureWidth = 64;
		textureHeight = 32;
		
		
		body = new ModelRenderer(this, 0, 0);
		body.setRotationPoint(0.0F, 0.0F, 0.0F);
		body.addBox(-8.0F, -8.0F, -8.0F, 16, 16, 16, 0.0F);
	}
	
	@Override
	public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale)
	{
		body.render(scale);
	}
}

 

Any help or suggestions for a different approach are appreciated :)

Edited by ricepuffz
Link to post
Share on other sites
5 hours ago, diesieben07 said:

You can't do this, the whole model needs to be rendered with just one texture.

Thanks for the info. Still, I'm not sure how to set the texture that is going to be used for the model and after having looked through several classes, including the EntityPlayer class and all its superclasses, I can't seem to find a variable that hold the ResourceLocation to the texture or anything similar. The closest thing I found was:

public ResourceLocation getEntityTexture(AbstractClientPlayer entity)
{
    return entity.getLocationSkin();
}

in the RenderPlayer class, but I'm quite sure how I would make use of that. My guess would be that I would somehow have to let AbstractClientPlayer::hasSkin always return true and let AbstractClientPlayer::getLocationSkin return the ResourceLocation of the texture I want to use.

If I'm absolutely wrong and my approach can't work at all would you mind guiding me in the right direction?

Thanks!

Link to post
Share on other sites

That is the correct way to do it ;)

 

This is my code

 

@Mixin(value = AbstractClientPlayer.class)
public abstract class MixinAbstractClientPlayer extends MixinEntityPlayer
{
	@Shadow
	@Nullable
	protected abstract NetworkPlayerInfo getPlayerInfo();
    @Inject(method = "hasSkin", at = @At("RETURN"), cancellable = true)
	public void hasSkin(CallbackInfoReturnable<Boolean> cir)
	{
		PlayerSkin.HasSkin event = new PlayerSkin.HasSkin(getPlayerInfo(), cir.getReturnValue());
		MinecraftForge.EVENT_BUS.post(event);
		cir.setReturnValue(event.result);
	}
	
	@Inject(method = "getLocationSkin()Lnet/minecraft/util/ResourceLocation;", at = @At("RETURN"), cancellable = true)
	public void getSkin(CallbackInfoReturnable<ResourceLocation> cir)
	{
		PlayerSkin.GetSkin event = new PlayerSkin.GetSkin(getPlayerInfo(), cir.getReturnValue());
		MinecraftForge.EVENT_BUS.post(event);
		cir.setReturnValue(event.skinLocation);
	}
}

 

  • Thanks 1
Link to post
Share on other sites
59 minutes ago, cookiedragon234 said:

That is the correct way to do it ;)

 

This is my code

 


@Mixin(value = AbstractClientPlayer.class)
public abstract class MixinAbstractClientPlayer extends MixinEntityPlayer
{
	@Shadow
	@Nullable
	protected abstract NetworkPlayerInfo getPlayerInfo();
    @Inject(method = "hasSkin", at = @At("RETURN"), cancellable = true)
	public void hasSkin(CallbackInfoReturnable<Boolean> cir)
	{
		PlayerSkin.HasSkin event = new PlayerSkin.HasSkin(getPlayerInfo(), cir.getReturnValue());
		MinecraftForge.EVENT_BUS.post(event);
		cir.setReturnValue(event.result);
	}
	
	@Inject(method = "getLocationSkin()Lnet/minecraft/util/ResourceLocation;", at = @At("RETURN"), cancellable = true)
	public void getSkin(CallbackInfoReturnable<ResourceLocation> cir)
	{
		PlayerSkin.GetSkin event = new PlayerSkin.GetSkin(getPlayerInfo(), cir.getReturnValue());
		MinecraftForge.EVENT_BUS.post(event);
		cir.setReturnValue(event.skinLocation);
	}
}

 

I'm pretty sure Mixin didn't exist in 1.12.2 though? I can't find any of the classes you specified in your code in the forge version I am using (forge-1.12.2-14.23.5.2768)

Thanks for the idea tho! I'll do some more research on modifying vanilla code tomorrow and see if I can do it myself :)

Edited by ricepuffz
Link to post
Share on other sites
1 hour ago, ricepuffz said:

I'm pretty sure Mixin didn't exist in 1.12.2 though? I can't find any of the classes you specified in your code in the forge version I am using (forge-1.12.2-14.23.5.2768)

Thanks for the idea tho! I'll do some more research on modifying vanilla code tomorrow and see if I can do it myself :)

That is coremodding. It is not recommended on this forum. In fact, your problem does not need coremodding to solve.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Link to post
Share on other sites
8 hours ago, DavidM said:

That is coremodding. It is not recommended on this forum. In fact, your problem does not need coremodding to solve.

Well, how would I go about achieving a different entity texture without coremodding then? As I said, I couldn't figure it out myself by looking at all the forge provided classes.

Thanks for all the information though! :)

Link to post
Share on other sites

Okay, so since no more replies were coming in I decided to read up on the JVM architecture as well as Java bytecode and ASM and managed to create a coremod to do what I explained in a previous post of mine, which works just fine. Now I'm running into the issue of the skin not loading right, aka even with the standard player model and a skin file which is just a full on 64x64 black and white gradient with no transparent pixels the player looks black and pink like this: 

image.png.8a4875f6f4c88b963c1f1eff05f44b49.png

I am certain that it's not an issue with the bytecode manipulation itself, but more that my approach is still wrong (or that the png format is not being accepted or whatever), which is why I think that it's okay to continue this thread (correct me if this is straight up a coremodding issue, although I don't really know where else to look for help if not here). This was my last idea so I'm kind of desperate now :"

I would be more than glad if someone could help me. (Even suggestions of different approaches or hypotheses would be highly appreciated)

 

If any more information of what I've done so far is required just ask and I'll add it.

 

Also I found this thread where the exact same issue with the skin was present: https://www.minecraftforge.net/forum/topic/44152-bug-only-a-few-custom-skins-work/

 

Link to post
Share on other sites
Guest
This topic is now closed to further replies.


×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.