2013-08-11 12:23:49 -07:00
|
|
|
package tconstruct.client;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-31 11:26:08 -05:00
|
|
|
import net.minecraft.util.IIcon;
|
2013-08-11 12:23:49 -07:00
|
|
|
import net.minecraftforge.client.IItemRenderer;
|
2023-01-28 18:04:28 -08:00
|
|
|
|
2013-10-12 23:46:35 +01:00
|
|
|
import tconstruct.TConstruct;
|
2013-08-11 12:23:49 -07:00
|
|
|
import tconstruct.library.tools.ToolCore;
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public class ToolCoreRenderer implements IItemRenderer {
|
2023-01-28 18:04:28 -08:00
|
|
|
|
2014-08-28 12:49:57 +02:00
|
|
|
private final boolean isEntity;
|
2014-08-31 19:09:46 +02:00
|
|
|
private final boolean noEntityTranslation;
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public ToolCoreRenderer() {
|
2014-09-09 18:30:15 +10:00
|
|
|
this(false, false);
|
|
|
|
|
}
|
2014-08-28 12:49:57 +02:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public ToolCoreRenderer(boolean isEntity) {
|
2014-08-31 19:09:46 +02:00
|
|
|
this(isEntity, false);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
public ToolCoreRenderer(boolean isEntity, boolean noEntityTranslation) {
|
2014-08-28 12:49:57 +02:00
|
|
|
this.isEntity = isEntity;
|
2014-08-31 19:09:46 +02:00
|
|
|
this.noEntityTranslation = noEntityTranslation;
|
2014-08-28 12:49:57 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-11 12:23:49 -07:00
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
|
|
|
|
if (!item.hasTagCompound()) return false;
|
2014-08-28 14:35:05 +02:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
switch (type) {
|
|
|
|
|
case ENTITY:
|
2023-01-25 23:36:51 +01:00
|
|
|
case INVENTORY:
|
2022-09-22 19:51:23 +01:00
|
|
|
return true;
|
|
|
|
|
case EQUIPPED:
|
|
|
|
|
GL11.glTranslatef(0.03f, 0F, -0.09375F);
|
|
|
|
|
case EQUIPPED_FIRST_PERSON:
|
|
|
|
|
return !isEntity;
|
|
|
|
|
default:
|
|
|
|
|
TConstruct.logger.warn("[TCon] Unhandled render case!");
|
|
|
|
|
case FIRST_PERSON_MAP:
|
|
|
|
|
return false;
|
2013-08-11 12:23:49 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
2013-08-11 12:23:49 -07:00
|
|
|
return handleRenderType(item, type) & helper.ordinal() < ItemRendererHelper.EQUIPPED_BLOCK.ordinal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static final int toolIcons = 10;
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-09-22 19:51:23 +01:00
|
|
|
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
2013-08-11 12:23:49 -07:00
|
|
|
ToolCore tool = (ToolCore) item.getItem();
|
|
|
|
|
|
|
|
|
|
boolean isInventory = type == ItemRenderType.INVENTORY;
|
|
|
|
|
Entity ent = null;
|
2022-09-22 19:51:23 +01:00
|
|
|
if (data.length > 1) ent = (Entity) data[1];
|
2013-08-11 12:23:49 -07:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
int iconParts = toolIcons; // tool.getRenderPasses(item.getItemDamage());
|
2014-08-28 14:30:49 +02:00
|
|
|
// TODO: have the tools define how many render passes they have
|
|
|
|
|
// (requires more logic rewrite than it sounds like)
|
2013-08-11 12:23:49 -07:00
|
|
|
|
2013-12-31 11:26:08 -05:00
|
|
|
IIcon[] tempParts = new IIcon[iconParts];
|
2013-08-11 12:23:49 -07:00
|
|
|
label: {
|
2022-09-22 19:51:23 +01:00
|
|
|
if (!isInventory && ent instanceof EntityPlayer) {
|
2013-08-11 12:23:49 -07:00
|
|
|
EntityPlayer player = (EntityPlayer) ent;
|
|
|
|
|
ItemStack itemInUse = player.getItemInUse();
|
2022-09-22 19:51:23 +01:00
|
|
|
if (itemInUse != null) {
|
2013-08-11 12:23:49 -07:00
|
|
|
int useCount = player.getItemInUseCount();
|
|
|
|
|
for (int i = iconParts; i-- > 0;) tempParts[i] = tool.getIcon(item, i, player, itemInUse, useCount);
|
|
|
|
|
break label;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = iconParts; i-- > 0;) tempParts[i] = tool.getIcon(item, i);
|
2013-08-11 12:23:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
2013-12-31 11:26:08 -05:00
|
|
|
IIcon[] parts = new IIcon[iconParts];
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2013-12-31 11:26:08 -05:00
|
|
|
IIcon part = tempParts[i];
|
2022-09-22 19:51:23 +01:00
|
|
|
if (part == null || part == ToolCore.blankSprite || part == ToolCore.emptyIcon) ++count;
|
|
|
|
|
else parts[i - count] = part;
|
2013-08-11 12:23:49 -07:00
|
|
|
}
|
|
|
|
|
iconParts -= count;
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
if (iconParts <= 0) {
|
2013-08-11 12:23:49 -07:00
|
|
|
iconParts = 1;
|
|
|
|
|
// TODO: assign default sprite
|
|
|
|
|
// parts = new Icon[]{ defaultSprite };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tessellator tess = Tessellator.instance;
|
|
|
|
|
float[] xMax = new float[iconParts];
|
|
|
|
|
float[] yMin = new float[iconParts];
|
|
|
|
|
float[] xMin = new float[iconParts];
|
|
|
|
|
float[] yMax = new float[iconParts];
|
|
|
|
|
float depth = 1f / 16f;
|
|
|
|
|
|
|
|
|
|
float[] width = new float[iconParts];
|
|
|
|
|
float[] height = new float[iconParts];
|
|
|
|
|
float[] xDiff = new float[iconParts];
|
|
|
|
|
float[] yDiff = new float[iconParts];
|
2013-08-13 13:41:46 -04:00
|
|
|
float[] xSub = new float[iconParts];
|
|
|
|
|
float[] ySub = new float[iconParts];
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2013-12-31 11:26:08 -05:00
|
|
|
IIcon icon = parts[i];
|
2013-08-11 12:23:49 -07:00
|
|
|
xMin[i] = icon.getMinU();
|
|
|
|
|
xMax[i] = icon.getMaxU();
|
|
|
|
|
yMin[i] = icon.getMinV();
|
|
|
|
|
yMax[i] = icon.getMaxV();
|
2014-08-28 14:30:49 +02:00
|
|
|
width[i] = icon.getIconWidth();
|
|
|
|
|
height[i] = icon.getIconHeight();
|
2013-08-11 12:23:49 -07:00
|
|
|
xDiff[i] = xMin[i] - xMax[i];
|
|
|
|
|
yDiff[i] = yMin[i] - yMax[i];
|
2014-08-28 14:30:49 +02:00
|
|
|
xSub[i] = 0.5f * (xMax[i] - xMin[i]) / width[i];
|
|
|
|
|
ySub[i] = 0.5f * (yMax[i] - yMin[i]) / height[i];
|
2013-08-11 12:23:49 -07:00
|
|
|
}
|
|
|
|
|
GL11.glPushMatrix();
|
|
|
|
|
|
2014-09-22 15:51:55 +02:00
|
|
|
// color
|
2014-09-26 17:15:33 +02:00
|
|
|
int[] color = new int[iconParts];
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; i++) color[i] = item.getItem().getColorFromItemStack(item, i);
|
2014-09-26 16:49:39 +02:00
|
|
|
|
|
|
|
|
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
if (type == ItemRenderType.INVENTORY) {
|
2014-09-26 17:15:33 +02:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
// TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager();
|
|
|
|
|
// texturemanager.getResourceLocation(item.getItemSpriteNumber());
|
|
|
|
|
// TextureUtil.func_152777_a(false, false, 1.0F);
|
2014-09-26 16:49:39 +02:00
|
|
|
|
2013-08-11 12:23:49 -07:00
|
|
|
GL11.glDisable(GL11.GL_LIGHTING);
|
2014-09-26 16:49:39 +02:00
|
|
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
|
|
|
|
GL11.glDisable(GL11.GL_BLEND);
|
2014-09-26 17:15:33 +02:00
|
|
|
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.startDrawingQuads();
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(0, 16, 0, xMin[i], yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(16, 16, 0, xMax[i], yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(16, 0, 0, xMax[i], yMin[i]);
|
|
|
|
|
tess.addVertexWithUV(0, 0, 0, xMin[i], yMin[i]);
|
|
|
|
|
}
|
|
|
|
|
tess.draw();
|
|
|
|
|
GL11.glEnable(GL11.GL_LIGHTING);
|
2014-09-26 17:15:33 +02:00
|
|
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
2014-09-29 09:11:38 +02:00
|
|
|
GL11.glEnable(GL11.GL_BLEND);
|
2014-09-26 16:49:39 +02:00
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
// GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
|
|
|
|
// texturemanager.bindTexture(texturemanager.getResourceLocation(item.getItemSpriteNumber()));
|
|
|
|
|
// TextureUtil.func_147945_b();
|
|
|
|
|
} else {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case EQUIPPED_FIRST_PERSON:
|
|
|
|
|
break;
|
|
|
|
|
case EQUIPPED:
|
|
|
|
|
GL11.glTranslatef(0, -4 / 16f, 0);
|
|
|
|
|
break;
|
|
|
|
|
case ENTITY:
|
|
|
|
|
if (!noEntityTranslation) GL11.glTranslatef(-0.5f, 0f, depth); // correction of the rotation point
|
|
|
|
|
// when items lie on the ground
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2013-08-11 12:23:49 -07:00
|
|
|
}
|
|
|
|
|
|
2014-08-23 19:16:33 +02:00
|
|
|
// one side
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(0, 0, 1);
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(0, 0, 0, xMax[i], yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(1, 0, 0, xMin[i], yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(1, 1, 0, xMin[i], yMin[i]);
|
|
|
|
|
tess.addVertexWithUV(0, 1, 0, xMax[i], yMin[i]);
|
|
|
|
|
}
|
|
|
|
|
tess.draw();
|
2014-08-23 19:16:33 +02:00
|
|
|
|
|
|
|
|
// other side
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(0, 0, -1);
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(0, 1, -depth, xMax[i], yMin[i]);
|
|
|
|
|
tess.addVertexWithUV(1, 1, -depth, xMin[i], yMin[i]);
|
|
|
|
|
tess.addVertexWithUV(1, 0, -depth, xMin[i], yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(0, 0, -depth, xMax[i], yMax[i]);
|
|
|
|
|
}
|
|
|
|
|
tess.draw();
|
2014-08-23 19:16:33 +02:00
|
|
|
|
|
|
|
|
// make it have "depth"
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(-1, 0, 0);
|
|
|
|
|
float pos;
|
|
|
|
|
float iconPos;
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
float w = width[i], m = xMax[i], d = xDiff[i], s = xSub[i];
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int k = 0, e = (int) w; k < e; ++k) {
|
2014-08-28 14:30:49 +02:00
|
|
|
pos = k / w;
|
|
|
|
|
iconPos = m + d * pos - s;
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(pos, 0, -depth, iconPos, yMax[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
tess.addVertexWithUV(pos, 0, 0, iconPos, yMax[i]);
|
|
|
|
|
tess.addVertexWithUV(pos, 1, 0, iconPos, yMin[i]);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(pos, 1, -depth, iconPos, yMin[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tess.draw();
|
|
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(1, 0, 0);
|
|
|
|
|
float posEnd;
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
float w = width[i], m = xMax[i], d = xDiff[i], s = xSub[i];
|
|
|
|
|
float d2 = 1f / w;
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int k = 0, e = (int) w; k < e; ++k) {
|
2014-08-28 14:30:49 +02:00
|
|
|
pos = k / w;
|
|
|
|
|
iconPos = m + d * pos - s;
|
|
|
|
|
posEnd = pos + d2;
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(posEnd, 1, -depth, iconPos, yMin[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
tess.addVertexWithUV(posEnd, 1, 0, iconPos, yMin[i]);
|
|
|
|
|
tess.addVertexWithUV(posEnd, 0, 0, iconPos, yMax[i]);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(posEnd, 0, -depth, iconPos, yMax[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tess.draw();
|
|
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(0, 1, 0);
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
float h = height[i], m = yMax[i], d = yDiff[i], s = ySub[i];
|
|
|
|
|
float d2 = 1f / h;
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int k = 0, e = (int) h; k < e; ++k) {
|
2014-08-28 14:30:49 +02:00
|
|
|
pos = k / h;
|
|
|
|
|
iconPos = m + d * pos - s;
|
|
|
|
|
posEnd = pos + d2;
|
2014-09-09 18:30:15 +10:00
|
|
|
tess.addVertexWithUV(0, posEnd, 0, xMax[i], iconPos);
|
|
|
|
|
tess.addVertexWithUV(1, posEnd, 0, xMin[i], iconPos);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(1, posEnd, -depth, xMin[i], iconPos);
|
|
|
|
|
tess.addVertexWithUV(0, posEnd, -depth, xMax[i], iconPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tess.draw();
|
|
|
|
|
tess.startDrawingQuads();
|
|
|
|
|
tess.setNormal(0, -1, 0);
|
|
|
|
|
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int i = 0; i < iconParts; ++i) {
|
2014-09-26 17:15:33 +02:00
|
|
|
tess.setColorOpaque_I(color[i]);
|
2014-09-09 18:30:15 +10:00
|
|
|
float h = height[i], m = yMax[i], d = yDiff[i], s = ySub[i];
|
2022-09-22 19:51:23 +01:00
|
|
|
for (int k = 0, e = (int) h; k < e; ++k) {
|
2014-08-28 14:30:49 +02:00
|
|
|
pos = k / h;
|
|
|
|
|
iconPos = m + d * pos - s;
|
2014-09-09 18:30:15 +10:00
|
|
|
tess.addVertexWithUV(1, pos, 0, xMin[i], iconPos);
|
|
|
|
|
tess.addVertexWithUV(0, pos, 0, xMax[i], iconPos);
|
2013-08-11 12:23:49 -07:00
|
|
|
tess.addVertexWithUV(0, pos, -depth, xMax[i], iconPos);
|
|
|
|
|
tess.addVertexWithUV(1, pos, -depth, xMin[i], iconPos);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tess.draw();
|
|
|
|
|
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GL11.glPopMatrix();
|
|
|
|
|
}
|
|
|
|
|
}
|