Fix Tool Renderer

This commit is contained in:
Kam committed 2025-02-22 01:21:35 -05:00
1 parent faf335c831
commit 5dfe061bad
4 files changed
+47 -203

No files matched your search

@@ -533,9 +533,9 @@ public class ClientProxy extends CommonProxy {
@Override
public void registerItem(Item item) {
if (item instanceof ItemScripted || item instanceof ItemLinked) {
MinecraftForgeClient.registerItemRenderer(item, new CustomItemRenderer());
MinecraftForgeClient.registerItemRenderer(item, new ItemCustomRenderer());
} else if (item instanceof ItemNpcTool) {
MinecraftForgeClient.registerItemRenderer(item, new ToolItemRenderer());
MinecraftForgeClient.registerItemRenderer(item, new ItemToolRenderer());
}else {
MinecraftForgeClient.registerItemRenderer(item, new NpcItemRenderer());
}
@@ -27,7 +27,7 @@ import java.util.Random;
import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame;
public class CustomItemRenderer implements IItemRenderer {
public class ItemCustomRenderer implements IItemRenderer {
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private static final ResourceLocation enchant = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private final Random random = new Random();
@@ -11,16 +11,9 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.items.ItemCustomizable;
import noppes.npcs.items.ItemNpcTool;
import noppes.npcs.scripted.NpcAPI;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -28,14 +21,16 @@ import java.util.Random;
import static net.minecraft.client.renderer.entity.RenderItem.renderInFrame;
public class ToolItemRenderer implements IItemRenderer {
public class ItemToolRenderer implements IItemRenderer {
private static final ResourceLocation RES_ITEM_GLINT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png");
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png");
private static final ResourceLocation HAMMER = new ResourceLocation("customnpcs", "textures/items/npcHammer.png");
private final Random random = new Random();
private int item3dRenderTicks = 1;
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
@@ -75,26 +70,17 @@ public class ToolItemRenderer implements IItemRenderer {
entityItem.boundingBox.maxY = entityItem.boundingBox.minY + YSize * 1;
entityItem.boundingBox.maxZ = entityItem.boundingBox.minZ + ZSize * 1;
}
float entityRenderTicks = Minecraft.getMinecraft().timer.renderPartialTicks;
float bobbing = MathHelper.sin(((float)entityItem.age + entityRenderTicks) / 10.0F + entityItem.hoverStart) * 0.1F + 0.1F;
GL11.glRotatef(1 * entityRenderTicks %360, 1, 0, 0);
GL11.glRotatef(1 * entityRenderTicks %360, 0, 1, 0);
GL11.glRotatef(1 * entityRenderTicks %360, 0, 0, 1);
if (!renderInFrame) {
GL11.glTranslatef(0.0F, -bobbing, 0.0F);
if(itemStack.getItemDamage() == 1){
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_HANDLE);
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH);
} else {
renderEntityCustomItem(itemStack, entityItem, HAMMER);
}
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_HANDLE);
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
renderEntityCustomItem(itemStack, entityItem, PAINTBRUSH_BRUSH);
GL11.glPopMatrix();
return;
}
@@ -112,19 +98,25 @@ public class ToolItemRenderer implements IItemRenderer {
EntityLivingBase entityLivingBase = (EntityLivingBase) data[1];
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_HANDLE);
GL11.glPopMatrix();
if(itemStack.getItemDamage() == 1){
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_HANDLE);
GL11.glPopMatrix();
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH);
GL11.glPopMatrix();
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, PAINTBRUSH_BRUSH);
GL11.glPopMatrix();
} else {
GL11.glPushMatrix();
renderItem3d(entityLivingBase, itemStack, HAMMER);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
@@ -232,7 +224,6 @@ public class ToolItemRenderer implements IItemRenderer {
for (int k = 0; k < b0; ++k)
{
GL11.glTranslatef(0f, 0f, f9 + f10);
// TODO: May need to rebind here
ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, 16, 16, f9);
if (itemStack.hasEffect(pass))
{
@@ -327,15 +318,20 @@ public class ToolItemRenderer implements IItemRenderer {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_ALPHA_TEST);
textureManager.bindTexture(PAINTBRUSH_HANDLE);
renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f);
if(itemStack.getItemDamage() == 1){
textureManager.bindTexture(PAINTBRUSH_HANDLE);
renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f);
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
textureManager.bindTexture(PAINTBRUSH_BRUSH);
renderCustomItemSlot(0,0,16,16, red, green, blue);
int color = ItemNpcTool.getColor(itemStack.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
textureManager.bindTexture(PAINTBRUSH_BRUSH);
renderCustomItemSlot(0,0,16,16, red, green, blue);
} else {
textureManager.bindTexture(HAMMER);
renderCustomItemSlot(0,0,16,16, 1.0f, 1.0f, 1.0f);
}
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
@@ -404,8 +400,6 @@ public class ToolItemRenderer implements IItemRenderer {
}
public void renderItem3d(EntityLivingBase entityLivingBase, ItemStack itemStack, ResourceLocation location) {
item3dRenderTicks++;
Minecraft mc = Minecraft.getMinecraft();
TextureManager texturemanager = mc.getTextureManager();
int par3 = 0;
@@ -1,150 +0,0 @@
package noppes.npcs.client.renderer.items;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import noppes.npcs.items.ItemNpcTool;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
public class NpcItemToolRenderer implements IItemRenderer {
// Textures for the assembled paintbrush parts:
private static final ResourceLocation PAINTBRUSH_HANDLE = new ResourceLocation("customnpcs", "textures/items/npcBrushHandle.png");
private static final ResourceLocation PAINTBRUSH_BRUSH = new ResourceLocation("customnpcs", "textures/items/npcBrushHair.png");
private static final ResourceLocation ENCHANT = new ResourceLocation("textures/misc/enchanted_item_glint.png");
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return type != ItemRenderType.FIRST_PERSON_MAP;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return helper == ItemRendererHelper.ENTITY_ROTATION || helper == ItemRendererHelper.ENTITY_BOBBING;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
// Ensure the item implements our render interface
if (!(item.getItem() instanceof ItemNpcTool))
return;
EntityLivingBase entity = (EntityLivingBase) data[1];
GL11.glPushMatrix();
// For meta==1 (paintbrush) we want to assemble the texture from two parts
if (item.getItemDamage() == 1) {
renderPaintbrush(entity, item);
} else {
// For other tools, fall back on the normal special render routine.
renderItem3d(entity, item);
}
GL11.glPopMatrix();
}
/**
* Renders the paintbrush by drawing its handle first, then overlaying the brush part tinted
* by the NBT "BrushColor" value (an integer/hex value).
*/
private void renderPaintbrush(EntityLivingBase entity, ItemStack item) {
Minecraft mc = Minecraft.getMinecraft();
TextureManager textureManager = mc.getTextureManager();
Tessellator tessellator = Tessellator.instance;
int width = 16;
int height = 16;
float thickness = 0.0625F;
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
// Render the handle (untinted)
textureManager.bindTexture(PAINTBRUSH_HANDLE);
// Using full texture coordinates (0→1) in the same order as vanilla's renderItemIn2D:
ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, width, height, thickness);
// Get the NBT color (default is white if not present)
int color = ItemNpcTool.getColor(item.getTagCompound());
float red = ((color >> 16) & 0xFF) / 255.0F;
float green = ((color >> 8) & 0xFF) / 255.0F;
float blue = (color & 0xFF) / 255.0F;
GL11.glColor3f(red, green, blue);
// Render the brush (tinted by the color)
textureManager.bindTexture(PAINTBRUSH_BRUSH);
ItemRenderer.renderItemIn2D(tessellator, 1.0F, 0.0F, 0.0F, 1.0F, width, height, thickness);
// Reset GL color to white so that subsequent rendering is not tinted
GL11.glColor3f(1.0F, 1.0F, 1.0F);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
// If the item is enchanted, render the enchanted glint effect on top
if (item.hasEffect(0)) {
renderEnchantedEffect(tessellator, textureManager);
}
}
/**
* Fallback 3D item renderer (for non-paintbrush items)
*/
private void renderItem3d(EntityLivingBase entity, ItemStack item) {
Minecraft mc = Minecraft.getMinecraft();
TextureManager textureManager = mc.getTextureManager();
Tessellator tessellator = Tessellator.instance;
textureManager.bindTexture(textureManager.getResourceLocation(item.getItemSpriteNumber()));
IIcon icon = entity.getItemIcon(item, 0);
if (icon == null) {
return;
}
float minU = icon.getMinU();
float maxU = icon.getMaxU();
float minV = icon.getMinV();
float maxV = icon.getMaxV();
int width = icon.getIconWidth();
int height = icon.getIconHeight();
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
// Note: The order here mimics vanilla's 2D item rendering
ItemRenderer.renderItemIn2D(tessellator, maxU, minV, minU, maxV, width, height, 0.0625F);
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
}
/**
* Renders the enchanted glint overlay.
*/
private void renderEnchantedEffect(Tessellator tessellator, TextureManager textureManager) {
GL11.glDepthFunc(GL11.GL_EQUAL);
GL11.glDisable(GL11.GL_LIGHTING);
textureManager.bindTexture(ENCHANT);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE);
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);
ItemRenderer.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);
ItemRenderer.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.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
}
}