Jump to content

[SOLVED] [1.12.2] How can I detect if the player skin type is slim or default in rendering?


FlashHUN

Recommended Posts

I need to create a tameable mob that is a complete clone of the player and the player is the owner of it. How could I detect what the owner's skin type is in the rendering?

 

Renderer's constructor:

	public RenderShadowClone(RenderManager rendermanagerIn, boolean useSmallArms) {
		super(rendermanagerIn, new ModelPlayer(0.0F, useSmallArms), 0.5F);
	}

RenderHandler:

		RenderingRegistry.registerEntityRenderingHandler(EntityShadowClone.class, new IRenderFactory<EntityShadowClone>() {
			@Override
			public Render<? super EntityShadowClone> createRenderFor(RenderManager manager) {
				return new RenderShadowClone(manager, false);
			}
		});

 

Edited by FlashHUN
marked as solved
Link to comment
Share on other sites

4 minutes ago, diesieben07 said:

Render#doRender gets the entity passed in. From that you need to determine which model to render.

So in the RenderShadowClone class it should look something like this?

public class RenderShadowClone extends RenderLiving<EntityShadowClone> {
    
	private static boolean smallArms;
	
	public RenderShadowClone(RenderManager rendermanagerIn) {
		super(rendermanagerIn, new ModelPlayer(0.0F, smallArms), 0.5F);
	}

	@Override
	public ModelPlayer getMainModel()
    {
        return (ModelPlayer)super.getMainModel();
    }

	@Override
	protected ResourceLocation getEntityTexture(EntityShadowClone entity) {
		ResourceLocation skin = null;
		if (entity.getOwner() != null) {
			skin = ((AbstractClientPlayer) entity.getOwner()).getLocationSkin();
		}
		else {
			skin = DefaultPlayerSkin.getDefaultSkinLegacy();
		}
		return skin;
	}
	
	@Override
	protected void applyRotations(EntityShadowClone entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) {
		super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks);
	}
	
	@Override
	public void doRender(EntityShadowClone entity, double x, double y,
			double z, float entityYaw, float partialTicks) {
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
		if (((AbstractClientPlayer) entity.getOwner()).getSkinType() == "default") {
			this.smallArms = false;
		}
		else {
			this.smallArms = true;
		}
	}
}

 

Link to comment
Share on other sites

3 minutes ago, diesieben07 said:
  • You cannot compare Strings using ==. Please learn basic Java.
  • Why is smallArms static?
  • smallArms is a static field, why are you accessing it using this? Your IDE should be giving you a warning about this. And again, please learn basic Java.
  • Your smallArms field does nothing. You only ever write to it, you never read it.
public class RenderShadowClone extends RenderLiving<EntityShadowClone> {
    
	private static boolean smallArms;
	
	public RenderShadowClone(RenderManager rendermanagerIn) {
		super(rendermanagerIn, new ModelPlayer(0.0F, getSmallArms()), 0.5F);
	}

	@Override
	public ModelPlayer getMainModel()
    {
        return (ModelPlayer)super.getMainModel();
    }
	
	public static boolean getSmallArms() {
		return smallArms;
	}

	@Override
	protected ResourceLocation getEntityTexture(EntityShadowClone entity) {
		ResourceLocation skin = null;
		if (entity.getOwner() != null) {
			skin = ((AbstractClientPlayer) entity.getOwner()).getLocationSkin();
		}
		else {
			skin = DefaultPlayerSkin.getDefaultSkinLegacy();
		}
		return skin;
	}
	
	@Override
	protected void applyRotations(EntityShadowClone entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) {
		super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks);
	}
	
	@Override
	public void doRender(EntityShadowClone entity, double x, double y,
			double z, float entityYaw, float partialTicks) {
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
		if (((AbstractClientPlayer) entity.getOwner()).getSkinType().equals("default")) {
			smallArms = false;
		}
		else {
			smallArms = true;
		}
	}
}

Is this better?

The smallArms and getSmallArms() booleans are static because I get this error in the constructor when they're not:

Quote

Cannot refer to an instance method while explicitly invoking a constructor

 

Link to comment
Share on other sites

7 minutes ago, diesieben07 said:

This will not work. You need to learn basic programming.

You need two ModelPlayer instances.

	private ModelPlayer playerDef = new ModelPlayer(0.0F, false);
	private ModelPlayer playerSlim = new ModelPlayer(0.0F, true);

Yes, and what should I do with those and where? Sorry for bothering you so much with this, I'm just a bit lost

Edited by FlashHUN
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

When rendering choose if you want small arms or not. And then render one or the other.

		RenderingRegistry.registerEntityRenderingHandler(EntityShadowClone.class, new IRenderFactory<EntityShadowClone>() {
			@Override
			public Render<? super EntityShadowClone> createRenderFor(RenderManager manager) {
				return new RenderShadowClone(manager);
			}
		});

So, in here? If so, how?

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

No. That is where your renderer is registered. Rendering happens in Render#doRender.

Alright, I am completely lost...

public class RenderShadowClone extends RenderLiving<EntityShadowClone> {
    
	private ModelPlayer playerDef = new ModelPlayer(0.0F, false);
	private ModelPlayer playerSlim = new ModelPlayer(0.0F, true);
	
	public RenderShadowClone(RenderManager rendermanagerIn) {
		super(rendermanagerIn, *model*, 0.5F);
	}

	@Override
	public ModelPlayer getMainModel()
    {
        return (ModelPlayer)super.getMainModel();
    }

	@Override
	protected ResourceLocation getEntityTexture(EntityShadowClone entity) {
		ResourceLocation skin = null;
		if (entity.getOwner() != null) {
			skin = ((AbstractClientPlayer) entity.getOwner()).getLocationSkin();
		}
		else {
			skin = DefaultPlayerSkin.getDefaultSkinLegacy();
		}
		return skin;
	}
	
