Scripted & Linked Items now Rendering Images in Banners + Wall Banners

This commit is contained in:
Kam committed 2025-02-22 05:09:22 -05:00
1 parent 5dfe061bad
commit aeee864bf7
2 files changed
+89 -9

No files matched your search

@@ -6,6 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.item.ItemStack;
@@ -14,14 +15,19 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.CustomItems;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.blocks.BlockBanner;
import noppes.npcs.blocks.tiles.TileBanner;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.model.blocks.banner.ModelBannerFloor;
import noppes.npcs.client.model.blocks.banner.ModelBannerFloorFlag;
import noppes.npcs.client.model.blocks.legacy.ModelLegacyBanner;
import noppes.npcs.client.model.blocks.legacy.ModelLegacyBannerFlag;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.constants.EnumBannerVariant;
import noppes.npcs.scripted.NpcAPI;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -129,11 +135,44 @@ public class BlockBannerRenderer extends BlockRendererInterface{
float f2 = 0.05f;
Minecraft mc = Minecraft.getMinecraft();
GL11.glScalef(f2, f2, f2);
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
IItemStack iItemStack = NpcAPI.Instance().getIItemStack(iicon);
if (iItemStack instanceof IItemCustomizable) {
IItemCustomizable custom = (IItemCustomizable) iItemStack;
ImageData imageData = ClientCacheHandler.getImageData(custom.getTexture());
if (imageData.imageLoaded()) {
imageData.bindTexture();
int color = custom.getColor();
float[] colors = ColorUtil.hexToRGB(color);
renderCustomItemInBanner(colors[0], colors[1], colors[2]);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
} else {
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
}
} else {
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
}
GL11.glDepthMask(true);
GL11.glPopMatrix();
}
private void renderCustomItemInBanner(float red, float green, float blue) {
// Ensure lighting isn't interfering
GL11.glDisable(GL11.GL_LIGHTING);
// Force the texture to use the current color
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(red, green, blue, 1.0F);
tessellator.addVertexWithUV(-8, 8, 0, 0, 1);
tessellator.addVertexWithUV(8, 8, 0, 1, 1);
tessellator.addVertexWithUV(8, -8, 0, 1, 0);
tessellator.addVertexWithUV(-8, -8, 0, 0, 0);
tessellator.draw();
GL11.glEnable(GL11.GL_LIGHTING);
}
public void renderItemBanner(TextureManager txtMng, ItemStack item, int p_77015_4_, int p_77015_5_, boolean renderEffect)
{
Object object = item.getIconIndex();
@@ -6,6 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Blocks;
@@ -17,13 +18,19 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.CustomItems;
import noppes.npcs.api.item.IItemCustomizable;
import noppes.npcs.api.item.IItemStack;
import noppes.npcs.blocks.BlockWallBanner;
import noppes.npcs.blocks.tiles.TileWallBanner;
import noppes.npcs.client.ClientCacheHandler;
import noppes.npcs.client.model.blocks.banner.ModelBannerWall;
import noppes.npcs.client.model.blocks.banner.ModelBannerWallFlag;
import noppes.npcs.client.model.blocks.legacy.ModelLegacyWallBanner;
import noppes.npcs.client.model.blocks.legacy.ModelLegacyWallBannerFlag;
import noppes.npcs.client.renderer.ImageData;
import noppes.npcs.config.ConfigClient;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.item.ScriptItemStack;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
@@ -95,34 +102,68 @@ public class BlockWallBannerRenderer extends BlockRendererInterface{
}
GL11.glPopAttrib();
}
public void doRender(double par2, double par4, double par6, int meta, ItemStack iicon, float rotate)
{
public void doRender(double par2, double par4, double par6, int meta, ItemStack iicon, float rotate) {
GL11.glPushMatrix();
bindTexture(TextureMap.locationItemsTexture);
GL11.glTranslatef((float)par2 + 0.5f, (float)par4 + 0.2f, (float)par6 + 0.5f);
GL11.glRotatef(180, 0, 0, 1);
GL11.glRotatef(90 * meta, 0, 1, 0);
if(ConfigClient.LegacyBanner){
if (ConfigClient.LegacyBanner) {
GL11.glTranslatef(0, 0, 0.26f);
}
else {
} else {
GL11.glTranslatef(0, 0, 0.3f);
GL11.glTranslatef(0, -0.6f, 0); // Translate to pivot point
GL11.glRotatef((float) Math.toDegrees(rotate), 1, 0, 0); // Apply sway rotation
GL11.glTranslatef(0, 0.6f, 0); // Translate to pivot point
}
GL11.glDepthMask(false);
float f2 = 0.05f;
Minecraft mc = Minecraft.getMinecraft();
GL11.glScalef(f2, f2, f2);
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
// Check if the item is customizable.
IItemStack iItemStack = NpcAPI.Instance().getIItemStack(iicon);
if (iItemStack instanceof IItemCustomizable) {
IItemCustomizable custom = (IItemCustomizable) iItemStack;
ImageData imageData = ClientCacheHandler.getImageData(custom.getTexture());
if (imageData.imageLoaded()) {
imageData.bindTexture();
int color = custom.getColor();
float[] colors = ColorUtil.hexToRGB(color);
renderCustomItemInBanner(colors[0], colors[1], colors[2]);
GL11.glColor3f(1.0f, 1.0f, 1.0f);
} else {
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
}
} else {
renderItemBanner(mc.renderEngine, iicon, -8, -8, false);
}
GL11.glDepthMask(true);
GL11.glPopMatrix();
}
private void renderCustomItemInBanner(float red, float green, float blue) {
// Ensure lighting isn't interfering
GL11.glDisable(GL11.GL_LIGHTING);
// Force the texture to use the current color
GL11.glTexEnvi(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(red, green, blue, 1.0F);
tessellator.addVertexWithUV(-8, 8, 0, 0, 1);
tessellator.addVertexWithUV(8, 8, 0, 1, 1);
tessellator.addVertexWithUV(8, -8, 0, 1, 0);
tessellator.addVertexWithUV(-8, -8, 0, 0, 0);
tessellator.draw();
GL11.glEnable(GL11.GL_LIGHTING);
}
public void renderItemBanner(TextureManager txtMng, ItemStack item, int p_77015_4_, int p_77015_5_, boolean renderEffect)
{
Object object = item.getIconIndex();