Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10]GUI drawTexturedModalRect() bug or not working


Enginecrafter
 Share

Recommended Posts

I have a GuiScreen that shows a rectangle contained in texture file, but instedaded of showing rectangle it only shows a starange symblols like thaumcraft fonts.

 

Erroring GuiScreen:

package com.ec.screen;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.stream.ChatController;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Chat;

import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11;

import com.ec.handler.PacketMessage;
import com.ec.lib.MainLib;
import com.ec.lib.RefStrings;
import com.ec.tileentity.TileEntityPasswordLock;

public class PasswordChangeScreen extends GuiScreen{
int screenWidth = 196;
int screenHeight = 169;
public static int id = 2;

public static String enteredPassword = "";

public static World world;
public static int x;
public static int y;
public static int z;
public static EntityPlayer player;

public PasswordChangeScreen(World world, int x, int y, int z, EntityPlayer player)
{
	this.world = world;
	this.x = x;
	this.y = y;
	this.z = z;
	this.player = player;
}

@Override
public void drawScreen(int x, int y, float tick)
{
	int screenX = (width - screenWidth) / 2;
	int screenY = (height - screenHeight) / 2;

	GL11.glColor4f(1, 1, 1, 1);
	drawDefaultBackground();

	mc.renderEngine.bindTexture(new ResourceLocation(RefStrings.MODID, "textures/gui/PasswordGui.png"));
	drawTexturedModalRect(screenX, screenY, 0, 0, screenWidth, screenHeight);
	fontRendererObj.drawString(enteredPassword, screenX + 36, screenY + 11, 0);
	this.drawTexturedModalRect(screenX + 110, screenY + 11, 145, 171, 68, 20);

	super.drawScreen(x, y, tick);
}

@Override
public void initGui()
{
	int screenX = (width - screenWidth) / 2;
	int screenY = (height - screenHeight) / 2;

	buttonList.clear();
	GuiButton one;
	GuiButton two;
	GuiButton three;
	GuiButton four;
	GuiButton five;
	GuiButton six;
	GuiButton seven;
	GuiButton eight;
	GuiButton nine;
	GuiButton zero;
	GuiButton erase;
	GuiButton changePassword;
	GuiButton back;

	buttonList.add(one = new GuiButton(1, screenX + 25, screenY + 25, 10, 10, "1"));
	buttonList.add(two = new GuiButton(2, screenX + 45, screenY + 25, 10, 10, "2"));
	buttonList.add(three = new GuiButton(3, screenX + 65, screenY + 25, 10, 10, "3"));
	buttonList.add(four = new GuiButton(4, screenX + 25, screenY + 45, 10, 10, "4"));
	buttonList.add(five = new GuiButton(5, screenX + 45, screenY + 45, 10, 10, "5"));
	buttonList.add(six = new GuiButton(6, screenX + 65, screenY + 45, 10, 10, "6"));
	buttonList.add(seven = new GuiButton(7, screenX + 25, screenY + 65, 10, 10, "7"));
	buttonList.add(eight = new GuiButton(8, screenX + 45, screenY + 65, 10, 10, "8"));
	buttonList.add(nine = new GuiButton(9, screenX + 65, screenY + 65, 10, 10, "9"));
	buttonList.add(zero = new GuiButton(0, screenX + 45, screenY + 85, 10, 10, "0"));
	buttonList.add(erase = new GuiButton(10, screenX + 85, screenY + 45, 15, 20, "Clear"));
	buttonList.add(changePassword = new GuiButton(11, screenX + 125, screenY + 55, 20, 20, "Change password"));
	buttonList.add(back = new GuiButton(12, screenX + 125, screenY + 85, 20, 20, "Back"));
	super.initGui();
}

@Override
public void actionPerformed(GuiButton button)
{
	int screenX = (width - screenWidth) / 2;
	int screenY = (height - screenHeight) / 2;

	TileEntityPasswordLock tile = (TileEntityPasswordLock)world.getTileEntity(x, y, z);

	switch(button.id)
	{
	case 0:
		enteredPassword = enteredPassword + "0";
		break;
	case 1:
		enteredPassword = enteredPassword + "1";
		break;
	case 2:
		enteredPassword = enteredPassword + "2";
		break;
	case 3:
		enteredPassword = enteredPassword + "3";
		break;
	case 4:
		enteredPassword = enteredPassword + "4";
		break;
	case 5:
		enteredPassword = enteredPassword + "5";
		break;
	case 6:
		enteredPassword = enteredPassword + "6";
		break;
	case 7:
		enteredPassword = enteredPassword + "7";
		break;
	case 8:
		enteredPassword = enteredPassword + "8";
		break;
	case 9:
		enteredPassword = enteredPassword + "9";
		break;
	case 10:
		enteredPassword = "";
		break;
	case 11:
		if(enteredPassword.length() == 4)
		{
			MainLib.sendPacketToServer(new PacketMessage("changePassword", x, y, z, enteredPassword));
			mc.displayGuiScreen(null);
		}
		break;
	case 12:
		MainLib.openGui(player, PasswordLockScreen.id, world, x, y, z);
		break;
	default:
		break;
	}
}
}

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

