Jump to content

[Solved][1.6.4] TileEntitySpecialRenderer breaks with another entity in view


Recommended Posts

Posted

UPDATE: Turns out when another entity is in the scene the wrong texture map is set (items instead of blocks) . Adding "bindTexture(TextureMap.locationBlocksTexture)" in "renderTileEntityAt()" fixed the problem.

 

I implemented a TileEntitySpecialRenderer and everything is rendered exactly as it should be until any entitys other than my own enter the scene (e.g. any item, any creature and even the player itself in 3rd person view). I first thought I messed up with the Tessellator.draw() and Tessellator.startDrawingQuads() calls but if I do it any other way than in the posted code I get the usual exceptions ("tessellator already tessellating" etc). Hints on what's going on here would be very appreciated.

(The transparent blocks are the ones rendered by the TileEntitySpecialRenderer)

 

That's how it's always supposed to look like

a3gneq.jpg

 

That's how it looks with an addtional entity in the scene (the bucket on the ground).

34nmnvo.png

 

TileEntitySpecialRenderer

package simplefluidtanks;

import java.util.ArrayList;
import java.util.HashMap;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.launchwrapper.LogWrapper;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidRegistry.FluidRegisterEvent;
import net.minecraftforge.fluids.FluidStack;

@SideOnly(Side.CLIENT)
public class TankBlockRenderer extends TileEntitySpecialRenderer
{
public TankBlockRenderer()
{
	super();
}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
{
	if (tileEntity == null || !(tileEntity instanceof TankBlockEntity))
	{
		return;
	}

	Block block = tileEntity.getBlockType();

	if (block == null || !(block instanceof TankBlock))
	{
		return;
	}

	TankBlock tank = (TankBlock)block;
	TankBlockEntity entity = (TankBlockEntity)tileEntity;
	Icon[] icons = tank.getIcons();

	Tessellator tsr = Tessellator.instance;
	int brightness = block.getMixedBrightnessForBlock(entity.worldObj, entity.xCoord, entity.yCoord, entity.zCoord);
	tsr.setBrightness(brightness);

	TessellationManager.setBaseCoords(x, y, z);

	if (tsr.isDrawing) tsr.draw();

	tsr.startDrawingQuads();

	if (!entity.isPartOfTank())
	{
		renderSolid(entity, icons[0]);
	}
	else
	{
		boolean[] connections = entity.getConnections();
		int fillPercentage = entity.getFillPercentage();
		double fluidHeight = 16.0 / 100 * fillPercentage;
		double verticalTextureOffset = 16.0 / 100 * (100 - fillPercentage);
		Icon fluidIcon = getFluidTexture(entity);

		renderPositiveXFace(entity, connections, icons, fluidIcon, fillPercentage, fluidHeight, verticalTextureOffset);
		renderNegativeXFace(entity, connections, icons, fluidIcon, fillPercentage, fluidHeight, verticalTextureOffset);
		renderPositiveZFace(entity, connections, icons, fluidIcon, fillPercentage, fluidHeight, verticalTextureOffset);
		renderNegativeZFace(entity, connections, icons, fluidIcon, fillPercentage, fluidHeight, verticalTextureOffset);
		renderPositiveYFace(entity, connections, icons, fluidIcon, fillPercentage, fluidHeight);
		renderNegativeYFace(entity, connections, icons, fluidIcon, fillPercentage);
	}

	tsr.draw();
}

private void renderSolid(TankBlockEntity entity, Icon icon)
{
	TessellationManager.renderCube(1, 0, 1, 14, 14, 14, icon, true, TessellationManager.pixel);
}

private void renderPositiveXFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage, double fluidHeight, double verticalTextureOffset)
{
	// only render this side if there isn't a tank block from the same tank in front of it 
	if (!connections[ConnectedTexturesHelper.XPOS])
	{
		if (fillPercentage > 0 && fluidIcon != null)
		{
			TessellationManager.renderPositiveXFace(16, 0, 0, fluidHeight, 16, 0, verticalTextureOffset, 0, 0, fluidIcon, TessellationManager.pixel);
		}

		TessellationManager.renderPositiveXFace(16, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.XPOS)]);
		// inner face
		TessellationManager.renderNegativeXFace(16, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.XNEG)]);
	}
}

