Jump to content

[1.7.10] Tessellator Model texture problem


Erfurt

Recommended Posts

Hey guys,

 

So i have made a model using tessellator, and I have tested it with a test texture, and it works perfectly. However I have a block class that I want to use my model for, but the thing is the block have subblocks, and I have different textures for each subblock. The textures are defined in the block class, and I don't know how to take them from there and use them in the tessellator model.

 

So my question is there an easy way to do it? Preferable a way where I can add the texture for more subblocks in my block class, I don't know if that is possible.

Link to comment
Share on other sites

Tesselator is just the way I draw the model.

Here's my code, and as I stated in the original post, everything is working fine, I just want to be able to grab the texture from the block instead of having to add it in the model. The reason for this is because my block havesubblocks with different textures.

private final ResourceLocation texture = new ResourceLocation(Reference.MOD_ID + ":" + "textures/model/test2.png");

boolean drawInside = true;

private float pixel = 1F/16F;
private float texturePixel = 1F/16F;

@Override
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f)
{
	//System.out.println("RENDERING BLOCK HEDGE");
	GL11.glPushMatrix();
	GL11.glTranslatef((float)x, (float)y, (float)z);
	GL11.glDisable(GL11.GL_LIGHTING);
	this.bindTexture(texture);
	{

		TileEntityHedge hedge = (TileEntityHedge) tileentity;

		if(!hedge.onlyOneOpposite(hedge.connections))
		{
			drawCore(tileentity);

			for(int i = 0; i < hedge.connections.length; i++)
			{
				if(hedge.connections[i] != null)
				{
					drawConnector(hedge.connections[i]);
				}
			}

		}else
		{
			for(int i = 0; i < hedge.connections.length; i++)
			{
				if(hedge.connections[i] != null)
				{
					drawStraight(hedge.connections[i]);
					break;
				}
			}
		}

	}
	GL11.glEnable(GL11.GL_LIGHTING);
	GL11.glTranslatef(-(float)x, -(float)y, -(float)z);
	GL11.glPopMatrix();
}

public void drawStraight (ForgeDirection direction)
{
	GL11.glTranslatef(0.5F, 0.5F, 0.5F);
	if(direction.equals(ForgeDirection.EAST) || direction.equals(ForgeDirection.WEST))
	{
		//ROTATE
	}else if(direction.equals(ForgeDirection.NORTH) || direction.equals(ForgeDirection.SOUTH))
	{
		GL11.glRotatef(90, 0, 1, 0);
	}
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);

	Tessellator tessellator = Tessellator.instance;
	tessellator.startDrawingQuads();
	{
		tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 1);
		tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 0);
		tessellator.addVertexWithUV(0, 1, 1-8*pixel/2, 0, 0);
		tessellator.addVertexWithUV(0, 0, 1-8*pixel/2, 0, 1);

		tessellator.addVertexWithUV(0, 0, 8*pixel/2, 1, 1);
		tessellator.addVertexWithUV(0, 1, 8*pixel/2, 1, 0);
		tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 0);
		tessellator.addVertexWithUV(1, 0, 8*pixel/2, 0, 1);

		tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 0, 4*texturePixel);
		tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 12*texturePixel);
		tessellator.addVertexWithUV(0, 1, 8*pixel/2, 1, 12*texturePixel);
		tessellator.addVertexWithUV(0, 1, 1-8*pixel/2, 1, 4*texturePixel);

		tessellator.addVertexWithUV(0, 0, 1-8*pixel/2, 0, 4*texturePixel);
		tessellator.addVertexWithUV(0, 0, 8*pixel/2, 0, 12*texturePixel);
		tessellator.addVertexWithUV(1, 0, 8*pixel/2, 1, 12*texturePixel);
		tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 4*texturePixel);

		if(drawInside)
		{
			tessellator.addVertexWithUV(0, 0, 1-8*pixel/2, 0, 1);
			tessellator.addVertexWithUV(0, 1, 1-8*pixel/2, 0, 0);
			tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 0);
			tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 1);

			tessellator.addVertexWithUV(1, 0, 8*pixel/2, 0, 1);
			tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 0);
			tessellator.addVertexWithUV(0, 1, 8*pixel/2, 1, 0);
			tessellator.addVertexWithUV(0, 0, 8*pixel/2, 1, 1);

			tessellator.addVertexWithUV(0, 1, 1-8*pixel/2, 1, 4*texturePixel);
			tessellator.addVertexWithUV(0, 1, 8*pixel/2, 1, 12*texturePixel);
			tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 12*texturePixel);
			tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 0, 4*texturePixel);

			tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 4*texturePixel);
			tessellator.addVertexWithUV(1, 0, 8*pixel/2, 1, 12*texturePixel);
			tessellator.addVertexWithUV(0, 0, 8*pixel/2, 0, 12*texturePixel);
			tessellator.addVertexWithUV(0, 0, 1-8*pixel/2, 0, 4*texturePixel);
		}
	}
	tessellator.draw();

	GL11.glTranslatef(0.5F, 0.5F, 0.5F);
	if(direction.equals(ForgeDirection.NORTH) || direction.equals(ForgeDirection.SOUTH))
	{
		GL11.glRotatef(-90, 0, 1, 0);
	}
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
}

