Introduce DrawingUtils to centralise GUI rendering utility methods
This commit is contained in:
@@ -27,7 +27,6 @@ import electroblob.wizardry.registry.WizardryPotions;
|
||||
import electroblob.wizardry.spell.MindControl;
|
||||
import electroblob.wizardry.spell.Spell;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -68,7 +67,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
* <p>
|
||||
* - In-world utilities (position calculating, retrieving entities, etc.)<br>
|
||||
* - Raytracing<br>
|
||||
* - Drawing utilities (client-only)<br>
|
||||
* - NBT and data storage utilities<br>
|
||||
* - Interaction with the ally designation system<br>
|
||||
* - Loot and weighting utilities
|
||||
@@ -684,82 +682,6 @@ public final class WizardryUtilities {
|
||||
return result;
|
||||
}
|
||||
|
||||
// SECTION Rendering and GUIs
|
||||
// ===============================================================================================================
|
||||
|
||||
// Doesn't seem right to put this in the proxies since it should only ever be called from client-side code, and I'm
|
||||
// not about to make a whole separate utilities class just for one method. Fully qualified names it is!
|
||||
/**
|
||||
* <b>[Client-side only]</b> Draws a textured rectangle, taking the size of the image and the bit needed into
|
||||
* account, unlike {@link net.minecraft.client.gui.Gui#drawTexturedModalRect(int, int, int, int, int, int)
|
||||
* Gui.drawTexturedModalRect(int, int, int, int, int, int)}, which is harcoded for only 256x256 textures. Also handy
|
||||
* for custom potion icons.
|
||||
*
|
||||
* @param x The x position of the rectangle
|
||||
* @param y The y position of the rectangle
|
||||
* @param u The x position of the top left corner of the section of the image wanted
|
||||
* @param v The y position of the top left corner of the section of the image wanted
|
||||
* @param width The width of the section
|
||||
* @param height The height of the section
|
||||
* @param textureWidth The width of the actual image.
|
||||
* @param textureHeight The height of the actual image.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void drawTexturedRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight){
|
||||
drawTexturedFlippedRect(x, y, u, v, width, height, textureWidth, textureHeight, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>[Client-side only]</b> Draws a textured rectangle, taking the size of the image and the bit needed into
|
||||
* account, unlike {@link net.minecraft.client.gui.Gui#drawTexturedModalRect(int, int, int, int, int, int)
|
||||
* Gui.drawTexturedModalRect(int, int, int, int, int, int)}, which is harcoded for only 256x256 textures. Also handy
|
||||
* for custom potion icons. This version allows the texture to be flipped in x and/or y.
|
||||
*
|
||||
* @param x The x position of the rectangle
|
||||
* @param y The y position of the rectangle
|
||||
* @param u The x position of the top left corner of the section of the image wanted
|
||||
* @param v The y position of the top left corner of the section of the image wanted
|
||||
* @param width The width of the section
|
||||
* @param height The height of the section
|
||||
* @param textureWidth The width of the actual image.
|
||||
* @param textureHeight The height of the actual image.
|
||||
* @param flipX Whether to flip the texture in the x direction.
|
||||
* @param flipY Whether to flip the texture in the y direction.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void drawTexturedFlippedRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight, boolean flipX, boolean flipY){
|
||||
|
||||
float f = 1F / (float)textureWidth;
|
||||
float f1 = 1F / (float)textureHeight;
|
||||
|
||||
int u1 = flipX ? u + width : u;
|
||||
int u2 = flipX ? u : u + width;
|
||||
int v1 = flipY ? v + height : v;
|
||||
int v2 = flipY ? v : v + height;
|
||||
|
||||
// Essentially the same as getting the tessellator. For most code, you'll want the tessellator AND the
|
||||
// vertexbuffer stored in local variables.
|
||||
BufferBuilder buffer = net.minecraft.client.renderer.Tessellator.getInstance().getBuffer();
|
||||
// Equivalent of tessellator.startDrawingQuads()
|
||||
buffer.begin(org.lwjgl.opengl.GL11.GL_QUADS, net.minecraft.client.renderer.vertex.DefaultVertexFormats.POSITION_TEX);
|
||||
// Equivalent of tessellator.addVertex()
|
||||
buffer.pos((double)(x), (double)(y + height), 0).tex((double)((float)(u1) * f), (double)((float)(v2) * f1)).endVertex();
|
||||
buffer.pos((double)(x + width), (double)(y + height), 0).tex((double)((float)(u2) * f), (double)((float)(v2) * f1)).endVertex();
|
||||
buffer.pos((double)(x + width), (double)(y), 0).tex((double)((float)(u2) * f), (double)((float)(v1) * f1)).endVertex();
|
||||
buffer.pos((double)(x), (double)(y), 0).tex((double)((float)(u1) * f), (double)((float)(v1) * f1)).endVertex();
|
||||
// Exactly the same as before.
|
||||
net.minecraft.client.renderer.Tessellator.getInstance().draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand for {@link WizardryUtilities#drawTexturedRect(int, int, int, int, int, int, int, int)} which draws the
|
||||
* entire texture (u and v are set to 0 and textureWidth and textureHeight are the same as width and height).
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void drawTexturedRect(int x, int y, int width, int height){
|
||||
drawTexturedRect(x, y, 0, 0, width, height, width, height);
|
||||
}
|
||||
|
||||
// SECTION NBT and Data Storage
|
||||
// ===============================================================================================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user