From 5293f811c80bba4f57edb565afeb21251bbb4446 Mon Sep 17 00:00:00 2001 From: Vincent Lee Date: Wed, 30 Dec 2015 19:34:14 -0600 Subject: [PATCH] Fix king key weapon and item render --- .../client/core/helper/IconHelper.java | 85 +++++++++++++++++++ .../render/entity/RenderBabylonWeapon.java | 3 +- .../assets/botania/models/item/kingKey.json | 2 +- 3 files changed, 88 insertions(+), 2 deletions(-) diff --git a/src/main/java/vazkii/botania/client/core/helper/IconHelper.java b/src/main/java/vazkii/botania/client/core/helper/IconHelper.java index 573998ad7..3b7c2b0a2 100644 --- a/src/main/java/vazkii/botania/client/core/helper/IconHelper.java +++ b/src/main/java/vazkii/botania/client/core/helper/IconHelper.java @@ -10,9 +10,13 @@ */ package vazkii.botania.client.core.helper; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; import vazkii.botania.client.lib.LibResources; public final class IconHelper { @@ -25,4 +29,85 @@ public final class IconHelper { return ir.registerSprite(new ResourceLocation(LibResources.PREFIX_MOD + dir + "/" + name)); } + /** + * Renders a sprite from the spritesheet with depth, like a "builtin/generated" item model. + * Adapted from ItemRenderer.renderItemIn2D, 1.7.10 + */ + public static void renderIconIn3D(Tessellator tess, float p_78439_1_, float p_78439_2_, float p_78439_3_, float p_78439_4_, int width, int height, float thickness) { + WorldRenderer wr = tess.getWorldRenderer(); + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + wr.pos(0.0D, 0.0D, 0.0D).tex(p_78439_1_, p_78439_4_).normal(0, 0, 1).endVertex(); + wr.pos(1.0D, 0.0D, 0.0D).tex(p_78439_3_, p_78439_4_).normal(0, 0, 1).endVertex(); + wr.pos(1.0D, 1.0D, 0.0D).tex(p_78439_3_, p_78439_2_).normal(0, 0, 1).endVertex(); + wr.pos(0.0D, 1.0D, 0.0D).tex(p_78439_1_, p_78439_2_).normal(0, 0, 1).endVertex(); + tess.draw(); + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + wr.pos(0.0D, 1.0D, (0.0F - thickness)).tex(p_78439_1_, p_78439_2_).normal(0, 0, -1).endVertex(); + wr.pos(1.0D, 1.0D, (0.0F - thickness)).tex(p_78439_3_, p_78439_2_).normal(0, 0, -1).endVertex(); + wr.pos(1.0D, 0.0D, (0.0F - thickness)).tex(p_78439_3_, p_78439_4_).normal(0, 0, -1).endVertex(); + wr.pos(0.0D, 0.0D, (0.0F - thickness)).tex(p_78439_1_, p_78439_4_).normal(0, 0, -1).endVertex(); + tess.draw(); + float f5 = 0.5F * (p_78439_1_ - p_78439_3_) / (float)width; + float f6 = 0.5F * (p_78439_4_ - p_78439_2_) / (float)height; + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + int k; + float f7; + float f8; + + for (k = 0; k < width; ++k) + { + f7 = (float)k / (float)width; + f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + wr.pos(f7, 0.0D, (0.0F - thickness)).tex(f8, p_78439_4_).normal(-1, 0, 0).endVertex(); + wr.pos(f7, 0.0D, 0.0D).tex(f8, p_78439_4_).normal(-1, 0, 0).endVertex(); + wr.pos(f7, 1.0D, 0.0D).tex(f8, p_78439_2_).normal(-1, 0, 0).endVertex(); + wr.pos(f7, 1.0D, (0.0F - thickness)).tex(f8, p_78439_2_).normal(-1, 0, 0).endVertex(); + } + + tess.draw(); + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + float f9; + + for (k = 0; k < width; ++k) + { + f7 = (float)k / (float)width; + f8 = p_78439_1_ + (p_78439_3_ - p_78439_1_) * f7 - f5; + f9 = f7 + 1.0F / (float)width; + wr.pos(f9, 1.0D, (0.0F - thickness)).tex(f8, p_78439_2_).normal(1, 0, 0).endVertex(); + wr.pos(f9, 1.0D, 0.0D).tex(f8, p_78439_2_).normal(1, 0, 0).endVertex(); + wr.pos(f9, 0.0D, 0.0D).tex(f8, p_78439_4_).normal(1, 0, 0).endVertex(); + wr.pos(f9, 0.0D, (0.0F - thickness)).tex(f8, p_78439_4_).normal(1, 0, 0).endVertex(); + } + + tess.draw(); + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + + for (k = 0; k < height; ++k) + { + f7 = (float)k / (float)height; + f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + f9 = f7 + 1.0F / (float)height; + wr.pos(0.0D, f9, 0.0D).tex(p_78439_1_, f8).normal(0, 1, 0).endVertex(); + wr.pos(1.0D, f9, 0.0D).tex(p_78439_3_, f8).normal(0, 1, 0).endVertex(); + wr.pos(1.0D, f9, (0.0F - thickness)).tex(p_78439_3_, f8).normal(0, 1, 0).endVertex(); + wr.pos(0.0D, f9, (0.0F - thickness)).tex(p_78439_1_, f8).normal(0, 1, 0).endVertex(); + } + + tess.draw(); + wr.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX_NORMAL); + + for (k = 0; k < height; ++k) + { + f7 = (float)k / (float)height; + f8 = p_78439_4_ + (p_78439_2_ - p_78439_4_) * f7 - f6; + wr.pos(1.0D, f7, 0.0D).tex(p_78439_3_, f8).normal(0, -1, 0).endVertex(); + wr.pos(0.0D, f7, 0.0D).tex(p_78439_1_, f8).normal(0, -1, 0).endVertex(); + wr.pos(0.0D, f7, (0.0F - thickness)).tex(p_78439_1_, f8).normal(0, -1, 0).endVertex(); + wr.pos(1.0D, f7, (0.0F - thickness)).tex(p_78439_3_, f8).normal(0, -1, 0).endVertex(); + } + + tess.draw(); + + } + } \ No newline at end of file diff --git a/src/main/java/vazkii/botania/client/render/entity/RenderBabylonWeapon.java b/src/main/java/vazkii/botania/client/render/entity/RenderBabylonWeapon.java index 8df06e2eb..d8cbeb00a 100644 --- a/src/main/java/vazkii/botania/client/render/entity/RenderBabylonWeapon.java +++ b/src/main/java/vazkii/botania/client/render/entity/RenderBabylonWeapon.java @@ -28,6 +28,7 @@ import net.minecraft.util.ResourceLocation; import org.lwjgl.opengl.GL11; import vazkii.botania.client.core.handler.RenderEventHandler; +import vazkii.botania.client.core.helper.IconHelper; import vazkii.botania.client.core.helper.ShaderHelper; import vazkii.botania.client.lib.LibResources; import vazkii.botania.common.entity.EntityBabylonWeapon; @@ -70,7 +71,7 @@ public class RenderBabylonWeapon extends Render { OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); GlStateManager.disableLighting(); - //ItemRenderer.renderItemIn2D(Tessellator.getInstance(), f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); + IconHelper.renderIconIn3D(Tessellator.getInstance(), f1, f2, f, f3, icon.getIconWidth(), icon.getIconHeight(), 1F / 16F); GlStateManager.popMatrix(); GlStateManager.disableCull(); diff --git a/src/main/resources/assets/botania/models/item/kingKey.json b/src/main/resources/assets/botania/models/item/kingKey.json index c559fe3fb..f543ff9f7 100644 --- a/src/main/resources/assets/botania/models/item/kingKey.json +++ b/src/main/resources/assets/botania/models/item/kingKey.json @@ -1,5 +1,5 @@ { - "parent": "botania:item/standard_item", + "parent": "botania:item/standard_tool", "textures": { "layer0": "botania:items/kingKey" }