public void drawConnector (ForgeDirection direction)
{
	GL11.glTranslatef(0.5F, 0.5F, 0.5F);
	if(direction.equals(ForgeDirection.EAST))
	{
		//ROTATE
	}else if(direction.equals(ForgeDirection.WEST))
	{
		GL11.glRotatef(180, 0, 1, 0);
	}else if(direction.equals(ForgeDirection.NORTH))
	{
		GL11.glRotatef(90, 0, 1, 0);
	}else if(direction.equals(ForgeDirection.SOUTH))
	{
		GL11.glRotatef(-90, 0, 1, 0);
	}
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);

	Tessellator tessellator = Tessellator.instance;
	tessellator.startDrawingQuads();
	{
		tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 1);
		tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);

		tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
		tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 0);
		tessellator.addVertexWithUV(1, 0, 8*pixel/2, 0, 1);

		tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 12*texturePixel);
		tessellator.addVertexWithUV(1, 1, 8*pixel/2, 1, 4*texturePixel);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 4*texturePixel);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);

		tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 4*texturePixel);
		tessellator.addVertexWithUV(1, 0, 8*pixel/2, 1, 4*texturePixel);
		tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 12*texturePixel);

		if(drawInside)
		{
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
			tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 0);
			tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 1);

			tessellator.addVertexWithUV(1, 0, 8*pixel/2, 0, 1);
			tessellator.addVertexWithUV(1, 1, 8*pixel/2, 0, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);

			tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 4*texturePixel);
			tessellator.addVertexWithUV(1, 1, 8*pixel/2, 1, 4*texturePixel);
			tessellator.addVertexWithUV(1, 1, 1-8*pixel/2, 1, 12*texturePixel);

			tessellator.addVertexWithUV(1, 0, 1-8*pixel/2, 1, 12*texturePixel);
			tessellator.addVertexWithUV(1, 0, 8*pixel/2, 1, 4*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 4*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);
		}
	}
	tessellator.draw();

	GL11.glTranslatef(0.5F, 0.5F, 0.5F);
	if(direction.equals(ForgeDirection.WEST))
	{
		GL11.glRotatef(-180, 0, 1, 0);
	}else if(direction.equals(ForgeDirection.NORTH))
	{
		GL11.glRotatef(-90, 0, 1, 0);
	}else if(direction.equals(ForgeDirection.SOUTH))
	{
		GL11.glRotatef(90, 0, 1, 0);
	}
	GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
}

