darty11 Posted November 23, 2014 Share Posted November 23, 2014 In my mod I am trying to create a knife that switched between 2 modes, stabbing and normal. When it is in normal mode, it is rendered just like a sword, but when it is in stabbing mode I want it to be rotated 180 degrees so that it looks like the player is holding it like this http://thumbs.dreamstime.com/z/hand-holding-knife-isolated-white-background-33425579.jpg I have an IItemRenderer set up, and it works fine, I just don't know how to rotate the knife so that it looks the way I want it to. This is my current IItemRenderer: public class KnifeRendering implements IItemRenderer { private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png"); @Override public boolean handleRenderType(ItemStack item, ItemRenderType type) { if(item.getItem() instanceof UniversalKnife) { UniversalKnife k=(UniversalKnife)item.getItem(); return (type==ItemRenderType.EQUIPPED||type==ItemRenderType.EQUIPPED_FIRST_PERSON)&&k.getIsStabing(item); } return false; } @Override public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { // TODO Auto-generated method stub return true; } public static void renderItemIn2D(Tessellator p_78439_0_, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int p_78439_5_, int p_78439_6_, float p_78439_7_) { p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(0.0F, 0.0F, 1.0F); p_78439_0_.addVertexWithUV(0.0D, 0.0D, 0.0D, (double)p_78439_1_, (double)p_78439_4_); p_78439_0_.addVertexWithUV(1.0D, 0.0D, 0.0D, (double)p_78439_3_, (double)p_78439_4_); p_78439_0_.addVertexWithUV(1.0D, 1.0D, 0.0D, (double)p_78439_3_, (double)p_78439_2_); p_78439_0_.addVertexWithUV(0.0D, 1.0D, 0.0D, (double)p_78439_1_, (double)p_78439_2_); p_78439_0_.draw(); p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(0.0F, 0.0F, -1.0F); p_78439_0_.addVertexWithUV(0.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_2_); p_78439_0_.addVertexWithUV(1.0D, 1.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_2_); p_78439_0_.addVertexWithUV(1.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)p_78439_4_); p_78439_0_.addVertexWithUV(0.0D, 0.0D, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)p_78439_4_); p_78439_0_.draw(); float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float)p_78439_5_; float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float)p_78439_6_; p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(-1.0F, 0.0F, 0.0F); int k; float f7; float f8; for (k = 0; k < p_78439_5_; ++k) { f7 = (float)k / (float)p_78439_5_; f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; p_78439_0_.addVertexWithUV((double)f7, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_); p_78439_0_.addVertexWithUV((double)f7, 0.0D, 0.0D, (double)f8, (double)p_78439_4_); p_78439_0_.addVertexWithUV((double)f7, 1.0D, 0.0D, (double)f8, (double)p_78439_2_); p_78439_0_.addVertexWithUV((double)f7, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_); } p_78439_0_.draw(); p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(1.0F, 0.0F, 0.0F); float f9; for (k = 0; k < p_78439_5_; ++k) { f7 = (float)k / (float)p_78439_5_; f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; f9 = f7 + 1.0F / (float)p_78439_5_; p_78439_0_.addVertexWithUV((double)f9, 1.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_2_); p_78439_0_.addVertexWithUV((double)f9, 1.0D, 0.0D, (double)f8, (double)p_78439_2_); p_78439_0_.addVertexWithUV((double)f9, 0.0D, 0.0D, (double)f8, (double)p_78439_4_); p_78439_0_.addVertexWithUV((double)f9, 0.0D, (double)(0.0F - p_78439_7_), (double)f8, (double)p_78439_4_); } p_78439_0_.draw(); p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(0.0F, 1.0F, 0.0F); for (k = 0; k < p_78439_6_; ++k) { f7 = (float)k / (float)p_78439_6_; f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; f9 = f7 + 1.0F / (float)p_78439_6_; p_78439_0_.addVertexWithUV(0.0D, (double)f9, 0.0D, (double)p_78439_1_, (double)f8); p_78439_0_.addVertexWithUV(1.0D, (double)f9, 0.0D, (double)p_78439_3_, (double)f8); p_78439_0_.addVertexWithUV(1.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8); p_78439_0_.addVertexWithUV(0.0D, (double)f9, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8); } p_78439_0_.draw(); p_78439_0_.startDrawingQuads(); p_78439_0_.setNormal(0.0F, -1.0F, 0.0F); for (k = 0; k < p_78439_6_; ++k) { f7 = (float)k / (float)p_78439_6_; f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; p_78439_0_.addVertexWithUV(1.0D, (double)f7, 0.0D, (double)p_78439_3_, (double)f8); p_78439_0_.addVertexWithUV(0.0D, (double)f7, 0.0D, (double)p_78439_1_, (double)f8); p_78439_0_.addVertexWithUV(0.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_1_, (double)f8); p_78439_0_.addVertexWithUV(1.0D, (double)f7, (double)(0.0F - p_78439_7_), (double)p_78439_3_, (double)f8); } p_78439_0_.draw(); } @Override public void renderItem(ItemRenderType type, ItemStack item, Object... data) { TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); IIcon iicon = item.getIconIndex(); GL11.glTranslatef(0.5F, 0.5F, 0.5F); GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glTranslatef(0.0F, -0.3F, 0.0F); GL11.glScalef(1.5F, 1.5F, 1.5F); GL11.glRotatef(50.0F, 0.0F, 1.0F, 0.0F); GL11.glRotatef(335.0F, 0.0F, 0.0F, 1.0F); GL11.glTranslatef(-0.9375F, -0.0625F, 0.0F); if (iicon == null) { GL11.glPopMatrix(); return; } texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber())); TextureUtil.func_152777_a(false, false, 1.0F); Tessellator tessellator = Tessellator.instance; float f = iicon.getMinU(); float f1 = iicon.getMaxU(); float f2 = iicon.getMinV(); float f3 = iicon.getMaxV(); renderItemIn2D(tessellator, f1, f2, f, f3, iicon.getIconWidth(), iicon.getIconHeight(), 0.0625F); if (item.hasEffect(0)) { GL11.glDepthFunc(GL11.GL_EQUAL); GL11.glDisable(GL11.GL_LIGHTING); texturemanager.bindTexture(RES_ITEM_GLINT); GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(768, 1, 1, 0); float f7 = 0.76F; GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F); GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glPushMatrix(); float f8 = 0.125F; GL11.glScalef(f8, f8, f8); float f9 = (float)(Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; GL11.glTranslatef(f9, 0.0F, 0.0F); GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); GL11.glPopMatrix(); GL11.glPushMatrix(); GL11.glScalef(f8, f8, f8); f9 = (float)(Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; GL11.glTranslatef(-f9, 0.0F, 0.0F); GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.0625F); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthFunc(GL11.GL_LEQUAL); } GL11.glDisable(GL12.GL_RESCALE_NORMAL); texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber())); TextureUtil.func_147945_b(); } } Everything works fine, I just have absolutely no idea how to achieve the effect I am looking for. Quote Link to comment Share on other sites More sharing options...
Ernio Posted November 23, 2014 Share Posted November 23, 2014 You will certainly have to use some storage type - either choose NBT per ItemStack (state of knife) or IExtendedEntityProps and hold boolean value for rotation. IEEP will be better ofc. (one per player). Then in your renderer you will have to operate on literally basic java/GL. Make If for your rotation boolean and then just try using: GL11.glRotatef(0.0F, 0.0F, 0.0F, 0.0F); GL11.glTranslatef(0.0F, 0.0F, 0.0F); Translatef moves center of item by some value (in item I think center is some corner, idk). Rotatef - obviously rotates. I am too lazy to come up with right values so hit: Launch MC in debug mode get you item to hand and start having fun with those 2 lines. Quote 1.7.10 is no longer supported by forge, you are on your own. Link to comment Share on other sites More sharing options...
Recommended Posts
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.