Jump to content

Recommended Posts

Posted

I'm trying to draw tabs, I have it set up so that when I click a certain area a boolean becomes true and then I'm based on the state of the boolean trying to draw a rectangle so it appears as if the the tab has been select

 

 

method for drawing the tabs:

 

public void drawSelectedTab(){
	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;





	int tabOU;

	if(tabOfficial){
		tabOU = 237;
	}
	else{
		tabOU = 233;
	}

	//tab Official
	drawTexturedModalRect(guiX + 203, guiY + 3,              tabOU, 15,             3, 22);


	int tabCU;
	if(tabCommunity){
		tabCU = 237;
	}
	else{
		tabCU = 233;
	}
	//tab Community
	drawTexturedModalRect(guiX + 203, guiY + 27,             tabCU, 15,             3, 22);

	int tabFU;
	if(tabFavorites){
		tabFU = 237;
	}
	else{
		tabFU = 233;
	}
	//tab Favorites
	drawTexturedModalRect(guiX + 203, guiY + 51,             tabFU, 15,             3, 22);	



}

 

and heres the part that determines which tab has been selected

@Override
protected void mouseClicked(int x, int y, int mouseButton) throws IOException {

	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;


	//tab Official
	if(trueZone(guiX + 205, guiY + 3, 19, 22, x, y)){

		tabOfficial = true;
		tabCommunity = false;
		tabFavorites = false;

		if(tabOfficial){
			System.out.println("Clicked tab Official");
		}
	}//tab Official

	//tab Community
	if(trueZone(guiX + 205, guiY + 27, 19, 22, x, y)){

		tabOfficial = false;
		tabCommunity = true;
		tabFavorites = false;

		if(tabCommunity){
			System.out.println("Clicked tab Community");
		}			
	}//tab Community	

	//tab Favorites
	if(trueZone(guiX + 205, guiY + 51, 19, 22, x, y)){

		tabOfficial = false;
		tabCommunity = false;
		tabFavorites = true;

		if(tabFavorites){
			System.out.println("Clicked tab Favorites");
		}
	}//tab Favorites

 

Heres the entire class:

package com.neg2013.main;

import java.io.IOException;
import java.util.List;

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

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;

public class GuiServerPicker extends GuiScreen{

int buttonWidth = 194;
int buttonHeight = 21;

int tabWidth = 19;
int tabHeight = 22;

int guiWidth = 225;
int guiHeight = 154;

boolean clicked1 = false;
boolean clicked2 = false;
boolean clicked3 = false;
boolean clicked4 = false;
boolean clicked5 = false;
boolean clicked6 = false;

boolean tabOfficial = true;
boolean tabCommunity = false;
boolean tabFavorites = false;

int id = 0;
GuiButton menuButton;

//int serverV = 207;
int ServersOnPage = 5;

@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;

	mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
	GL11.glColor4f(1, 1, 1, 1);
	drawTexturedModalRect(guiX, guiY, 0, 0, guiWidth, guiHeight);

	serverButtons("NEG2013", "Is", "The", "God", "Of", "Sexiness", ServersOnPage);
	drawSelectedTab();











	super.drawScreen(mouseX, mouseY, partialTicks);

}//drawScreen

	//ADD THE PLAYER COUNT	

public void serverButtons(String name1, String name2, String name3, String name4, String name5, String name6, int ServersOnPage){
	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;

	int color = 0X000000;



	if(ServersOnPage < 1){
		return;
	}
	//server 1
		int i = 0;
		int serverV;

		if(clicked1){
			serverV = 229;
		}
		else{
			serverV = 207;
		}

		fontRendererObj.drawString( name1, guiX + 8 , guiY + 10 + (25 * i), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i), 1, serverV, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name1, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i), color);
			//server 1 end


	if(ServersOnPage < 2){
		return;
	}
	//server 2
		int i1 = 1;
		int server1V;

		if(clicked2){
			server1V = 229;
		}
		else{
			server1V = 207;
		}

		fontRendererObj.drawString( name2, guiX + 8 , guiY + 10 + (25 * i1), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i1), 1, server1V, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name2, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i1), color);
			//server 3 end

	if(ServersOnPage < 3){
		return;
	}
	//server 3
		int i2 = 2;
		int server2V;

		if(clicked3){
			server2V = 229;
		}
		else{
			server2V = 207;
		}

		fontRendererObj.drawString( name3, guiX + 8 , guiY + 10 + (25 * i2), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i2), 1, server2V, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name3, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i2), color);
			//server 3 end

	if(ServersOnPage < 4){
		return;
	}
	//server 4
		int i3 = 3;
		int server3V;

		if(clicked4){
			server3V = 229;
		}
		else{
			server3V = 207;
		}

		fontRendererObj.drawString( name4, guiX + 8 , guiY + 10 + (25 * i3), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i3), 1, server3V, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name4, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i3), color);
			//server 4 end

	if(ServersOnPage < 5){
		return;
	}
	//server 5
		int i4 = 4;
		int server4V;

		if(clicked5){
			server4V = 229;
		}
		else{
			server4V = 207;
		}

		fontRendererObj.drawString( name5, guiX + 8 , guiY + 10 + (25 * i4), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i4), 1, server4V, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name5, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i4), color);
			//server 5 end

	if(ServersOnPage < 6){
		return;
	}
	//server 6
		int i5 = 5;
		int server5V;

		if(clicked6){
			server5V = 229;
		}
		else{
			server5V = 207;
		}

		fontRendererObj.drawString( name6, guiX + 8 , guiY + 10 + (25 * i5), color);
		mc.renderEngine.bindTexture(new ResourceLocation(Reference.MODID, "textures/gui/gui.png"));
		GL11.glColor4f(1, 1, 1, 1);	
		drawTexturedModalRect(guiX + 4 , guiY + 4 + (25 * i5), 1, server5V, buttonWidth, buttonHeight);
		fontRendererObj.drawString( name6, guiX + 4 + 4 , guiY + 4 + 6 + (25 * i5), color);
			//server 6 end
			if(ServersOnPage > 6){
				return;
			}


}//serverButtons