public void drawCore (TileEntity tileentity)
{
	Tessellator tessellator = Tessellator.instance;
	tessellator.startDrawingQuads();
	{
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
		tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 0);
		tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 4*texturePixel, 1);

		tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 1);
		tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);

		tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);
		tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
		tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
		tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);

		tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 1);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 0);
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 4*texturePixel, 1);

		tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 4*texturePixel);
		tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 12*texturePixel);
		tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 12*texturePixel);
		tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 4*texturePixel);

		tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);
		tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 4*texturePixel);
		tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 4*texturePixel);
		tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 12*texturePixel);

		if(drawInside)
		{
			tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 4*texturePixel, 1);
			tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);

			tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
			tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 0);
			tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 1);

			tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 1);
			tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 0);
			tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 0);
			tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 1);

			tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 4*texturePixel, 1);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 0);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 12*texturePixel, 1);

			tessellator.addVertexWithUV(8*pixel/2, 1, 1-8*pixel/2, 12*texturePixel, 4*texturePixel);
			tessellator.addVertexWithUV(8*pixel/2, 1, 8*pixel/2, 12*texturePixel, 12*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 8*pixel/2, 4*texturePixel, 12*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 1, 1-8*pixel/2, 4*texturePixel, 4*texturePixel);

			tessellator.addVertexWithUV(1-8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 12*texturePixel);
			tessellator.addVertexWithUV(8*pixel/2, 0, 8*pixel/2, 4*texturePixel, 4*texturePixel);
			tessellator.addVertexWithUV(8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 4*texturePixel);
			tessellator.addVertexWithUV(1-8*pixel/2, 0, 1-8*pixel/2, 12*texturePixel, 12*texturePixel);
		}
	}
	tessellator.draw();
}

Link to comment
Share on other sites

Are you sure that "test2.png" exists in your textures/model folder?

That's just a texture I used to check if the model was rendering correctly

I honestly do not see your problem. You have access to everything in the renderer, the Block, the World, the TileEntity. Wherever you have stored what the subtype should be, you just need to access it and then choose the appropriate texture.

I'll try to work a little more with it, and see if I can get it to work, even though I'm not sure how to do it.  If I can't get it to work, I'll post in here again.

Link to comment
Share on other sites

I can't get it to work, maybe it something in my block class, maybe someone could take a look? And maybe tell me what I should reference in my render class :)

public class BlockHedge extends BlockContainer
{
@SideOnly(Side.CLIENT)
private boolean field_150121_P;
protected int field_150127_b;
float pixel = 1F/16F;
public IIcon[][] texture = new IIcon[2][];

public static final String[][] HedgeTypes = new String[][] {{"leaves_oak", "leaves_spruce", "leaves_birch", "leaves_jungle", "leaves_acacia", "leaves_big_oak"}, {"leaves_oak_opaque", "leaves_spruce_opaque", "leaves_birch_opaque", "leaves_jungle_opaque", "leaves_acacia_opaque", "leaves_big_oak_opaque"}};

public static final String[] subBlocksHedges = new String[] {"oak", "spruce", "birch", "jungle", "acacia", "big_oak"};

public BlockHedge(Material mat)
{
	super(mat);
	this.setResistance(1);
	this.setHardness(0.2F);
	this.setCreativeTab(CreativeTabs.tabDecorations);
}

public int getRenderType()
{
	return -1;
}

public boolean isOpaqueCube()
{
	return false;
}

public boolean renderAsNormalBlock()
{
	return false;
}

public TileEntity createNewTileEntity(World world, int i)
{
	return new TileEntityHedge();

}

public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
	TileEntityHedge hedge = (TileEntityHedge)world.getTileEntity(x, y, z);

	if(hedge != null)
	{
		float minX = 4*pixel-(hedge.connections[1] != null?(4*pixel):0);
		float minZ = 4*pixel-(hedge.connections[2] != null?(4*pixel):0);
		float maxX = 1-4*pixel+(hedge.connections[0] != null?(4*pixel):0);
		float maxZ = 1-4*pixel+(hedge.connections[3] != null?(4*pixel):0);

		this.setBlockBounds(minX, 0, minZ, maxX, 1.5F, maxZ);
	}

		return AxisAlignedBB.getBoundingBox(x+this.minX, y+this.minY, z+this.minZ, x+this.maxX, y+this.maxY, z+this.maxZ);
}

