Jump to content

[1.7.10] drawTexturedModalRect problems and questions?


Elix_x

Recommended Posts

First of all, my gui uses more then 256*256 texture, so i needed to rewrite drawTexturedModalRect().

It's done, but now i'm having a lot of problems:

None of methods are not working properly to draw texture above old place (ex: burning progress in furnace, etc), because

1) i don't unedrstand properly what does x, y, u, v, width, height means and i can't figure it out.

2) i have too big texture

Also i found that if change screen size of mc, position and square changes...? I'm not sure if it must happen.

Modified drawTexturedModalRect:

public void drawTexturedModalRect(int x, int y, int u, int v, int width, int height, int textureWidth, int textureHeight)
{
	float f = 1F / (float)textureWidth;
	float f1 = 1F / (float)textureHeight;
	Tessellator tessellator = Tessellator.instance;
	tessellator.startDrawingQuads();
	tessellator.addVertexWithUV((double)(x), (double)(y + height), 0, (double)((float)(u) * f), (double)((float)(v + height) * f1));
	tessellator.addVertexWithUV((double)(x + width), (double)(y + height), 0, (double)((float)(u + width) * f), (double)((float)(v + height) * f1));
	tessellator.addVertexWithUV((double)(x + width), (double)(y), 0, (double)((float)(u + width) * f), (double)((float)(v) * f1));
	tessellator.addVertexWithUV((double)(x), (double)(y), 0, (double)((float)(u) * f), (double)((float)(v) * f1));
	tessellator.draw();
}

and it calling code in drawGuiContainerBackgroundLayer

drawTexturedModalRect(guiLeft + 154, guiTop + 83, 13, 13, guiLeft + 248, guiTop + 0, 288, 288);

My texture:

03BajQT.png

Help me please!

Link to comment
Share on other sites

You might want to rework that texture to fit into 256x256, like this:

VRsEqgD.png

 

You will need to draw it in 2 parts, but power-of-two textures (256 = 28) are more efficient in graphics cards (and older cards only support those kinds of textures).

Thanks! I know that i can fit in 256*256, but gui it self draws fine, like expected (drawTexturedModalRect(guiLeft, guiTop, 0, 0, 247, 248, 288, 288); )

 

EDIT: i think i figured it out:

drawTexturedModalRect(x, y, u, v, width, height);

x and y being coordinates of top left corner of place to place image. Must always begin with guiLeft + and guiTop +

u and v being place of top left corner of image to take. MUST NEVER USE guiLeft and guiTop

width and height being size of image to draw...

Pretty simple. FAIL.

 

Link to comment
Share on other sites

Ok. Now i have another problem:

TileEntity isn't get properly for GUIand with wrong data:

GUI:

public GUIToolsCompressor(InventoryPlayer inventory, TileEntityToolsCompressor tileentity) {
	super(new ContainerToolsCompressor(inventory, tileentity));
	toolsCompressor = tileentity;
	System.out.println(toolsCompressor + " " + toolsCompressor.isWorking());
	this.xSize = 247;
	this.ySize = 248;
}

onBlockActivated:

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ){
	if(world.isRemote){
		return true;
	} else if(!player.isSneaking()) {
		TileEntityToolsCompressor te = (TileEntityToolsCompressor) world.getTileEntity(x, y, z);
		System.out.println(te + " " + te.isWorking());
		if(te != null){
			FMLNetworkHandler.openGui(player, MainToolsCompressor.instance, MainToolsCompressor.guiIdToolsCompressor, world, x, y, z);
		}

		return true;
	} else {
		return false;
	}
}

Console:

[16:20:05] [server thread/INFO] [sTDOUT]: [code.elix_x.mods.toolscompressor.blocks.ToolsCompressor:onBlockActivated:61]: code.elix_x.mods.toolscompressor.blocks.TileEntityToolsCompressor@43c0a9cb true
[16:20:05] [Client thread/INFO] [sTDOUT]: [code.elix_x.mods.toolscompressor.gui.GUIToolsCompressor:<init>:24]: code.elix_x.mods.toolscompressor.blocks.TileEntityToolsCompressor@75f2a654 false

Why tile entity's data is different in gui???

 

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.