Skip to content

Commit

Permalink
Simplify rendering logic, respect hovering
Browse files Browse the repository at this point in the history
  • Loading branch information
ACGaming committed Jun 13, 2024
1 parent aecd043 commit 4bb05bd
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBook;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand All @@ -25,48 +25,7 @@ public class RenderHSBloodAltar extends TileEntitySpecialRenderer<HSTileEntityBl
@Override
public void render(HSTileEntityBloodAltar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
{
GlStateManager.pushMatrix();
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
World world = te.getWorld();
//noinspection ConstantConditions
if (world == null) return;

GlStateManager.pushAttrib();
GlStateManager.disableLighting();
GlStateManager.translate(x, y, z);

GlStateManager.pushMatrix();
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
GlStateManager.translate(0.20, 0.25, 0.25);
RenderHelper.enableStandardItemLighting();
GlStateManager.pushAttrib();

ItemStack stack = te.getInputStack();
if (!stack.isEmpty())
{
// Display input item
GlStateManager.pushMatrix();
GlStateManager.translate(0.25, 1.75, 0.25);
GlStateManager.rotate(timeD, 0, 1, 0);
GlStateManager.scale(0.8, 0.8, 0.8);
renderItem.renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display blood essence
GlStateManager.pushMatrix();
GlStateManager.translate(0.3, 0.25, -0.25);
GlStateManager.scale(0.5, 0.5, 0.5);
renderItem.renderItem(te.getEssenceStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();
}

RenderHelper.disableStandardItemLighting();
GlStateManager.popAttrib();
GlStateManager.popMatrix();

GlStateManager.popAttrib();
GlStateManager.popMatrix();

// RENDER BOOK
GlStateManager.pushMatrix();
GlStateManager.translate((float) x + 0.5F, (float) y + 0.75F, (float) z + 0.5F);
float f = (float) te.tickCount + partialTicks;
Expand Down Expand Up @@ -114,22 +73,23 @@ public void render(HSTileEntityBloodAltar te, double x, double y, double z, floa
this.modelBook.render(null, f, f3, f4, f5, 0.0F, 0.0625F);
GlStateManager.popMatrix();

if (!stack.isEmpty())
// RENDER ITEMS & COUNTS
if (!te.getInputStack().isEmpty())
{
int textColor = te.isValidRecipe() ? 0x00FF00 : 0xFFFFFF;
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
int textColor = te.isValidRecipe() ? 0xFF5555 : 0xFFFFFF;

// Display blood count
String bloodText = "x " + te.getBloodCount();
// Display input item
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 0.25, z - 0.01);
GlStateManager.scale(-0.025f, -0.025f, 0.025f);
GlStateManager.disableLighting();
Minecraft.getMinecraft().fontRenderer.drawString(bloodText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(bloodText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.translate(x + 0.5, y + 2.0, z + 0.5);
GlStateManager.rotate(timeD, 0, 1, 0);
GlStateManager.scale(0.8, 0.8, 0.8);
renderItem.renderItem(te.getInputStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display input stack count
String stackText = String.valueOf(stack.getCount());
// Display input item count
String stackText = String.valueOf(te.getInputStack().getCount());
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 1.5, z + 0.5);
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0);
Expand All @@ -139,6 +99,60 @@ public void render(HSTileEntityBloodAltar te, double x, double y, double z, floa
Minecraft.getMinecraft().fontRenderer.drawString(stackText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(stackText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.popMatrix();

RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
if (result.typeOfHit != RayTraceResult.Type.BLOCK) return;
BlockPos resultPos = new BlockPos(result.getBlockPos().getX(), result.getBlockPos().getY(), result.getBlockPos().getZ());
if (!resultPos.equals(te.getPos())) return;

EnumFacing facing = Minecraft.getMinecraft().objectMouseOver.sideHit;
if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH || facing == EnumFacing.WEST || facing == EnumFacing.EAST)
{
double offsetX = 0;
double offsetZ = 0;
int angle = 0;
switch (facing)
{
case NORTH:
offsetX = 0.5;
offsetZ = -0.02;
break;
case SOUTH:
offsetX = 0.5;
offsetZ = 1.02;
angle = 180;
break;
case WEST:
offsetX = -0.02;
offsetZ = 0.5;
angle = 90;
break;
case EAST:
offsetX = 1.02;
offsetZ = 0.5;
angle = 270;
break;
}

// Display blood essence item
GlStateManager.pushMatrix();
GlStateManager.translate(x + offsetX, y + 0.5, z + offsetZ);
GlStateManager.rotate(angle, 0, 1, 0);
GlStateManager.scale(0.5, 0.5, 0.5);
renderItem.renderItem(te.getEssenceStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display blood essence count
String bloodText = "x " + te.getBloodCount();
GlStateManager.pushMatrix();
GlStateManager.translate(x + offsetX, y + 0.25, z + offsetZ);
GlStateManager.rotate(angle, 0, 1, 0);
GlStateManager.scale(-0.025f, -0.025f, 0.025f);
GlStateManager.disableLighting();
Minecraft.getMinecraft().fontRenderer.drawString(bloodText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(bloodText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.popMatrix();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBook;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

Expand All @@ -25,48 +25,7 @@ public class RenderHSSoulAltar extends TileEntitySpecialRenderer<HSTileEntitySou
@Override
public void render(HSTileEntitySoulAltar te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
{
GlStateManager.pushMatrix();
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
World world = te.getWorld();
//noinspection ConstantConditions
if (world == null) return;

GlStateManager.pushAttrib();
GlStateManager.disableLighting();
GlStateManager.translate(x, y, z);

GlStateManager.pushMatrix();
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
GlStateManager.translate(0.20, 0.25, 0.25);
RenderHelper.enableStandardItemLighting();
GlStateManager.pushAttrib();

ItemStack stack = te.getInputStack();
if (!stack.isEmpty())
{
// Display input item
GlStateManager.pushMatrix();
GlStateManager.translate(0.25, 1.75, 0.25);
GlStateManager.rotate(timeD, 0, 1, 0);
GlStateManager.scale(0.8, 0.8, 0.8);
renderItem.renderItem(stack, ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display soul essence
GlStateManager.pushMatrix();
GlStateManager.translate(0.3, 0.25, -0.25);
GlStateManager.scale(0.5, 0.5, 0.5);
renderItem.renderItem(te.getEssenceStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();
}

RenderHelper.disableStandardItemLighting();
GlStateManager.popAttrib();
GlStateManager.popMatrix();

GlStateManager.popAttrib();
GlStateManager.popMatrix();

// RENDER BOOK
GlStateManager.pushMatrix();
GlStateManager.translate((float) x + 0.5F, (float) y + 0.75F, (float) z + 0.5F);
float f = (float) te.tickCount + partialTicks;
Expand Down Expand Up @@ -114,22 +73,23 @@ public void render(HSTileEntitySoulAltar te, double x, double y, double z, float
this.modelBook.render(null, f, f3, f4, f5, 0.0F, 0.0625F);
GlStateManager.popMatrix();

if (!stack.isEmpty())
// RENDER ITEMS & COUNTS
if (!te.getInputStack().isEmpty())
{
int textColor = te.isValidRecipe() ? 0x00FF00 : 0xFFFFFF;
float timeD = (float) (360.0 * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL);
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
int textColor = te.isValidRecipe() ? 0x55FFFF : 0xFFFFFF;

// Display soul count
String soulsText = "x " + te.getSoulCount();
// Display input item
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 0.25, z - 0.01);
GlStateManager.scale(-0.025f, -0.025f, 0.025f);
GlStateManager.disableLighting();
Minecraft.getMinecraft().fontRenderer.drawString(soulsText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(soulsText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.translate(x + 0.5, y + 2.0, z + 0.5);
GlStateManager.rotate(timeD, 0, 1, 0);
GlStateManager.scale(0.8, 0.8, 0.8);
renderItem.renderItem(te.getInputStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display input stack count
String stackText = String.valueOf(stack.getCount());
// Display input item count
String stackText = String.valueOf(te.getInputStack().getCount());
GlStateManager.pushMatrix();
GlStateManager.translate(x + 0.5, y + 1.5, z + 0.5);
GlStateManager.rotate(-Minecraft.getMinecraft().getRenderManager().playerViewY, 0, 1, 0);
Expand All @@ -139,6 +99,60 @@ public void render(HSTileEntitySoulAltar te, double x, double y, double z, float
Minecraft.getMinecraft().fontRenderer.drawString(stackText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(stackText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.popMatrix();

RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
if (result.typeOfHit != RayTraceResult.Type.BLOCK) return;
BlockPos resultPos = new BlockPos(result.getBlockPos().getX(), result.getBlockPos().getY(), result.getBlockPos().getZ());
if (!resultPos.equals(te.getPos())) return;

EnumFacing facing = Minecraft.getMinecraft().objectMouseOver.sideHit;
if (facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH || facing == EnumFacing.WEST || facing == EnumFacing.EAST)
{
double offsetX = 0;
double offsetZ = 0;
int angle = 0;
switch (facing)
{
case NORTH:
offsetX = 0.5;
offsetZ = -0.02;
break;
case SOUTH:
offsetX = 0.5;
offsetZ = 1.02;
angle = 180;
break;
case WEST:
offsetX = -0.02;
offsetZ = 0.5;
angle = 90;
break;
case EAST:
offsetX = 1.02;
offsetZ = 0.5;
angle = 270;
break;
}

// Display soul essence item
GlStateManager.pushMatrix();
GlStateManager.translate(x + offsetX, y + 0.5, z + offsetZ);
GlStateManager.rotate(angle, 0, 1, 0);
GlStateManager.scale(0.5, 0.5, 0.5);
renderItem.renderItem(te.getEssenceStack(), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.popMatrix();

// Display soul essence count
String soulsText = "x " + te.getSoulCount();
GlStateManager.pushMatrix();
GlStateManager.translate(x + offsetX, y + 0.25, z + offsetZ);
GlStateManager.rotate(angle, 0, 1, 0);
GlStateManager.scale(-0.025f, -0.025f, 0.025f);
GlStateManager.disableLighting();
Minecraft.getMinecraft().fontRenderer.drawString(soulsText, -Minecraft.getMinecraft().fontRenderer.getStringWidth(soulsText) / 2, 0, textColor);
GlStateManager.enableLighting();
GlStateManager.popMatrix();
}
}
}
}

0 comments on commit 4bb05bd

Please sign in to comment.