Jump to content

Recommended Posts

Posted

Hello,

I added an item, which makes the player's arm point in the direction the player is looking.

The rendering of the arm is working, but the item is always rendering at the body of the player.

I know there is the LayerHeldItem class, which renders the item, but i don't know how to remove the normal LayerHeldItem and add a new one.

Is there also a way to do this without creating a new RenderPlayer class?

Here is my code:

Spoiler

public class FlareGunHandler 
{
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPrePlayerRender(RenderPlayerEvent.Pre event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote);
		{
			EntityPlayer player = event.getEntityPlayer();
			
			GlStateManager.pushMatrix();
			
			if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ToolFlareGun)
			{
				event.getRenderer().getMainModel().bipedRightArm.isHidden = true;
			}
			if(player.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ToolFlareGun)
			{
				event.getRenderer().getMainModel().bipedLeftArm.isHidden = true;
			}
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPostPlayerRender(RenderPlayerEvent.Post event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote)
		{
			EntityPlayer playerR = event.getEntityPlayer();
			EntityPlayer playerC = Minecraft.getMinecraft().player;
			float yRotationPoint = 20.5F;
			
			if(!playerR.equals(playerC))
			{
				GlStateManager.translate(Utils.getPlayerXOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerYOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerZOffset(playerR, playerC, event.getPartialRenderTick()));
			}
			
			if(playerR.isSneaking())
			{
				yRotationPoint = 16.5F; 
			}
			
			if(playerR.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ToolFlareGun)
			{

				//rotate arm
				event.getRenderer().getMainModel().bipedRightArm.isHidden = false;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointX = -MathHelper.cos((float)Math.toRadians(playerR.renderYawOffset)) * 4.2F;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointY = yRotationPoint;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointZ = -MathHelper.sin((float)Math.toRadians(playerR.renderYawOffset)) * 5.0F;
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = (float)Math.toRadians(playerR.rotationPitch + 90.0D);
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleY = (float)-Math.toRadians(playerR.renderYawOffset);
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleZ = 0.0F;
				event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
				event.getRenderer().getMainModel().bipedRightArm.render(0.0625F);
				event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 2.0F;
				
				//rotate armor
			}
			if(playerR.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ToolFlareGun)
			{
				//rotate arm
				event.getRenderer().getMainModel().bipedLeftArm.isHidden = false;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointX = MathHelper.cos((float)Math.toRadians(playerR.renderYawOffset)) * 4.2F;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointY = yRotationPoint;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointZ = MathHelper.sin((float)Math.toRadians(playerR.renderYawOffset)) * 5.0F;
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleX = (float)Math.toRadians(playerR.rotationPitch + 90.0D);
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleY = (float)-Math.toRadians(playerR.renderYawOffset);
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleZ = 0.0F;
				event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
				event.getRenderer().getMainModel().bipedLeftArm.renderWithRotation(0.0625F);
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointY = 2.0F;
				
				//rotate armor
			}
			GlStateManager.popMatrix();
		}
	}
}

 

Spoiler

2019-10-09_18_14_26.thumb.png.84491045ec1598d50dd45f14e8dadc6e.png

 

Posted
2 hours ago, Lyon said:

But is there a way to change the item rotation based on the direction the player is looking?

Yes but you'll have to either cancel the players default rendering in the RenderPlayerEvent.Pre and then render everything your self the way you want it. Or you can use reflection to change the players model specifically for the layer the item is rendered in.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted
6 hours ago, Lyon said:

But is there a way to change the item rotation based on the direction the player is looking?

One small point: the item's position will be relative to the arm which you are already adjusting to match the direction the player is looking, so you shouldn't actually need the item to do any additional rotation itself; just have it set up in the json file. Right?

  • Thanks 1
Posted
21 hours ago, salvestrom said:

Right?

No he makes the arm invisible in the Pre event so it doesnt render via PlayerRenderer but instead renders in the Post event. Therefore the item has already be rendered at the normal arm position.

 

25 minutes ago, Lyon said:

but how can I cancel the normal rendring of the the item.

Not sure you'll have to look at the code where it renders the item(s) being held.

  • Thanks 1

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I got it working, but I am not sure if it is the best solution.

Thank you very much!

However here is my code:

Spoiler

	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPrePlayerRender(RenderPlayerEvent.Pre event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote);
		{
			EntityPlayer player = event.getEntityPlayer();
			
			GlStateManager.pushMatrix();
			
			if(player.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ToolFlareGun)
			{
				this.cancelItemRendering(event.getRenderer());
				event.getRenderer().getMainModel().bipedRightArm.isHidden = true;
			}
			if(player.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ToolFlareGun)
			{
				this.cancelItemRendering(event.getRenderer());
				event.getRenderer().getMainModel().bipedLeftArm.isHidden = true;
			}
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPostPlayerRender(RenderPlayerEvent.Post event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote)
		{
			EntityPlayer playerR = event.getEntityPlayer();
			EntityPlayer playerC = Minecraft.getMinecraft().player;
			float yRotationPoint = 20.5F;
			
			if(!playerR.equals(playerC))
			{
				GlStateManager.translate(Utils.getPlayerXOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerYOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerZOffset(playerR, playerC, event.getPartialRenderTick()));
			}
			
			if(playerR.isSneaking())
			{
				yRotationPoint = 16.5F; 
			}
			
			if(playerR.getHeldItem(EnumHand.MAIN_HAND).getItem() instanceof ToolFlareGun)
			{
				//rotate arm
				event.getRenderer().getMainModel().bipedRightArm.isHidden = false;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointX = -MathHelper.cos((float)Math.toRadians(playerR.renderYawOffset)) * 4.5F;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointY = yRotationPoint;
				event.getRenderer().getMainModel().bipedRightArm.rotationPointZ = -MathHelper.sin((float)Math.toRadians(playerR.renderYawOffset)) * 4.7F;
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleX = (float)Math.toRadians(playerR.rotationPitch + 90.0D);
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleY = (float)-Math.toRadians(playerR.rotationYaw);
				event.getRenderer().getMainModel().bipedRightArm.rotateAngleZ = 0.0F;
				this.renderHeldItem((EntityLivingBase)playerR, playerR.getHeldItem(EnumHand.MAIN_HAND), (RenderLivingBase)event.getRenderer(), ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
				event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
				event.getRenderer().getMainModel().bipedRightArm.renderWithRotation(0.0625F);
				event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 2.0F;
				
				//rotate armor
				
				this.addItemRendering(event.getRenderer());
			}
			
			if(playerR.getHeldItem(EnumHand.OFF_HAND).getItem() instanceof ToolFlareGun)
			{
				//rotate arm
				event.getRenderer().getMainModel().bipedLeftArm.isHidden = false;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointX = MathHelper.cos((float)Math.toRadians(playerR.renderYawOffset)) * 4.5F;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointY = yRotationPoint;
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointZ = MathHelper.sin((float)Math.toRadians(playerR.renderYawOffset)) * 4.7F;
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleX = (float)Math.toRadians(playerR.rotationPitch + 90.0D);
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleY = (float)-Math.toRadians(playerR.rotationYaw);
				event.getRenderer().getMainModel().bipedLeftArm.rotateAngleZ = 0.0F;
				this.renderHeldItem((EntityLivingBase)playerR, playerR.getHeldItem(EnumHand.OFF_HAND), (RenderLivingBase)event.getRenderer(), ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.LEFT);
				event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
				event.getRenderer().getMainModel().bipedLeftArm.renderWithRotation(0.0625F);
				event.getRenderer().getMainModel().bipedLeftArm.rotationPointY = 2.0F;
				
				//rotate armor
				
				this.addItemRendering(event.getRenderer());
			}
			
			GlStateManager.popMatrix();
		}
	}
	
	public void renderHeldItem(EntityLivingBase entity, ItemStack stack, RenderLivingBase<EntityPlayer> r, ItemCameraTransforms.TransformType camera, EnumHandSide handSide)
	{
		 GlStateManager.pushMatrix();
		 
		 if (r.getMainModel().isChild)
         {
             GlStateManager.translate(0.0F, 0.75F, 0.0F);
             GlStateManager.scale(0.5F, 0.5F, 0.5F);
         }
         
         ((ModelBiped)r.getMainModel()).postRenderArm(0.0625F, handSide);
         
         GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
         GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
         boolean isLeft = handSide == EnumHandSide.LEFT;
         GlStateManager.translate(0.0625F, 0.125F, -0.625F);
         Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, stack, camera, isLeft);
         
         GlStateManager.popMatrix();
	}
	
	public void addItemRendering(RenderPlayer render)
	{
		try 
		{
			Class c = RenderPlayer.class;
			Method m = this.getMethod(c, "addLayer");
			m.invoke(render, new LayerHeldItem(render));
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	public void cancelItemRendering(RenderPlayer render)
	{	
		try 
		{
			Class c = RenderPlayer.class;
			Field f = this.getField(c, "layerRenderers");
			Method m = this.getMethod(c, "addLayer");
			f.setAccessible(true);
			f.set(render, Lists.<LayerRenderer<AbstractClientPlayer>>newArrayList());
			m.invoke(render, new LayerBipedArmor(render));
			m.invoke(render, new LayerArrow(render));
			m.invoke(render, new LayerDeadmau5Head(render));
			m.invoke(render, new LayerCape(render));
			m.invoke(render, new LayerCustomHead(render.getMainModel().bipedHead));
			m.invoke(render, new LayerElytra(render));
			m.invoke(render, new LayerEntityOnShoulder(render.getRenderManager()));
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	public Field getField(Class clazz, String fieldName) throws Exception 
	{
	    try 
	    {
	    	return clazz.getDeclaredField(fieldName);
	    } 
	    catch (Exception e) 
	    {
	    	Class superClass = clazz.getSuperclass();
	    	if (superClass == null) 
	    	{
	    		throw e;
	    	} 
	    	else 
	    	{
	    		return getField(superClass, fieldName);
	    	}
	    }
	}
	
	public Method getMethod(Class clazz, String methodName) throws Exception 
	{
	    try 
	    {
	    	Method[] m = clazz.getDeclaredMethods();
	    	for(int i=0; i < m.length; i++)
	    	{
	    		if(m[i].getName().equals(methodName))
	    		{
	    			return m[i];
	    		}
	    	}
	    	throw new NoSuchFieldException();
	    } 
	    catch (Exception e) 
	    {
	    	Class superClass = clazz.getSuperclass();
	    	if (superClass == null) 
	    	{
	    		throw e;
	    	} 
	    	else 
	    	{
	    		return getMethod(superClass, methodName);
	    	}
	    }
	}

 

 

Posted

With what you're doing here, could you instead access the model file and insert an if statement to the animation method that checks for your item in hand and alters the angles there, before rendering?

Posted

So I improved some things and everything is working well in Eclipse.

But when I build the mod and launch it in minecraft, the item rendering isn't cancelled.

Here is my new code:

ItemRenderHandler:

Spoiler

public class ItemRenderHandler 
{
	private static final Item[] specialItems = {ItemInit.FLARE_GUN, ItemInit.Lamp};
	private boolean lastRender;
	private SpecialLayerHeldItem layer;
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPrePlayerRender(RenderPlayerEvent.Pre event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote);
		{
			EntityPlayer player = event.getEntityPlayer();
			
			if(this.contains(specialItems, player.getHeldItem(EnumHand.MAIN_HAND).getItem()) || this.contains(specialItems, player.getHeldItem(EnumHand.OFF_HAND).getItem()))
			{
				if(!lastRender)
				{
					layer = new SpecialLayerHeldItem(event.getRenderer());
					this.addLayerRender(event.getRenderer(), layer);
				}
				
				GlStateManager.pushMatrix();
				
				if((this.contains(specialItems, player.getHeldItem(EnumHand.MAIN_HAND).getItem()) && event.getEntityLiving().getPrimaryHand() == EnumHandSide.RIGHT) ||
				(this.contains(specialItems, player.getHeldItem(EnumHand.OFF_HAND).getItem()) && event.getEntityLiving().getPrimaryHand() == EnumHandSide.LEFT))
				{
					event.getRenderer().getMainModel().bipedRightArm.isHidden = true;
					layer.shouldRenderRightItem(false);
				}
				else
				{
					layer.shouldRenderRightItem(true);
				}
				
				if((this.contains(specialItems, player.getHeldItem(EnumHand.OFF_HAND).getItem()) && event.getEntityLiving().getPrimaryHand() == EnumHandSide.RIGHT) ||
				(this.contains(specialItems, player.getHeldItem(EnumHand.MAIN_HAND).getItem()) && event.getEntityLiving().getPrimaryHand() == EnumHandSide.LEFT))
				{
					event.getRenderer().getMainModel().bipedLeftArm.isHidden = true;
					layer.shouldRenderLeftItem(false);
				}
				else
				{
					layer.shouldRenderLeftItem(true);
				}
				
				lastRender = true;
			}
			else
			{
				lastRender = false;
				this.removeSpecialLayerRender(event.getRenderer());
			}
		}
	}
	
	@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onPostPlayerRender(RenderPlayerEvent.Post event)
	{
		if(event.getEntityPlayer().getEntityWorld().isRemote);
		{
			EntityPlayer playerR = event.getEntityPlayer();
			EntityPlayer playerC = Minecraft.getMinecraft().player;
			
			if(this.contains(specialItems, playerR.getHeldItem(EnumHand.MAIN_HAND).getItem()) || this.contains(specialItems, playerR.getHeldItem(EnumHand.OFF_HAND).getItem()))
			{
				if(!playerR.equals(playerC))
				{
					GlStateManager.translate(Utils.getPlayerXOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerYOffset(playerR, playerC, event.getPartialRenderTick()), Utils.getPlayerZOffset(playerR, playerC, event.getPartialRenderTick()));
				}
				
				if(layer != null && !layer.getRenderRightItem())
				{
					ItemStack stack = playerR.getHeldItem(event.getEntityLiving().getPrimaryHand() == EnumHandSide.RIGHT ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
					
					event.getRenderer().getMainModel().bipedRightArm.isHidden = false;
					
					if(stack.getItem() instanceof ToolLamp)
					{
						this.renderLamp(event.getRenderer().getMainModel(), playerR, EnumHandSide.RIGHT);
					}
					else if(stack.getItem() instanceof ToolFlareGun)
					{
						this.renderFlareGun(event.getRenderer().getMainModel(), playerR, EnumHandSide.RIGHT);
					}
					
					this.renderHeldItem((EntityLivingBase)playerR, stack, (RenderLivingBase)event.getRenderer(), ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
					
					event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
					event.getRenderer().getMainModel().bipedRightArm.renderWithRotation(0.0625F);
					event.getRenderer().getMainModel().bipedRightArm.rotationPointY = 2.0F;
				}
				
				if(layer != null && !layer.getRenderLeftItem())
				{
					ItemStack stack = playerR.getHeldItem(event.getEntityLiving().getPrimaryHand() == EnumHandSide.LEFT ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND);
					
					event.getRenderer().getMainModel().bipedLeftArm.isHidden = false;
					
					if(stack.getItem() instanceof ToolLamp)
					{
						this.renderLamp(event.getRenderer().getMainModel(), playerR, EnumHandSide.LEFT);
					}
					else if(stack.getItem() instanceof ToolFlareGun)
					{
						this.renderFlareGun(event.getRenderer().getMainModel(), playerR, EnumHandSide.LEFT);
					}
					
					this.renderHeldItem((EntityLivingBase)playerR, stack, (RenderLivingBase)event.getRenderer(), ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);
					
					event.getRenderer().bindTexture(event.getRenderer().getEntityTexture((AbstractClientPlayer)playerR));
					event.getRenderer().getMainModel().bipedLeftArm.renderWithRotation(0.0625F);
					event.getRenderer().getMainModel().bipedLeftArm.rotationPointY = 2.0F;
					
				}
				
				GlStateManager.popMatrix();
			}
		}
	}
	
	public void renderFlareGun(ModelPlayer model, EntityPlayer player, EnumHandSide hand)
	{
		if(hand == EnumHandSide.RIGHT)
		{
			model.bipedRightArm.rotationPointX = -MathHelper.cos((float)Math.toRadians(player.renderYawOffset)) * 4.5F;
			model.bipedRightArm.rotationPointY = player.isSneaking() ? 16.5F :  20.5F;
			model.bipedRightArm.rotationPointZ = -MathHelper.sin((float)Math.toRadians(player.renderYawOffset)) * 4.7F;
			model.bipedRightArm.rotateAngleX = (float)Math.toRadians(player.rotationPitch + 90.0D);
			model.bipedRightArm.rotateAngleY = (float)-Math.toRadians(player.rotationYaw);
			model.bipedRightArm.rotateAngleZ = 0.0F;
		}
		
		if(hand == EnumHandSide.LEFT)
		{
			model.bipedLeftArm.rotationPointX = MathHelper.cos((float)Math.toRadians(player.renderYawOffset)) * 4.5F;
			model.bipedLeftArm.rotationPointY = player.isSneaking() ? 16.5F :  20.5F;
			model.bipedLeftArm.rotationPointZ = MathHelper.sin((float)Math.toRadians(player.renderYawOffset)) * 4.7F;
			model.bipedLeftArm.rotateAngleX = (float)Math.toRadians(player.rotationPitch + 90.0D);
			model.bipedLeftArm.rotateAngleY = (float)-Math.toRadians(player.rotationYaw);
			model.bipedLeftArm.rotateAngleZ = 0.0F;
		}
	}
	
	public void renderLamp(ModelPlayer model, EntityPlayer player, EnumHandSide hand)
	{
		if(hand == EnumHandSide.RIGHT)
		{
			model.bipedRightArm.rotationPointX = -MathHelper.cos((float)Math.toRadians(player.renderYawOffset)) * 4.5F;
			model.bipedRightArm.rotationPointY = player.isSneaking() ? 16.5F :  20.5F;
			model.bipedRightArm.rotationPointZ = -MathHelper.sin((float)Math.toRadians(player.renderYawOffset)) * 4.7F;
			model.bipedRightArm.rotateAngleX = (float)Math.toRadians(90.0F);
			model.bipedRightArm.rotateAngleY = (float)-Math.toRadians(player.renderYawOffset);
			model.bipedRightArm.rotateAngleZ = 0.0F;
		}
		
		if(hand == EnumHandSide.LEFT)
		{
			model.bipedLeftArm.rotationPointX = MathHelper.cos((float)Math.toRadians(player.renderYawOffset)) * 4.5F;
			model.bipedLeftArm.rotationPointY = player.isSneaking() ? 16.5F :  20.5F;
			model.bipedLeftArm.rotationPointZ = MathHelper.sin((float)Math.toRadians(player.renderYawOffset)) * 4.7F;
			model.bipedLeftArm.rotateAngleX = (float)Math.toRadians(90.0F);
			model.bipedLeftArm.rotateAngleY = (float)-Math.toRadians(player.renderYawOffset);
			model.bipedLeftArm.rotateAngleZ = 0.0F;
		}
	}
	
	public void renderHeldItem(EntityLivingBase entity, ItemStack stack, RenderLivingBase<EntityPlayer> r, ItemCameraTransforms.TransformType camera, EnumHandSide handSide)
	{
		 GlStateManager.pushMatrix();
		 
		 if (r.getMainModel().isChild)
         {
             GlStateManager.translate(0.0F, 0.75F, 0.0F);
             GlStateManager.scale(0.5F, 0.5F, 0.5F);
         }
         
         ((ModelBiped)r.getMainModel()).postRenderArm(0.0625F, handSide);
         
         GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
         GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
         boolean isLeft = handSide == EnumHandSide.LEFT;
         GlStateManager.translate((float)(isLeft ? -1 : 1) / 16.0F, 0.125F, -0.625F);
         Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, stack, camera, isLeft);
         
         GlStateManager.popMatrix();
	}
	
	public void addLayerRender(RenderPlayer render, LayerRenderer<EntityLivingBase> layer)
	{	
		try 
		{
			Class c = RenderPlayer.class;
			Field f = this.getField(c, "layerRenderers");
			Method m = this.getMethod(c, "addLayer");
			f.setAccessible(true);
			f.set(render, Lists.<LayerRenderer<AbstractClientPlayer>>newArrayList());
			m.invoke(render, new LayerBipedArmor(render));
			m.invoke(render, new LayerArrow(render));
			m.invoke(render, new LayerDeadmau5Head(render));
			m.invoke(render, new LayerCape(render));
			m.invoke(render, new LayerCustomHead(render.getMainModel().bipedHead));
			m.invoke(render, new LayerElytra(render));
			m.invoke(render, new LayerEntityOnShoulder(render.getRenderManager()));
			m.invoke(render, layer);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	public void removeSpecialLayerRender(RenderPlayer render)
	{	
		try 
		{
			Class c = RenderPlayer.class;
			Field f = this.getField(c, "layerRenderers");
			Method m = this.getMethod(c, "addLayer");
			f.setAccessible(true);
			f.set(render, Lists.<LayerRenderer<AbstractClientPlayer>>newArrayList());
			m.invoke(render, new LayerBipedArmor(render));
			m.invoke(render, new LayerArrow(render));
			m.invoke(render, new LayerDeadmau5Head(render));
			m.invoke(render, new LayerCape(render));
			m.invoke(render, new LayerCustomHead(render.getMainModel().bipedHead));
			m.invoke(render, new LayerElytra(render));
			m.invoke(render, new LayerEntityOnShoulder(render.getRenderManager()));
			m.invoke(render, new LayerHeldItem(render));
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
		}
	}
	
	public Field getField(Class clazz, String fieldName) throws Exception 
	{
	    try 
	    {
	    	return clazz.getDeclaredField(fieldName);
	    } 
	    catch (Exception e) 
	    {
	    	Class superClass = clazz.getSuperclass();
	    	if (superClass == null) 
	    	{
	    		throw e;
	    	} 
	    	else 
	    	{
	    		return getField(superClass, fieldName);
	    	}
	    }
	}
	
	public Method getMethod(Class clazz, String methodName) throws Exception 
	{
	    try 
	    {
	    	Method[] m = clazz.getDeclaredMethods();
	    	for(int i=0; i < m.length; i++)
	    	{
	    		if(m[i].getName().equals(methodName))
	    		{
	    			return m[i];
	    		}
	    	}
	    	throw new NoSuchFieldException();
	    } 
	    catch (Exception e) 
	    {
	    	Class superClass = clazz.getSuperclass();
	    	if (superClass == null) 
	    	{
	    		throw e;
	    	} 
	    	else 
	    	{
	    		return getMethod(superClass, methodName);
	    	}
	    }
	}
	
	public boolean contains(Object[] array, Object obj)
	{
		for(int i=0; i < array.length; i++)
		{
			if(array[i].equals(obj))
			{
				return true;
			}
		}
		return false;
	}
}

 

SpecialLayerHeldItem:

Spoiler

public class SpecialLayerHeldItem implements LayerRenderer<EntityLivingBase>
{
	protected final RenderLivingBase<?> livingEntityRenderer;
	private boolean renderLeftItem, renderRightItem;
	
	public SpecialLayerHeldItem(RenderLivingBase<?> livingEntityRendererIn) 
	{
		 this.livingEntityRenderer = livingEntityRendererIn;
	}
	
	@Override
	public void doRenderLayer(EntityLivingBase entitylivingbaseIn, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch, float scale) 
	{
		boolean flag = entitylivingbaseIn.getPrimaryHand() == EnumHandSide.RIGHT;
        ItemStack itemstack = flag ? entitylivingbaseIn.getHeldItemOffhand() : entitylivingbaseIn.getHeldItemMainhand();
        ItemStack itemstack1 = flag ? entitylivingbaseIn.getHeldItemMainhand() : entitylivingbaseIn.getHeldItemOffhand();

        if (!itemstack.isEmpty() || !itemstack1.isEmpty())
        {
            GlStateManager.pushMatrix();

            if (this.livingEntityRenderer.getMainModel().isChild)
            {
                float f = 0.5F;
                GlStateManager.translate(0.0F, 0.75F, 0.0F);
                GlStateManager.scale(0.5F, 0.5F, 0.5F);
            }

            if(renderRightItem)
            {
            	this.renderHeldItem(entitylivingbaseIn, itemstack1, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
            }
            
            if(renderLeftItem)
            {
            	this.renderHeldItem(entitylivingbaseIn, itemstack, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);
            }
            
            GlStateManager.popMatrix();
        }
	}
	
	private void renderHeldItem(EntityLivingBase p_188358_1_, ItemStack p_188358_2_, ItemCameraTransforms.TransformType p_188358_3_, EnumHandSide handSide)
    {
        if (!p_188358_2_.isEmpty())
        {
            GlStateManager.pushMatrix();

            if (p_188358_1_.isSneaking())
            {
                GlStateManager.translate(0.0F, 0.2F, 0.0F);
            }

            this.translateToHand(handSide);
            GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
            GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
            boolean flag = handSide == EnumHandSide.LEFT;
            GlStateManager.translate((float)(flag ? -1 : 1) / 16.0F, 0.125F, -0.625F);
            Minecraft.getMinecraft().getItemRenderer().renderItemSide(p_188358_1_, p_188358_2_, p_188358_3_, flag);
            GlStateManager.popMatrix();
        }
    }

    protected void translateToHand(EnumHandSide p_191361_1_)
    {
        ((ModelBiped)this.livingEntityRenderer.getMainModel()).postRenderArm(0.0625F, p_191361_1_);
    }

    public boolean shouldCombineTextures()
    {
        return false;
    }
    
    public void shouldRenderRightItem(boolean b)
    {
    	renderRightItem = b;
    }
    
    public void shouldRenderLeftItem(boolean b)
    {
    	renderLeftItem = b;
    }
    
    public boolean getRenderRightItem()
    {
    	return renderRightItem;
    }
    
    public boolean getRenderLeftItem()
    {
    	return renderLeftItem;
    }
}

 

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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