public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
{
	TileEntityHedge hedge = (TileEntityHedge)world.getTileEntity(x, y, z);

	if(hedge != null)
	{
		float minX = 4*pixel-(hedge.connections[1] != null?(4*pixel):0);
		float minZ = 4*pixel-(hedge.connections[2] != null?(4*pixel):0);
		float maxX = 1-4*pixel+(hedge.connections[0] != null?(4*pixel):0);
		float maxZ = 1-4*pixel+(hedge.connections[3] != null?(4*pixel):0);

		this.setBlockBounds(minX, 0, minZ, maxX, 1, maxZ);
	}

		return AxisAlignedBB.getBoundingBox(x+this.minX, y+this.minY, z+this.minZ, x+this.maxX, y+this.maxY, z+this.maxZ);
}

@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
	for (int i = 0; i < HedgeTypes.length; ++i)
        {
            this.texture[i] = new IIcon[HedgeTypes[i].length];

            for (int j = 0; j < HedgeTypes[i].length; ++j)
            {
                this.texture[i][j] = iconRegister.registerIcon(HedgeTypes[i][j]);
            }
        }
}

@SideOnly(Side.CLIENT)
    public void setGraphicsLevel(boolean bool)
    {
        this.field_150121_P = bool;
        this.field_150127_b = bool ? 0 : 1;
    }

public boolean canPlaceTorchOnTop(World world, int x, int y, int z)
    {
	return false;
}

@SideOnly(Side.CLIENT)
    public void getSubBlocks(Item hedge, CreativeTabs creativeTabs, List list)
    {
	for(int i = 0 ; i < subBlocksHedges.length ; i++)
	{
		list.add(new ItemStack(hedge, 1, i));
	}
    }

@SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return meta == 1 ? this.texture[this.field_150127_b][1] : (meta == 3 ? this.texture[this.field_150127_b][3] : (meta == 2 ? this.texture[this.field_150127_b][2] : (meta == 5 ? this.texture[this.field_150127_b][5] : (meta == 4 ? this.texture[this.field_150127_b][4] : this.texture[this.field_150127_b][0]))));
    }

public int damageDropped(int meta)
{
	return meta;
}

@SideOnly(Side.CLIENT)
    public int getBlockColor()
    {
        double d0 = 0.5D;
        double d1 = 1.0D;
        return ColorizerFoliage.getFoliageColor(d0, d1);
    }

    @SideOnly(Side.CLIENT)
    public int getRenderColor(int meta)
    {
    	return meta == 1 ? ColorizerFoliage.getFoliageColorPine() : (meta == 2 ? ColorizerFoliage.getFoliageColorBirch() : ColorizerFoliage.getFoliageColorBasic());
    }
    
    @SideOnly(Side.CLIENT)
    public int colorMultiplier(IBlockAccess blockAccess, int x, int y, int z)
    {
        int l = 0;
        int i1 = 0;
        int j1 = 0;

        for (int k1 = -1; k1 <= 1; ++k1)
        {
            for (int l1 = -1; l1 <= 1; ++l1)
            {
                int i2 = blockAccess.getBiomeGenForCoords(x + l1, z + k1).getBiomeFoliageColor(x + l1, y, z + k1);
                l += (i2 & 16711680) >> 16;
                i1 += (i2 & 65280) >> 8;
                j1 += i2 & 255;
            }
        }
        
        int meta = blockAccess.getBlockMetadata(x, y, z);
        return meta == 1 ? ColorizerFoliage.getFoliageColorPine() : (meta == 2 ? ColorizerFoliage.getFoliageColorBirch() : (l / 9 & 255) << 16 | (i1 / 9 & 255) << 8 | j1 / 9 & 255);
    }
    
}

Link to comment
Share on other sites

I see a huge blob of copypasta code. Please explain what you are trying to achieve.

Well, I'm making a mod that adds some cosmetic hedges blocks, I was originally extending the blockwall class, but I felt like the wall model was out of place, and that's the reason why I decided to make a custom render model. I don't know if that was what you were after?

Link to comment
Share on other sites

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



×
×
  • Create New...

Important Information

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