public class RTexture{
private static final TextureManager manager = Minecraft.getMinecraft().getTextureManager();
private static final Tessellator tessellator = Tessellator.getInstance();
//магические числа, которые взял откуда-то из ванилы
private static final float f = 0.00390625F;
private float fu1, fu2, fv1, fv2;
public final ResourceLocation texture;
public float yHeight, xWidth;
public int xPos, yPos;
public int zIndex;
public RTexture(ResourceLocation texture) {
this.texture = texture;
}
public RTexture(String resPath) {
this.texture = new ResourceLocation(main.MOD_ID+":"+resPath);
}
public void draw(){ //принцип работы стырил от туда же
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
manager.bindTexture(texture);
BufferBuilder bufferbuilder = tessellator.getBuffer();
bufferbuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
bufferbuilder.pos(xPos, yHeight, zIndex).tex(fu1, fv1).endVertex();
bufferbuilder.pos(xWidth, yHeight, zIndex).tex(fu2, fv1).endVertex();
bufferbuilder.pos(xWidth, yPos, zIndex).tex(fu2, fv2).endVertex();
bufferbuilder.pos(xPos, yPos, zIndex).tex(fu1, fv2).endVertex();
tessellator.draw();
}
//это у меня вызывается во время обновления gui, откуда основу стырил - сам знаешь
public RTexture update(int xPos, int yPos, int zIndex, int shiftTextureX, int shiftTextureY, int width, int height){
this.xPos = xPos;
this.yPos = yPos;
this.zIndex = zIndex;
fu1 = (float)(shiftTextureX) * f;
fu2 = (float)(shiftTextureX + width) * f;
fv1 = (float)(shiftTextureY + height) * f;
fv2 = (float)(shiftTextureY) * f;
yHeight = this.yPos + height;
xWidth = this.xPos + width;
return this;
}
}