Skip to content

Commit

Permalink
Let anchor use anchor X and Z values as well
Browse files Browse the repository at this point in the history
  • Loading branch information
mchorse committed Mar 4, 2020
1 parent 9b2e7fe commit fe5cb7e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import mchorse.blockbuster.client.model.ModelCustom;
import mchorse.blockbuster.client.model.ModelCustomRenderer;
import mchorse.blockbuster.client.render.layer.LayerHeldItem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
Expand All @@ -25,49 +26,9 @@ public static void renderItems(EntityLivingBase entity, ModelCustom model, float
if (itemstack != null || itemstack1 != null)
{
GlStateManager.pushMatrix();
renderHeldItem(entity, model, itemstack, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);
renderHeldItem(entity, model, itemstack1, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
LayerHeldItem.renderHeldItem(entity, itemstack, model, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);
LayerHeldItem.renderHeldItem(entity, itemstack1, model, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
GlStateManager.popMatrix();
}
}

/**
* Render item in every arm.
*
* Items could be rendered to several limbs.
*/
private static void renderHeldItem(EntityLivingBase entity, ModelCustom model, ItemStack item, ItemCameraTransforms.TransformType transform, EnumHandSide handSide)
{
if (item != null)
{
for (ModelCustomRenderer arm : model.getRenderForArm(handSide))
{
boolean flag = handSide == EnumHandSide.LEFT;

float x = 0.0F;
float y = arm.limb.size[1] * (arm.limb.size[1] * (1 - arm.limb.anchor[1]) / arm.limb.size[1]) * -0.0625F;
float z = arm.limb.size[2] / 2 * 0.0625F;

if (arm.limb.size[0] > arm.limb.size[1])
{
x = arm.limb.size[0] * (10.0F / 12.0F) * 0.0625F;
}

GlStateManager.pushMatrix();
arm.postRender(0.0625F);

GlStateManager.rotate(-90.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(x, z, y);

if (arm.limb.size[0] > arm.limb.size[1])
{
GlStateManager.rotate(-90.0F, 0.0F, 1.0F, 0.0F);
}

Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, item, transform, flag);
GlStateManager.popMatrix();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import mchorse.blockbuster.client.model.ModelCustom;
import mchorse.blockbuster.client.model.ModelCustomRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.entity.RenderLivingBase;
Expand Down Expand Up @@ -46,8 +47,8 @@ public void doRenderLayer(EntityLivingBase entity, float limbSwing, float limbSw
model.headPitch = headPitch;
model.scale = scale;

this.renderHeldItem(entity, itemstack1, model, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
this.renderHeldItem(entity, itemstack, model, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);
renderHeldItem(entity, itemstack1, model, ItemCameraTransforms.TransformType.THIRD_PERSON_RIGHT_HAND, EnumHandSide.RIGHT);
renderHeldItem(entity, itemstack, model, ItemCameraTransforms.TransformType.THIRD_PERSON_LEFT_HAND, EnumHandSide.LEFT);

model.model.setRotationAngles(limbSwing, limbSwingAmount, ageInTicks, netHeadYaw, headPitch, scale, entity);
}
Expand All @@ -58,7 +59,7 @@ public void doRenderLayer(EntityLivingBase entity, float limbSwing, float limbSw
*
* Items could be rendered to several limbs.
*/
private void renderHeldItem(EntityLivingBase entity, ItemStack item, HeldModel model, ItemCameraTransforms.TransformType transform, EnumHandSide handSide)
public static void renderHeldItem(EntityLivingBase entity, ItemStack item, HeldModel model, ItemCameraTransforms.TransformType transform, EnumHandSide handSide)
{
if (item != null)
{
Expand All @@ -68,19 +69,41 @@ private void renderHeldItem(EntityLivingBase entity, ItemStack item, HeldModel m

model.setup(entity);
GlStateManager.pushMatrix();
this.applyTransform(arm);
applyTransform(arm);

Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, item, transform, flag);
GlStateManager.popMatrix();
}
}
}

private void applyTransform(ModelCustomRenderer arm)
/**
* Render item in every arm.
*
* Items could be rendered to several limbs.
*/
public static void renderHeldItem(EntityLivingBase entity, ItemStack item, ModelCustom model, ItemCameraTransforms.TransformType transform, EnumHandSide handSide)
{
if (item != null)
{
for (ModelCustomRenderer arm : model.getRenderForArm(handSide))
{
boolean flag = handSide == EnumHandSide.LEFT;

GlStateManager.pushMatrix();
applyTransform(arm);

Minecraft.getMinecraft().getItemRenderer().renderItemSide(entity, item, transform, flag);
GlStateManager.popMatrix();
}
}
}

private static void applyTransform(ModelCustomRenderer arm)
{
float x = 0.0F;
float x = (arm.limb.size[0] * (0.5F - arm.limb.anchor[0])) * 0.0625F;
float y = arm.limb.size[1] * (arm.limb.size[1] * (1 - arm.limb.anchor[1]) / arm.limb.size[1]) * -0.0625F;
float z = arm.limb.size[2] / 2 * 0.0625F;
float z = (arm.limb.size[2] * (arm.limb.anchor[2] - 0.5F)) * 0.0625F;

if (arm.limb.size[0] > arm.limb.size[1])
{
Expand Down

0 comments on commit fe5cb7e

Please sign in to comment.