	@Override
	protected void applyRotations(EntityShadowClone entityLiving, float p_77043_2_, float rotationYaw, float partialTicks) {
		super.applyRotations(entityLiving, p_77043_2_, rotationYaw, partialTicks);
	}
	
	@Override
	public void doRender(EntityShadowClone entity, double x, double y,
			double z, float entityYaw, float partialTicks) {
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
		if (entity.getOwner() != null && entity.getOwner() instanceof EntityPlayer) {
			if (((AbstractClientPlayer) entity.getOwner()).getSkinType().equals("default")) {
				
			}
			else {
				
			}
		}
		else {
			
		}
	}
}

What exactly should I be doing, what method should I be using?

Link to comment
Share on other sites

5 minutes ago, diesieben07 said:
  • Have you looked at the versions of doRender in your superclasses? In particular RenderLivingBase, where the actual interesting rendering happens.
  • You need to set RenderLivingBase#mainModel accordingly before rendering or do the whole rendering manually.

Yes, I have looked at the versions of doRender in my supers, but I haven't found anything I could use.

Should my doRender look like this then?

	@Override
	public void doRender(EntityShadowClone entity, double x, double y,
			double z, float entityYaw, float partialTicks) {
		if (entity.getOwner() != null && entity.getOwner() instanceof EntityPlayer) {
				if (((AbstractClientPlayer) entity.getOwner()).getSkinType().equals("default")) {
					mainModel = playerDef;
				}
				else {
					mainModel = playerSlim;
				}
			}
			else {
				mainModel = playerDef;
			}
		super.doRender(entity, x, y, z, entityYaw, partialTicks);
	}

If so, how can I then get that in the constructor?

	public RenderShadowClone(RenderManager rendermanagerIn) {
		super(rendermanagerIn, getMainModel(), 0.5F);
	}

gives me this error:

Quote

Cannot refer to an instance method while explicitly invoking a constructor

 

Link to comment
Share on other sites

2 minutes ago, diesieben07 said:

Have you looked at what the super constructor does with the model you give it? It simply sets mainModel. So since you overwrite that one every time you render anyways, there is no need to pass anything useful here. Just pass either of the two models.

 

Please, learn to read the code you are using.

Thank you for all the help and sorry, I'm just simply new to all of this with only a littlebit of basic knowledge of java.

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried to play a mod for forge 1.20.2 and the mod didn't work, fix this please.
    • EntityRenders requires an EntityRenderProvider. This is what I have: @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { @SubscribeEvent public static void clientSetup(FMLClientSetupEvent event) { EntityRenderers.register(HOSE.get(), new HoseEntityRenderFactory()); } private static class HoseEntityRenderFactory implements EntityRendererProvider<HoseEntity> { @Override public EntityRenderer<HoseEntity> create(Context context) { return new HoseEntityRenderer<>(context); } } } Replace HoseEntity with your own entity. If you're doing multiple try doing generics (though untested).
    • First off, I know should probably be able to debug this on my own, but this is my first mod, and I couldn't figure it out for multiple days now. What I'm trying to do, is to modify the default minecart by replacing it with a slightly different version, but I'm stuck 1 step before that, that being "cloning" the minecart as a separate Entity/Item. Here you can see a GitHub gist of all relevant files: https://gist.github.com/Kipama/cd39127e8891715a3006fa990ca7ff14 If there are files missing or access isn't working as intended, please let me know! In the Gist you can find the following files: -CustomMinecartEntity.java:        This file extends AbstractMinecart and is a clone of the vanilla minecart entity. I know I should override the minecart entity directly, but as this should work rn, I didn't change it yet. -CustomMinecartRenderer.java:  Basically vanilla MinecartRenderer with a Custom slapped on it, extends MinecraftRenderer. -ModEntities.java:                         This is where the new Entity gets added to the deferred register ENTITY_TYPES. -ModernMinecarts.java:               The main mod file. Relevant part is at the bottom, where I try to use onClientSetup to register the new Entity using EntityRenderers.register(). That last part is where my problem begins. When I try to register the new entity using EntityRenderers.register(ModEntities.CUSTOM_MINECART_ENTITY.get(), CustomMinecartRenderer::new); I get a syntax Error saying the provided and required types don't match. These are the required and provided types: ModEntities.CUSTOM_MINECART_ENTITY.get(): Required: EntityType<? extends T> Provided:EntityType<CustomMinecartEntity> CustomMinecartRenderer::new: Required: EntityRendererProvider<T> Provided:<method reference   So far I looked at 2 different Git repositories implementing custom entities, but haven't been able to figure out what I'm doing wrong. Any answers, suggestions and ridicules appreciated.
    • Yes, it is. I found out how to do it. (for Forge 1.20.1) Add this to main class constructor: // ... MinecraftForge.EVENT_BUS.<PlayerInteractEvent.EntityInteract>addListener(e -> { Player playerWhoUsed = e.getEntity(); ItemStack usedItemStack = e.getItemStack(); Entity entityThatWasClicked = e.getTarget(); if (usedItemStack.getItem() instanceof YourItem item) { // your code... e.setCancelled(true); // you can remove this if you want to continue interaction } } // ...
    • Hi there, I'm hoping to create a block that renders a fake skybox, blocking anything behind it. There are a couple of mods that already do this, but they are very outdated. One example: https://github.com/Elix-x/Skyblocks/ https://www.curseforge.com/minecraft/mc-mods/skyblocks I'm not familiar enough with rendering to be able to port it. Is there anyone who can point me in the right direction? Any help would be appreciated.
  • Topics

×
×
  • Create New...

Important Information

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