Jump to content

[1.7.10]GUI drawTexturedModalRect() bug or not working


Enginecrafter

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • https://pastebin.com/VwpAW6PX My game crashes upon launch when trying to implement the Oculus mod to this mod compilation, above is the crash report, I do not know where to begin to attempt to fix this issue and require assistance.
    • This has been released asย 49.0.49.
    • https://youtube.com/shorts/gqLTSMymgUg?si=5QOeSvA4TTs-bL46
    • CubeHaven is a SMP server with unique features that can't be found on the majority of other servers! Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132 3 different stores: - CubeHaven Store: Our store to purchase using real money. - Bitcoin Store: Store for Bitcoin. Bitcoin can be earned from playing the server. Giving options for players if they want to spend real money or grind to obtain exclusive packages. - Black Market: A hidden store for trading that operates outside our traditional stores, like custom enchantments, exclusive items and more. Some of our features include: Rank Up: Progress through different ranks to unlock new privileges and perks. ๐Ÿ“ˆ Skills: RPG-style skill system that enhances your gaming experience! ๐ŸŽฎ Leaderboards: Compete and shine! Top players are rewarded weekly! ๐Ÿ† Random Teleporter: Travel instantly across different worlds with a click! ๐ŸŒ Custom World Generation: Beautifully generated world. ๐ŸŒ Dungeons: Explore challenging and rewarding dungeons filled with treasures and monsters. ๐Ÿฐ Kits: Unlock ranks and gain access to various kits. ๐Ÿ› ๏ธ Fishing Tournament: Compete in a friendly fishing tournament! ๐ŸŽฃ Chat Games: Enjoy games right within the chat! ๐ŸŽฒ Minions: Get some help from your loyal minions. ๐Ÿ‘ฅ Piรฑata Party: Enjoy a festive party with Piรฑatas! ๐ŸŽ‰ Quests: Over 1000 quests that you can complete! ๐Ÿ“œ Bounty Hunter: Set a bounty on a player's head. ๐Ÿ’ฐ Tags: Displayed on nametags, in the tab list, and in chat. ๐Ÿท๏ธ Coinflip: Bet with other players on coin toss outcomes, victory, or defeat! ๐ŸŸข Invisible & Glowing Frames: Hide your frames for a cleaner look or apply a glow to it for a beautiful look. ๐Ÿ”ฒโœจ[ Player Warp: Set your own warp points for other players to teleport to. ๐ŸŒŸ Display Shop: Create your own shop and sell to other players! ๐Ÿ›’ Item Skins: Customize your items with unique skins. ๐ŸŽจ Pets: Your cute loyal companion to follow you wherever you go! ๐Ÿพ Cosmetics: Enhance the look of your character with beautiful cosmetics! ๐Ÿ’„ XP-Bottle: Store your exp safely in a bottle for later use! ๐Ÿถ Chest & Inventory Sorting: Keep your items neatly sorted in your inventory or chest! ๐Ÿ“ฆ Glowing: Stand out from other players with a colorful glow! โœจ Player Particles: Over 100 unique particle effects to show off. ๐ŸŽ‡ Portable Inventories: Over virtual inventories with ease. ๐Ÿงณ And a lot more! Become part of our growing community today! Discord:ย https://cubehaven.net/discord Java: MC.CUBEHAVEN.NET Bedrock: MC.CUBEHAVEN.NET:19132
    • # Problematic frame: # C [libopenal.so+0x9fb4d] It is always the same issue - this refers to the Linux OS - so your system may prevent Java from working ย  I am not familiar with Linux - check for similar/related issues ย 
  • Topics

×
×
  • Create New...

Important Information

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