/*if(tabOfficial){
				//tab1
				drawTexturedModalRect(guiX + 203, guiY + 3,              237, 15,             3, 22);

				//tab2
				drawTexturedModalRect(guiX + 203, guiY + 27,             233, 15,             3, 22);

				//tab3
				drawTexturedModalRect(guiX + 203, guiY + 51,             233, 15,             3, 22);

			}//tabO

			if(tabCommunity){
				//tab1
				drawTexturedModalRect(guiX + 203, guiY + 3,              233, 15,             3, 22);

				//tab2
				drawTexturedModalRect(guiX + 203, guiY + 27,             237, 15,            3, 22);

				//tab3
				drawTexturedModalRect(guiX + 203, guiY + 51,             233, 15,             3, 22);

			}//tabC

			if(tabFavorites){
				//tab1
				drawTexturedModalRect(guiX + 203, guiY + 3,              233, 15,            3, 22);

				//tab2
				drawTexturedModalRect(guiX + 203, guiY + 27,             233, 15,             3, 22);

				//tab3
				drawTexturedModalRect(guiX + 203, guiY + 51,             237, 15,             3, 22);

			}//tabF*/

public void connectToServers(){

	//server 1

	if(clicked1){

	}

	//server 2
	if(clicked1){

	}

	//server 3
	if(clicked1){

	}

	//server 4
	if(clicked1){

	}//server 5

	if(clicked1){

	}

	//server 6
	if(clicked1){

	}

}//connectToServers



