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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • After uninstalling this mod, everything works! Thanks!
    • I had been playing on this fabric server for about a month with some friend and one day it just stopped starting, can anyone help me understand what the cause is? https://mclo.gs/2jop3r5    
    • The mobs are moving normally for a second, then freeze, then go back to normal, and this repeats. I describe this as mob lag, bc they stutter as if they were lagging. I don't have the best wifi, but that shouldn't matter since its 10mbps which is enough for a server. I have 8 gigs of ram for it, no optimizations have worked, if there is anything more you may need to help lmk, ill describe. The modlist is pretty hefty: VS_ClockworkSurvivalSupportV1.4 aether-1.20.1-1.2.0-neoforge.jar alexsdelight-1.5.jar alexsmobs-1.22.7.jar appleskin-forge-mc1.20.1-2.5.1.jar backpacked-forge-1.20.1-2.2.5.jar balm-forge-1.20.1-7.2.1.jar bettervillage-forge-1.20.1-3.2.0.jar BiomesOPlenty-1.20.1-18.0.0.598.jar botarium-forge-1.20.1-2.3.2.jar CGM-Unofficial-1.4.11+Forge+1.20.1.jar citadel-2.5.2-1.20.1.jar clockwork-1.20.1-0.1.2-forge-05f5d5fbbb.jar configured-forge-1.20.1-2.2.2.jar connectivity-1.20.1-4.9.jar create-1.20.1-0.5.1.f.jar create-new-age-forge-1.20.1-1.1.2.jar createarmoryv0.6.1n.jar createbigcannons-forge-1.20.1-0.5.3.b.jar createchunkloading-1.6.0-forge.jar createdeco-2.0.1-1.20.1-forge.jar createdieselgenerators-1.20.1-1.2h.jar createendertransmission-2.0.7-1.20.1.jar create_misc_and_things_ 1.20.1_4.0A.jar cristellib-1.1.5-forge.jar cupboard-1.20.1-2.3.jar curios-forge-5.7.0+1.20.1.jar destroy-1.20.1-0.8.jar Dungeon Crawl-1.20.1-2.3.14.jar FallingTree-1.20.1-4.3.4.jar FarmersDelight-1.20.1-1.2.4.jar framework-forge-1.20.1-0.6.26.jar geckolib-forge-1.20.1-4.4.2.jar InsaneLib-1.12.1-mc1.20.1.jar Jade-1.20.1-forge-11.8.0.jar jei-1.20.1-forge-15.3.0.4.jar journeymap-1.20.1-5.9.18-forge.jar JustEnoughResources-1.20.1-1.4.0.247.jar kotlinforforge-4.10.0-all.jar l2library-2.4.23.jar libraryferret-forge-1.20.1-4.0.0.jar macawsbridgesbop-1.20-1.1.jar mcw-bridges-2.1.0-mc1.20.4forge.jar moonlight-1.20-2.9.17-forge.jar morevillagers-forge-1.20.1-5.0.0.jar Mo_ZombiesWave-1.20.1-0.1.0-forge.jar NaturesCompass-1.20.1-1.11.2-forge.jar Placebo-1.20.1-8.6.1.jar refinedstorage-1.12.4.jar soundphysics-forge-1.20.1-1.1.2.jar spark-1.10.53-forge.jar stealing_villagers-forge-1.20.1-1.0.0.jar s_a_b-1.3.0_1.20.1.jar takesapillage-1.0.3-1.20.1.jar TerraBlender-forge-1.20.1-3.0.1.4.jar tombstone-1.20.1-8.6.2.jar Towns-and-Towers-1.12-Fabric+Forge.jar twilightforest-1.20.1-4.3.2145-universal.jar valkyrienskies-120-2.1.3-beta.1.jar veinmining-forge-1.3.0+1.20.1.jar waystones-forge-1.20-14.1.3.jar YungsApi-1.20-Forge-4.0.3.jar YungsBetterDesertTemples-1.20-Forge-3.0.3.jar YungsBetterDungeons-1.20-Forge-4.0.3.jar YungsBetterEndIsland-1.20-Forge-2.0.5.jar YungsBetterJungleTemples-1.20-Forge-2.0.4.jar YungsBetterMineshafts-1.20-Forge-4.0.4.jar YungsBetterNetherFortresses-1.20-Forge-2.0.5.jar YungsBetterOceanMonuments-1.20-Forge-3.0.4.jar YungsBetterStrongholds-1.20-Forge-4.0.3.jar YungsBetterWitchHuts-1.20-Forge-3.0.3.jar YungsBridges-1.20-Forge-4.0.3.jar zaynens_leather_from_rotten_flesh_mod_1.20.1.jar
    • Thank you so much! Unfortunately before reading this I reinstalled my java installer. Now when I try to open the forge installer I receive an error message stating 'Unable to install Java' even though I have definitely downloaded and installed the latest version. Any idea what this could be or how I could fix it?  
    • IT WORKED! THANK YOU!
  • Topics

×
×
  • Create New...

Important Information

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