From c0a0ae8c3df2243c639d825185eded74f2b34152 Mon Sep 17 00:00:00 2001 From: ACGaming <4818419+ACGaming@users.noreply.github.com> Date: Sun, 7 Jul 2024 22:20:32 +0200 Subject: [PATCH] Add necronomicon holding animation --- .../events/HSRenderSpecificHandEvent.java | 98 ++++++++++++++++++- .../harkenscythe/items/HSNecronomicon.java | 3 +- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/src/main/java/mod/emt/harkenscythe/events/HSRenderSpecificHandEvent.java b/src/main/java/mod/emt/harkenscythe/events/HSRenderSpecificHandEvent.java index cfbf748..b75fce0 100644 --- a/src/main/java/mod/emt/harkenscythe/events/HSRenderSpecificHandEvent.java +++ b/src/main/java/mod/emt/harkenscythe/events/HSRenderSpecificHandEvent.java @@ -4,12 +4,20 @@ import mod.emt.harkenscythe.items.HSDimensionalMirror; import mod.emt.harkenscythe.items.HSNecronomicon; import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.AbstractClientPlayer; import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.client.renderer.BufferBuilder; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.block.model.ItemCameraTransforms; +import net.minecraft.client.renderer.entity.Render; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.item.Item; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHandSide; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.math.MathHelper; import net.minecraftforge.client.event.RenderSpecificHandEvent; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; @@ -20,6 +28,7 @@ public class HSRenderSpecificHandEvent { private static final Minecraft mc = Minecraft.getMinecraft(); + private static final ResourceLocation NECRONOMICON_ACTIVE = new ResourceLocation(HarkenScythe.MOD_ID, "textures/items/ancient_necronomicon_active.png"); @SubscribeEvent public static void onRenderHand(RenderSpecificHandEvent event) @@ -28,7 +37,7 @@ public static void onRenderHand(RenderSpecificHandEvent event) if (player != null && player.isHandActive() && player.getActiveHand() == event.getHand()) { Item heldItem = player.getActiveItemStack().getItem(); - if (heldItem instanceof HSDimensionalMirror || heldItem instanceof HSNecronomicon) + if (heldItem instanceof HSDimensionalMirror) { GlStateManager.pushMatrix(); boolean rightHanded = (((event.getHand() == EnumHand.MAIN_HAND) ? player.getPrimaryHand() : player.getPrimaryHand().opposite()) == EnumHandSide.RIGHT); @@ -37,15 +46,98 @@ public static void onRenderHand(RenderSpecificHandEvent event) GlStateManager.popMatrix(); event.setCanceled(true); } + else if (heldItem instanceof HSNecronomicon) + { + renderItemFirstPersonBimanual(event.getInterpolatedPitch(), event.getEquipProgress(), event.getSwingProgress()); + event.setCanceled(true); + } } } - private static void transformSideFirstPerson(float side, float equippedProg) + private static void transformSideFirstPerson(float side, float equipProgress) { - GlStateManager.translate(side * 0.56F, -0.52F + equippedProg * -0.6F, -0.72F); + GlStateManager.translate(side * 0.56F, -0.52F + equipProgress * -0.6F, -0.72F); GlStateManager.translate(side * -0.14142136F, 0.08F, 0.14142136F); GlStateManager.rotate(-102.25F, 1.0F, 0.0F, 0.0F); GlStateManager.rotate(side * 13.365F, 0.0F, 1.0F, 0.0F); GlStateManager.rotate(side * 78.05F, 0.0F, 0.0F, 1.0F); } + + private static void renderItemFirstPersonBimanual(float partialTicks, float equipProgress, float swingProgress) + { + float f = MathHelper.sqrt(swingProgress); + float f1 = -0.2F * MathHelper.sin(swingProgress * (float) Math.PI); + float f2 = -0.4F * MathHelper.sin(f * (float) Math.PI); + GlStateManager.translate(0.0F, -f1 / 2.0F, f2); + float f3 = getItemAngleFromPitch(partialTicks); + GlStateManager.translate(0.0F, 0.04F + equipProgress * -1.2F + f3 * -0.5F, -0.72F); + GlStateManager.rotate(f3 * -85.0F, 1.0F, 0.0F, 0.0F); + renderArms(); + float f4 = MathHelper.sin(f * (float) Math.PI); + GlStateManager.rotate(f4 * 20.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.scale(2.0F, 2.0F, 2.0F); + GlStateManager.rotate(180.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); + GlStateManager.scale(0.38F, 0.38F, 0.38F); + GlStateManager.disableLighting(); + mc.getTextureManager().bindTexture(NECRONOMICON_ACTIVE); + Tessellator tessellator = Tessellator.getInstance(); + BufferBuilder bufferbuilder = tessellator.getBuffer(); + GlStateManager.translate(-0.5F, -0.5F, 0.0F); + GlStateManager.scale(0.0078125F, 0.0078125F, 0.0078125F); + bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX); + bufferbuilder.pos(-7.0D, 135.0D, 0.0D).tex(0.0D, 1.0D).endVertex(); + bufferbuilder.pos(135.0D, 135.0D, 0.0D).tex(1.0D, 1.0D).endVertex(); + bufferbuilder.pos(135.0D, -7.0D, 0.0D).tex(1.0D, 0.0D).endVertex(); + bufferbuilder.pos(-7.0D, -7.0D, 0.0D).tex(0.0D, 0.0D).endVertex(); + tessellator.draw(); + GlStateManager.enableLighting(); + } + + private static float getItemAngleFromPitch(float pitch) + { + float f = 1.0F - pitch / 45.0F + 0.1F; + f = MathHelper.clamp(f, 0.0F, 1.0F); + f = -MathHelper.cos(f * (float) Math.PI) * 0.5F + 0.5F; + return f; + } + + private static void renderArms() + { + if (!mc.player.isInvisible()) + { + GlStateManager.disableCull(); + GlStateManager.pushMatrix(); + GlStateManager.rotate(90.0F, 0.0F, 1.0F, 0.0F); + renderArm(EnumHandSide.RIGHT); + renderArm(EnumHandSide.LEFT); + GlStateManager.popMatrix(); + GlStateManager.enableCull(); + } + } + + private static void renderArm(EnumHandSide handSide) + { + mc.getTextureManager().bindTexture(mc.player.getLocationSkin()); + Render render = mc.getRenderManager().getEntityRenderObject(mc.player); + if (render != null) + { + RenderPlayer renderplayer = (RenderPlayer) render; + GlStateManager.pushMatrix(); + float f = handSide == EnumHandSide.RIGHT ? 1.0F : -1.0F; + GlStateManager.rotate(92.0F, 0.0F, 1.0F, 0.0F); + GlStateManager.rotate(45.0F, 1.0F, 0.0F, 0.0F); + GlStateManager.rotate(f * -41.0F, 0.0F, 0.0F, 1.0F); + GlStateManager.translate(f * 0.3F, -1.1F, 0.45F); + if (handSide == EnumHandSide.RIGHT) + { + renderplayer.renderRightArm(mc.player); + } + else + { + renderplayer.renderLeftArm(mc.player); + } + GlStateManager.popMatrix(); + } + } } diff --git a/src/main/java/mod/emt/harkenscythe/items/HSNecronomicon.java b/src/main/java/mod/emt/harkenscythe/items/HSNecronomicon.java index 3c681ff..7c2e6e2 100644 --- a/src/main/java/mod/emt/harkenscythe/items/HSNecronomicon.java +++ b/src/main/java/mod/emt/harkenscythe/items/HSNecronomicon.java @@ -54,9 +54,10 @@ public ItemStack onItemUseFinish(ItemStack stack, World world, EntityLivingBase ItemStack bloodContainer = getBloodContainer(player); if (bloodContainer != ItemStack.EMPTY) { - bloodContainer.damageItem(5, player); + bloodContainer.setItemDamage(bloodContainer.getItemDamage() + 5); } } + player.getCooldownTracker().setCooldown(stack.getItem(), 100); } return stack; }