public void drawSelectedTab(){
	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;





	int tabOU;

	if(tabOfficial){
		tabOU = 237;
	}
	else{
		tabOU = 233;
	}

	//tab Official
	drawTexturedModalRect(guiX + 203, guiY + 3,              tabOU, 15,             3, 22);


	int tabCU;
	if(tabCommunity){
		tabCU = 237;
	}
	else{
		tabCU = 233;
	}
	//tab Community
	drawTexturedModalRect(guiX + 203, guiY + 27,             tabCU, 15,             3, 22);

	int tabFU;
	if(tabFavorites){
		tabFU = 237;
	}
	else{
		tabFU = 233;
	}
	//tab Favorites
	drawTexturedModalRect(guiX + 203, guiY + 51,             tabFU, 15,             3, 22);	



}
	public boolean trueZone(int OffsX, int OffsY, int Width, int Height, int MouseX, int MouseY){
	if(OffsX <= MouseX && MouseX <= OffsX + Width && OffsY <= MouseY && MouseY <= OffsY + Height ){
		return true;
	}
	else{
		return false;	
	}


}
@Override
protected void mouseClicked(int x, int y, int mouseButton) throws IOException {

	int guiX = (width - guiWidth) / 2;
	int guiY = (height - guiHeight) / 2;


	//tab Official
	if(trueZone(guiX + 205, guiY + 3, 19, 22, x, y)){

		tabOfficial = true;
		tabCommunity = false;
		tabFavorites = false;

		if(tabOfficial){
			System.out.println("Clicked tab Official");
		}
	}//tab Official

	//tab Community
	if(trueZone(guiX + 205, guiY + 27, 19, 22, x, y)){

		tabOfficial = false;
		tabCommunity = true;
		tabFavorites = false;

		if(tabCommunity){
			System.out.println("Clicked tab Community");
		}			
	}//tab Community	

	//tab Favorites
	if(trueZone(guiX + 205, guiY + 51, 19, 22, x, y)){

		tabOfficial = false;
		tabCommunity = false;
		tabFavorites = true;

		if(tabFavorites){
			System.out.println("Clicked tab Favorites");
		}
	}//tab Favorites




	if(ServersOnPage < 1){
		return;
	}
	//server1
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0 <= y && y <= guiY + 0 + buttonHeight ){
		System.out.println("Clicked Server 1");
		clicked1 = true;
		clicked2 = false;
		clicked3 = false;
		clicked4 = false;
		clicked5 = false;
		clicked6 = false;
	}
	if(ServersOnPage < 2){
		return;
	}
	//server2
	int i1 = 1;
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0  + (25 * i1) <= y && y <= guiY + 0  + (25 * i1) + buttonHeight ){
		System.out.println("Clicked Server 2");
		clicked1 = false;
		clicked2 = true;
		clicked3 = false;
		clicked4 = false;
		clicked5 = false;
		clicked6 = false;
	}
	if(ServersOnPage < 3){
		return;
	}
	//server3
	int i2 = 2;
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0  + (25 * i2) <= y && y <= guiY + 0  + (25 * i2) + buttonHeight ){
		System.out.println("Clicked Server 3");
		clicked1 = false;
		clicked2 = false;
		clicked3 = true;
		clicked4 = false;
		clicked5 = false;
		clicked6 = false;
	}
	if(ServersOnPage < 4){
		return;
	}
	//server4
	int i3 = 3;
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0  + (25 * i3)<= y && y <= guiY + 0 + (25 * i3) + buttonHeight ){
		System.out.println("Clicked Server 4");
		clicked1 = false;
		clicked2 = false;
		clicked3 = false;
		clicked4 = true;
		clicked5 = false;
		clicked6 = false;
	}
	if(ServersOnPage < 5){
		return;
	}
	//server5
	int i4 = 4;
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0 + (25 * i4) <= y && y <= guiY + 0 + (25 * i4) + buttonHeight ){
		System.out.println("Clicked Server 5");
		clicked1 = false;
		clicked2 = false;
		clicked3 = false;
		clicked4 = false;
		clicked5 = true;
		clicked6 = false;
	}
	if(ServersOnPage < 6){
		return;
	}
	//server6
	int i5 = 5;
	if(guiX + 0 <= x && x <= guiX + 0 + buttonWidth && guiY + 0 + (25 * i5) <= y && y <= guiY + 0 + (25 * i5) + buttonHeight ){
		System.out.println("Clicked Server 6");
		clicked1 = false;
		clicked2 = false;
		clicked3 = false;
		clicked4 = false;
		clicked5 = false;
		clicked6 = true;
	}


	super.mouseClicked(x, y, mouseButton);}//mouseclicked
@Override
protected void actionPerformed(GuiButton button) throws IOException {

	switch(button.id){

	case 666:

		Minecraft.getMinecraft().displayGuiScreen(new GuiServerPicker());

	break;

	}

	super.actionPerformed(button);}	
@Override
public void initGui() {
	buttonList.clear();
	buttonList.add(menuButton = new GuiButton(666, 0, 0, "NEG2013"));


	super.initGui();
}	
@Override
protected void keyTyped(char c, int key) throws IOException {

	switch(key){
	case Keyboard.KEY_E:
		Minecraft.getMinecraft().displayGuiScreen(null);
	break;




	}//switch

	super.keyTyped(c, key);
}//keyTyped	
@Override
public boolean doesGuiPauseGame() {
	return false;
}//doesGuiPauseGame
}//class


 

 

 

If you want to see anything else please just ask.

 

 

Posted

I already have it print out when there clicked and become truelike this

 

if(tabCommunity){

System.out.println("Clicked tab Community");

}

Posted

Don't use the default button I was saying use the default button "system". Make a class that extends GuiButton(which is where all the button rendering code is). Override the drawButton method and put your rendering code in there. And there is a method in GuiButton that checks if it is hovering over or not.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Interesting. I didn't know that. Did you want it to change size when you clicked it? Have you tried increasing the size it increases when you click it just to make sure that it is visible or not?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

Well if it worked before there are inconsistencies. And I would just switch over to the Vanilla GuiButton system it is much cleaner code. But why do you want to change the size when you click the button if the screen is going to change it won't render. Maybe you wanted it to render when it was being hovered over?

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I couldn't tell you why and yeah it has been a while since I have used drawTextureModelRect I forgot the parameters. Once you have switch over it should be much easier to pinpoint the problem.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Guest
This topic is now closed to further replies.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
    • It was working perfectly fine last night but now I'm getting an exit code -1 with the textbox: The game crashed: rendering overlay Error: net.minecraftforge.fml.ModLoadingException: Supplementaries (supplementaries) encountered an error during the done event phase Here's the crash log: https://pastebin.com/KmesArYS Any help is apricated
    • Link to Crashlog: https://pastebin.com/bKqH9fx2 Trying to set up a custom mod pack, was going smoothly up until recently as the WorldLoader screen, (the one that appears when you select "create new world" in Singleplayer), was clicked to test that it was running fine. Most Recent Few mods added were; - Create (+ its addons) - Immersive Weathering [Forge] I've tried all I could think of since loading up the game worked fine and I've never had this issue before.  Any help is appreciated.  
  • Topics

×
×
  • Create New...

Important Information

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