Skip to content

Commit

Permalink
Merge pull request #22 from GTNewHorizons/fix/item-renderer
Browse files Browse the repository at this point in the history
Properly render item halo
  • Loading branch information
Dream-Master authored Aug 20, 2022
2 parents cbb82e4 + c4bf6c9 commit 629d20b
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions src/main/java/fox/spiteful/avaritia/render/FancyHaloRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
import net.minecraftforge.client.IItemRenderer;

public class FancyHaloRenderer implements IItemRenderer {

public Random rand = new Random();

@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
Item itype = item.getItem();
if (itype instanceof IHaloRenderItem) {
IHaloRenderItem ihri = (IHaloRenderItem)itype;

if (!(ihri.drawHalo(item) || ihri.drawPulseEffect(item))) {
return false;
}
}

switch(type) {
case INVENTORY:
return true;
Expand All @@ -46,27 +46,27 @@ public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRe
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
boolean renderHalo = false;
boolean renderPulse = false;

int spread = 0;
IIcon halo = null;
int haloColour = 0;

Item itype = item.getItem();
if (itype instanceof IHaloRenderItem) {
IHaloRenderItem ihri = (IHaloRenderItem)itype;

spread = ihri.getHaloSize(item);
halo = ihri.getHaloTexture(item);
haloColour = ihri.getHaloColour(item);

renderHalo = ihri.drawHalo(item);
renderPulse = ihri.drawPulseEffect(item);
}

RenderItem r = RenderItem.getInstance();
Minecraft mc = Minecraft.getMinecraft();
Tessellator t = Tessellator.instance;

switch(type) {
case ENTITY:
break;
Expand All @@ -75,54 +75,49 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
RenderHelper.enableGUIStandardItemLighting();

GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDisable(GL11.GL_DEPTH_TEST);

if (renderHalo) {
float ca = (float)(haloColour >> 24 & 255) / 255.0F;
float cr = (float)(haloColour >> 16 & 255) / 255.0F;
float cg = (float)(haloColour >> 8 & 255) / 255.0F;
float cb = (float)(haloColour & 255) / 255.0F;
GL11.glColor4f(cr, cg, cb, ca);

t.startDrawingQuads();
t.addVertexWithUV(0-spread, 0-spread, 0, halo.getMinU(), halo.getMinV());
t.addVertexWithUV(0-spread, 16+spread, 0, halo.getMinU(), halo.getMaxV());
t.addVertexWithUV(16+spread, 16+spread, 0, halo.getMaxU(), halo.getMaxV());
t.addVertexWithUV(16+spread, 0-spread, 0, halo.getMaxU(), halo.getMinV());
t.draw();

RenderItem.getInstance().renderIcon(-spread, -spread, halo, 16 + spread * 2, 16 + spread * 2);
}

if (renderPulse) {
GL11.glPushMatrix();
double xs = (rand.nextGaussian() * 0.15) + 0.95;
double ox = (1-xs)/2.0;
GL11.glEnable(GL11.GL_BLEND);
GL11.glTranslated(ox*16.0, ox*16.0, 1.0);
GL11.glScaled(xs, xs, 1.0);

IIcon icon = item.getItem().getIcon(item, 0);

t.startDrawingQuads();
t.setColorRGBA_F(1.0f, 1.0f, 1.0f, 0.6f);
t.addVertexWithUV(0-ox, 0-ox, 0, icon.getMinU(), icon.getMinV());
t.addVertexWithUV(0-ox, 16+ox, 0, icon.getMinU(), icon.getMaxV());
t.addVertexWithUV(16+ox, 16+ox, 0, icon.getMaxU(), icon.getMaxV());
t.addVertexWithUV(16+ox, 0-ox, 0, icon.getMaxU(), icon.getMinV());
t.draw();

GL11.glPopMatrix();
}

r.renderItemIntoGUI(mc.fontRenderer, mc.getTextureManager(), item, 0, 0, true);

GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
GL11.glEnable(GL11.GL_DEPTH_TEST);

r.renderWithColor = true;

GL11.glDisable(GL11.GL_BLEND);
GL11.glPopMatrix();
break;
Expand Down

0 comments on commit 629d20b

Please sign in to comment.