private void renderNegativeXFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage, double fluidHeight, double verticalTextureOffset)
{
	// only render this side if there isn't a tank block from the same tank in front of it 
	if (!connections[ConnectedTexturesHelper.XNEG])
	{
		if (fillPercentage > 0 && fluidIcon != null)
		{
			TessellationManager.renderNegativeXFace(0, 0, 0, fluidHeight, 16, 0, verticalTextureOffset, 0, 0, fluidIcon, TessellationManager.pixel);
		}

		TessellationManager.renderNegativeXFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.XNEG)]);
		// inner face
		TessellationManager.renderPositiveXFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.XPOS)]);
	}
}

private void renderPositiveZFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage, double fluidHeight, double verticalTextureOffset)
{
	// only render this side if there isn't a tank block from the same tank in front of it 
	if (!connections[ConnectedTexturesHelper.ZPOS])
	{
		if (fillPercentage > 0 && fluidIcon != null)
		{
			TessellationManager.renderPositiveZFace(0, 0, 16, 16, fluidHeight, 0, verticalTextureOffset, 0, 0, fluidIcon, TessellationManager.pixel);
		}

		TessellationManager.renderPositiveZFace(0, 0, 16, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.ZPOS)]);
		// inner face
		TessellationManager.renderNegativeZFace(0, 0, 16, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.ZNEG)]);
	}
}

private void renderNegativeZFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage, double fluidHeight, double verticalTextureOffset)
{
	// only render this side if there isn't a tank block from the same tank in front of it 
	if (!connections[ConnectedTexturesHelper.ZNEG])
	{
		if (fillPercentage > 0 && fluidIcon != null)
		{
			TessellationManager.renderNegativeZFace(0, 0, 0, 16, fluidHeight, 0, verticalTextureOffset, 0, 0, fluidIcon, TessellationManager.pixel);
		}

		TessellationManager.renderNegativeZFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.ZNEG)]);
		// inner face
		TessellationManager.renderPositiveZFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.ZPOS)]);
	}
}

private void renderPositiveYFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage, double fluidHeight)
{
	if (fillPercentage > 0 && fluidIcon != null)
	{
		TessellationManager.renderPositiveYFace(0, fluidHeight, 0, 16, 16, fluidIcon);
	}

	// only render this side if there isn't a tank block from the same tank in front of it 
	if (!connections[ConnectedTexturesHelper.YPOS])
	{
		TessellationManager.renderPositiveYFace(0, 16, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.YPOS)]);
		// inner face
		TessellationManager.renderNegativeYFace(0, 16, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.YNEG)]);
	}
}

private void renderNegativeYFace(TankBlockEntity entity, boolean[] connections, Icon[] icons, Icon fluidIcon, int fillPercentage)
{
	// only render this side if there isn't a tank block from the same tank in front of it 
	if (fillPercentage > 0 && fluidIcon != null && !connections[ConnectedTexturesHelper.YNEG])
	{
		TessellationManager.renderNegativeYFace(0, 0, 0, 16, 16, fluidIcon);
	}

	if (!connections[ConnectedTexturesHelper.YNEG])
	{
		TessellationManager.renderNegativeYFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.YNEG)]);
		// inner face
		TessellationManager.renderPositiveYFace(0, 0, 0, 16, 16, icons[entity.getTexture(ConnectedTexturesHelper.YPOS)]);
	}
}