GuiScreen#drawTexturedModalRect uses fixed rate for uv vs xy, so it wouldn't be useful as you think.

Instead, make your own method replacing that; Usually setting uv to 0~1 is appropriate.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

I used it this way:

x - where I want to draw it on screen X

y - where I want to draw it on screen Y

u - position of rectangle in texture - X

v - position of rectangle in texture - Y

width

height

 

And, what do 0~1 mean? Did you mean I have to make a mathod where u and v will be always 0 and 1?

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

And, what do 0~1 mean? Did you mean I have to make a mathod where u and v will be always 0 and 1?

 

He means from 0.0D to 1.0D, a floating point number.

You need to calculate the u and v appropriate to the texture resolution you use, that means, u-position on texture is 16px, v-position is 32px, your texture is 128x64px:

u = 16 / 128 = 0.125D

v = 32 / 64 = 0.5D

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

What do you mean?

How can I do it? Is this method correct or I didn't understood it correctly?

 

Code:

http://pastebin.com/947L7sEp

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

If you look at Gui#drawTexturedModalRect, it multiplies u and v by a static value, fitting a texture of size 256x256.

If you want to draw a texture with a different size, you need to copy this method and adjust it to fit your texture resolution.

If you do have a texture using this resolution, you're fine to use it, but be careful that in this case u and v are the exact pixel values.

 

But your problem seems to be a different one: You don't bind your texture anywhere when drawing your rectangle, to do so, you need to call

this.mc.getTextureManager().bindTexture(TEXTURE_RESOURCE_LOCATION);

before you draw your rectangle.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I binded my texture in MainLib.createScreenBase(some parameters)

http://pastebin.com/WgGJ3MRu

 

And, what is z-value?

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

1. Please do not create a new ResourceLocation instance every frame, use a static (final) field for it.

2. The z value (or correctly, the z-index) is the "layer" your texture draws on. It is recommended to use the field provided in your Gui instance.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

I created new basic gui to test this and it worked, but on the advanced gui(the original gui) isn't still working. They are both using the same gui texture.

 

My function to render rectangle contained in texture on gui

http://pastebin.com/WDhYeED2

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

... and where do you call your drawRect method (which is useless, since it's the exact copy of drawTexturedModalRect)?

 

A fundamental question: What do you want to achieve with your advanced GUI that is different from a basic one?

Also I suggest you setup a Github repo and host your mod code there so we can help you better.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

The advanced gui is "advanced", because it uses lot of buttons, sends packets and so on.

I want ot create something like password lock that when correct password is entered, changes block on location that is set using my item "remote manipulator" and the block sets remote block's metadata to 1. Once the remote receiver has metadata 1 it emits redstone signal.

And, I don't want to create GitHub because I must update it every time I post something.

 

And there I call the function:

@Override
public void drawScreen(int x, int y , float tick)
{
	int[] screenPos = MainLib.createScreenBase(new int[]{width, height, 194, 168}, this, res);
	MainLib.drawRectangle(new int[]{screenPos[0], screenPos[1], 0, 177, 68, 20}, this.zLevel);
	super.drawScreen(x, y, tick);
}

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

Link to comment
Share on other sites

Enginecrafter, the advantages of having your project in Git is that for instance you can develop your mod from everywhere where there is IDE and if your hard disk fails you will have not lost your project. I myself would be lost nowadays without Github repo.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Link to comment
Share on other sites

And, Have I to copy-paste all my code to GitHub?

Or there is a "simple way"?

Sorry, if you find mistaches in my posts.

I am not EN.

And when I post anything on Modder support, it means, I can't help myself and I need your help. And when you decide to delete my topic, just PM me with the reason, please.

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
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.

 Share



×
×
  • Create New...

Important Information

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