- 51
- 8
- 5
Я хотел сделать кастомный рендер для руки, чтобы от первого лица игрок видел броню на своей руке, но на шифте рука почему-то странно поворачивается. Подскажите, пожалуйста, что делать. Вот мой код
Вот как выглядит в игре
Без шифта

С шифтом

Java:
package com.nymoo.afp.common.mixin.impl;
import com.nymoo.afp.common.item.IPowerArmor;
import com.nymoo.afp.common.render.model.armor.PowerArmorModel;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHandSide;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import org.lwjgl.opengl.GL11;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(ItemRenderer.class)
public abstract class MixinItemRenderer {
@Inject(method = "renderArmFirstPerson", at = @At("HEAD"), cancellable = true)
private void onRenderArmFirstPerson(float equipProgress, float swingProgress, EnumHandSide hand, CallbackInfo ci) {
EntityPlayer player = Minecraft.getMinecraft().player;
if (player == null) return;
ItemStack chestplateStack = player.getItemStackFromSlot(EntityEquipmentSlot.CHEST);
if (chestplateStack.isEmpty() || !(chestplateStack.getItem() instanceof IPowerArmor)) return;
// Кастомный рендер руки силовой брони
boolean flag = hand == EnumHandSide.RIGHT;
float f = flag ? 1.0F : -1.0F;
float f1 = MathHelper.sqrt(swingProgress);
float f2 = -0.3F * MathHelper.sin(f1 * (float) Math.PI);
float f3 = 0.4F * MathHelper.sin(f1 * ((float) Math.PI * 2F));
float f4 = -0.4F * MathHelper.sin(swingProgress * (float) Math.PI);
GlStateManager.translate(f * (f2 + 0.64000005F), f3 + -0.6F + equipProgress * -0.6F, f4 + -0.71999997F);
GlStateManager.rotate(f * 45.0F, 0.0F, 1.0F, 0.0F);
float f5 = MathHelper.sin(swingProgress * swingProgress * (float) Math.PI);
float f6 = MathHelper.sin(f1 * (float) Math.PI);
GlStateManager.rotate(f * f6 * 70.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.rotate(f * f5 * -20.0F, 0.0F, 0.0F, 1.0F);
// Получение модели брони
ModelBiped bipedModel = chestplateStack.getItem().getArmorModel(player, chestplateStack, EntityEquipmentSlot.CHEST, null);
PowerArmorModel model = (PowerArmorModel) bipedModel;
// Нейтральное вращение
model.setRotationAngles(0.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0625F, player);
// Биндинг текстуры брони
String regPath = chestplateStack.getItem().getRegistryName().getPath();
String armorType = regPath.substring(0, regPath.length() - "_chestplate".length());
ResourceLocation texture = new ResourceLocation("afp", "textures/armor/" + armorType + "/" + armorType + ".png");
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
// Трансформаторы
GlStateManager.translate(f * -1.0F, 3.6F, 3.5F);
GlStateManager.rotate(f * 120.0F, 0.0F, 0.0F, 1.0F);
GlStateManager.rotate(200.0F, 1.0F, 0.0F, 0.0F);
GlStateManager.rotate(f * -135.0F, 0.0F, 1.0F, 0.0F);
GlStateManager.translate(f * 5.6F, 0.0F, 0.0F);
// Рендер руки
GlStateManager.disableCull();
GL11.glShadeModel(GL11.GL_SMOOTH);
if (flag) {
model.rightArm.render(0.0625F);
} else {
model.leftArm.render(0.0625F);
}
GL11.glShadeModel(GL11.GL_FLAT);
GlStateManager.enableCull();
ci.cancel();
}
}
Вот как выглядит в игре
Без шифта

С шифтом