private Icon getFluidTexture(TankBlockEntity entity)
{
	ValveBlockEntity valve = entity.getValve();

	if (valve != null)
	{
		FluidStack fluidStack = valve.getFluid();

		if (fluidStack != null)
		{
			return fluidStack.getFluid().getIcon();
		}
	}

	return null;
}
}

 

TessellationManager (helper class)

package simplefluidtanks;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidRegistry;

public final class TessellationManager
{
public static final double pixel = 1d / 16d;

private static final Tessellator tr = Tessellator.instance;
private static double xBaseCoord;
private static double yBaseCoord;
private static double zBaseCoord;

private TessellationManager()
{
}

public static void setBaseCoords(double ... coords)
{
	if (coords != null && coords.length >= 3)
	{
		xBaseCoord = coords[0];
		yBaseCoord = coords[1];
		zBaseCoord = coords[2];
	}
}

public static void renderCube(double xOffset, double yOffset, double zOffset, double width, double height, double depth, Icon icon)
{
	renderCube(xOffset, yOffset, zOffset, width, height, depth, icon, false, pixel);
}

public static void renderCube(double xOffset, double yOffset, double zOffset, double width, double height, double depth, Icon icon, boolean renderInside, double scale)
{
	renderPositiveXFace(xOffset + width, yOffset, zOffset, height, depth, icon, scale);
	renderNegativeXFace(xOffset, yOffset, zOffset, height, depth, icon, scale);
	renderPositiveYFace(xOffset, yOffset + height, zOffset, width, depth, icon, scale);
	renderNegativeYFace(xOffset, yOffset, zOffset, width, depth, icon, scale);
	renderPositiveZFace(xOffset, yOffset, zOffset + depth, width, height, icon, scale);
	renderNegativeZFace(xOffset, yOffset, zOffset, width, height, icon, scale);

	if (renderInside)
	{
		// positive x back side
		renderNegativeXFace(xOffset + width, yOffset, zOffset, height, depth, icon, scale);
		// negative x back side
		renderPositiveXFace(xOffset, yOffset, zOffset, height, depth, icon, scale);
		// positive y back side
		renderNegativeYFace(xOffset, yOffset + height, zOffset, width, depth, icon, scale);
		// negative y back side
		renderPositiveYFace(xOffset, yOffset, zOffset, width, depth, icon, scale);
		// positive z back side
		renderNegativeZFace(xOffset, yOffset, zOffset + depth, width, height, icon, scale);
		// negative back side
		renderPositiveZFace(xOffset, yOffset, zOffset, width, height, icon, scale);
	}
}

public static void renderPositiveXFace(double xOffset, double yOffset, double zOffset, double height, double depth, Icon icon)
{
	renderPositiveXFace(xOffset, yOffset, zOffset, height, depth, 0, 0, 0, 0, icon, pixel);
}

public static void renderPositiveXFace(double xOffset, double yOffset, double zOffset, double height, double depth, Icon icon, double scale)
{
	renderPositiveXFace(xOffset, yOffset, zOffset, height, depth, 0, 0, 0, 0, icon, scale);
}

public static void renderPositiveXFace(double xOffset, double yOffset, double zOffset, double height, double depth, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(1f, 0f, 0f);

	double x = xBaseCoord + xOffset * scale;

	// bottom right
	double zBr = zBaseCoord + zOffset * scale;
	double yBr = yBaseCoord + yOffset * scale;

	// top right
	double zTr = zBaseCoord + zOffset * scale;
	double yTr = yBaseCoord + (yOffset + height) * scale;

	// top left
	double zTl = zBaseCoord + (zOffset + depth) * scale;
	double yTl = yBaseCoord + (yOffset + height) * scale;

	// bottom left
	double zBl = zBaseCoord + (zOffset + depth) * scale;
	double yBl = yBaseCoord + yOffset * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// bottom right
	tr.addVertexWithUV(x, yBr, zBr, maxU, maxV);
	// top right
	tr.addVertexWithUV(x, yTr, zTr, maxU, minV);
	// top left
	tr.addVertexWithUV(x, yTl, zTl, minU, minV);
	// bottom left
	tr.addVertexWithUV(x, yBl, zBl, minU, maxV);
}

public static void renderNegativeXFace(double xOffset, double yOffset, double zOffset, double height, double depth, Icon icon)
{
	renderNegativeXFace(xOffset, yOffset, zOffset, height, depth, 0, 0, 0, 0, icon, pixel);
}

public static void renderNegativeXFace(double xOffset, double yOffset, double zOffset, double height, double depth, Icon icon, double scale)
{
	renderNegativeXFace(xOffset, yOffset, zOffset, height, depth, 0, 0, 0, 0, icon, scale);
}

public static void renderNegativeXFace(double xOffset, double yOffset, double zOffset, double height, double depth, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(-1f, 0f, 0f);

	double x = xBaseCoord + xOffset * scale;

	// bottom left
	double zBl = zBaseCoord + zOffset * scale;
	double yBl = yBaseCoord + yOffset * scale;

	// bottom right
	double zBr = zBaseCoord + (zOffset + depth) * scale;
	double yBr = yBaseCoord + yOffset * scale;

	// top right
	double zTr = zBaseCoord + (zOffset + depth) * scale;
	double yTr = yBaseCoord + (yOffset + height) * scale;

	// top left
	double zTl = zBaseCoord + zOffset * scale;
	double yTl = yBaseCoord + (yOffset + height) * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// bottom left
	tr.addVertexWithUV(x, yBl, zBl, minU, maxV);
	// bottom right
	tr.addVertexWithUV(x, yBr, zBr, maxU, maxV);
	// top right
	tr.addVertexWithUV(x, yTr, zTr, maxU, minV);
	// top left
	tr.addVertexWithUV(x, yTl, zTl, minU, minV);
}

public static void renderPositiveYFace(double xOffset, double yOffset, double zOffset, double width, double depth, Icon icon)
{
	renderPositiveYFace(xOffset, yOffset, zOffset, width, depth, 0, 0, 0, 0, icon, pixel);
}

public static void renderPositiveYFace(double xOffset, double yOffset, double zOffset, double width, double depth, Icon icon, double scale)
{
	renderPositiveYFace(xOffset, yOffset, zOffset, width, depth, 0, 0, 0, 0, icon, scale);
}

public static void renderPositiveYFace(double xOffset, double yOffset, double zOffset, double width, double depth, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(0f, 1f, 0f);

	double y = yBaseCoord + yOffset * scale;

	// bottom right
	double xBr = xBaseCoord + xOffset * scale;
	double zBr = zBaseCoord + zOffset * scale;

	// top right
	double xTr = xBaseCoord + xOffset * scale;
	double zTr = zBaseCoord + (zOffset + depth) * scale;

	// top left
	double xTl = xBaseCoord + (xOffset + width) * scale;
	double zTl = zBaseCoord + (zOffset + depth) * scale;

	// bottom left
	double xBl = xBaseCoord + (xOffset + width) * scale;
	double zBl = zBaseCoord + zOffset * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// bottom right
	tr.addVertexWithUV(xBr, y, zBr, maxU, maxV);
	// top right
	tr.addVertexWithUV(xTr, y, zTr, maxU, minV);
	// top left
	tr.addVertexWithUV(xTl, y, zTl, minU, minV);
	// bottom left
	tr.addVertexWithUV(xBl, y, zBl, minU, maxV);
}

public static void renderNegativeYFace(double xOffset, double yOffset, double zOffset, double width, double depth, Icon icon)
{
	renderNegativeYFace(xOffset, yOffset, zOffset, width, depth, 0, 0, 0, 0, icon, pixel);
}

public static void renderNegativeYFace(double xOffset, double yOffset, double zOffset, double width, double depth, Icon icon, double scale)
{
	renderNegativeYFace(xOffset, yOffset, zOffset, width, depth, 0, 0, 0, 0, icon, scale);
}

public static void renderNegativeYFace(double xOffset, double yOffset, double zOffset, double width, double depth, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(0f, -1f, 0f);

	double y = yBaseCoord + yOffset * scale;

	// top right
	double xTr = xBaseCoord + xOffset * scale;
	double zTr = zBaseCoord + zOffset * scale;

	// top left
	double xTl = xBaseCoord + (xOffset + width) * scale;
	double zTl = zBaseCoord + zOffset * scale;

	// bottom left
	double xBl = xBaseCoord + (xOffset + width) * scale;
	double zBl = zBaseCoord + (zOffset + depth) * scale;

	// bottom right
	double xBr = xBaseCoord + xOffset * scale;
	double zBr = zBaseCoord + (zOffset + depth) * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// top right
	tr.addVertexWithUV(xTr, y, zTr, maxU, minV);
	// top left
	tr.addVertexWithUV(xTl, y, zTl, minU, minV);
	// bottom left
	tr.addVertexWithUV(xBl, y, zBl, minU, maxV);
	// bottom right
	tr.addVertexWithUV(xBr, y, zBr, maxU, maxV);
}

public static void renderPositiveZFace(double xOffset, double yOffset, double zOffset, double width, double height, Icon icon)
{
	renderPositiveZFace(xOffset, yOffset, zOffset, width, height, 0, 0, 0, 0, icon, pixel);
}

public static void renderPositiveZFace(double xOffset, double yOffset, double zOffset, double width, double height, Icon icon, double scale)
{
	renderPositiveZFace(xOffset, yOffset, zOffset, width, height, 0, 0, 0, 0, icon, scale);
}

public static void renderPositiveZFace(double xOffset, double yOffset, double zOffset, double width, double height, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(0f, 0f, 1f);

	double z = zBaseCoord + zOffset * scale;

	// bottom left
	double xBl = xBaseCoord + xOffset * scale;
	double yBl = yBaseCoord + yOffset * scale;

	// bottom right
	double xBr = xBaseCoord + (xOffset + width) * scale;
	double yBr = yBaseCoord + yOffset * scale;

	// top right
	double xTr = xBaseCoord + (xOffset + width) * scale;
	double yTr = yBaseCoord + (yOffset + height) * scale;

	// top left
	double xTl = xBaseCoord + xOffset * scale;
	double yTl = yBaseCoord + (yOffset + height) * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// bottom left
	tr.addVertexWithUV(xBl, yBl, z, minU, maxV);
	// bottom right
	tr.addVertexWithUV(xBr, yBr, z, maxU, maxV);
	// top right
	tr.addVertexWithUV(xTr, yTr, z, maxU, minV);
	// top left
	tr.addVertexWithUV(xTl, yTl, z, minU, minV);
}

public static void renderNegativeZFace(double xOffset, double yOffset, double zOffset, double width, double height, Icon icon)
{
	renderNegativeZFace(xOffset, yOffset, zOffset, width, height, 0, 0, 0, 0, icon, pixel);
}

public static void renderNegativeZFace(double xOffset, double yOffset, double zOffset, double width, double height, Icon icon, double scale)
{
	renderNegativeZFace(xOffset, yOffset, zOffset, width, height, 0, 0, 0, 0, icon, scale);
}

public static void renderNegativeZFace(double xOffset, double yOffset, double zOffset, double width, double height, double uOffset, double vOffset, double uMaxOffset, double vMaxOffset, Icon icon, double scale)
{
	tr.setNormal(0f, 0f, -1f);

	double z = zBaseCoord + zOffset * scale;

	// bottom right
	double xBr = xBaseCoord + xOffset * scale;
	double yBr = yBaseCoord + yOffset * scale;

	// top right
	double xTr = xBaseCoord + xOffset * scale;
	double yTr = yBaseCoord + (yOffset + height) * scale;

	// top left
	double xTl = xBaseCoord + (xOffset + width) * scale;
	double yTl = yBaseCoord + (yOffset + height) * scale;

	// bottom left
	double xBl = xBaseCoord + (xOffset + width) * scale;
	double yBl = yBaseCoord + yOffset * scale;

	double minU = (uOffset > 0 && uOffset < 16) ? icon.getMinU() + (icon.getInterpolatedU(uOffset) - icon.getMinU()) : icon.getMinU();
	double maxU = (uMaxOffset > 0 && uMaxOffset < 16) ? icon.getMaxU() - (icon.getMaxU() - icon.getInterpolatedU(uMaxOffset)) : icon.getMaxU();
	double minV = (vOffset > 0 && vOffset < 16) ? icon.getMinV() + (icon.getInterpolatedV(vOffset) - icon.getMinV()) : icon.getMinV();
	double maxV = (vMaxOffset > 0 && vMaxOffset < 16) ? icon.getMaxV() - (icon.getMaxV() - icon.getInterpolatedV(vMaxOffset)) : icon.getMaxV();

	// bottom right
	tr.addVertexWithUV(xBr, yBr, z, maxU, maxV);
	// top right
	tr.addVertexWithUV(xTr, yTr, z, maxU, minV);
	// top left
	tr.addVertexWithUV(xTl, yTl, z, minU, minV);
	// bottom left
	tr.addVertexWithUV(xBl, yBl, z, minU, maxV);
}
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
    • Hi everyone, I'm currently developing a Forge 1.21 mod for Minecraft and I want to display a custom HUD overlay for a minigame. My goal: When the game starts, all players should see an item/block icon (from the base game, not a custom texture) plus its name/text in the HUD – similar to how the bossbar overlay works. The HUD should appear centered above the hotbar (or at a similar prominent spot), and update dynamically (icon and name change as the target item changes). What I've tried: I looked at many online tutorials and several GitHub repos (e.g. SeasonHUD, MiniHUD), but most of them use NeoForge or Forge versions <1.20 that provide the IGuiOverlay API (e.g. implements IGuiOverlay, RegisterGuiOverlaysEvent). In Forge 1.21, it seems that neither IGuiOverlay nor RegisterGuiOverlaysEvent exist anymore – at least, I can't import them and they are missing from the docs and code completion. I tried using RenderLevelStageEvent as a workaround but it is probably not intended for custom HUDs. I am not using NeoForge, and switching the project to NeoForge is currently not an option for me. I tried to look at the original minecraft source code to see how elements like hearts, hotbar etc are drawn on the screen but I am too new to Minecraft modding to understand. What I'm looking for: What is the correct way to add a custom HUD element (icon + text) in Forge 1.21, given that the previous overlay API is missing? Is there a new recommended event, callback, or method in Forge 1.21 for custom HUD overlays, or is everyone just using a workaround? Is there a minimal open-source example repo for Forge 1.21 that demonstrates a working HUD overlay without relying on NeoForge or deprecated Forge APIs? My ideal solution: Centered HUD element with an in-game item/block icon (from the base game's assets, e.g. a diamond or any ItemStack / Item) and its name as text, with a transparent background rectangle. It should be visible to the players when the mini game is running. Easy to update the item (e.g. static variable or other method), so it can change dynamically during the game. Any help, code snippets, or up-to-date references would be really appreciated! If this is simply not possible right now in Forge 1.21, it would also help to know that for sure. Thank you very much in advance!
    • The simple answer is there is not an easy way. You would need to know how to program in Java, as well as at least some familiarity with how Forge works so you could port the differences. You would also need the sourcecode for the original mod, and permission from the author to modify it, if they did not use some sort of open source license. So it's not impossible, but it would take some effort, but doing so would open up a whole new world of possibilities for you!
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.