Jump to content

How to show Mouse in GUI


Schleim_time

Recommended Posts

i have created a gui that shows a picture ond a button to leave the GUI instead of ESC

Quote

@SideOnly(Side.CLIENT)
public class WastelandNewspaperGUI extends GuiScreen{

        public static ResourceLocation TEXTURES;
        private GuiButton ButtonClose;
        int year;

        public NewspaperGUI(int year) {
            TEXTURES = new ResourceLocation(reference.MOD_ID+ ":textures/gui/papers/newspaper"+year+".png");
            this.year=year;
        }
        
        @Override
        public void initGui() {
            Mouse.setGrabbed(true);
            buttonList.clear();
            this.buttonList.add(ButtonClose = new GuiButton(0, this.width / 2 - 100, this.height - (this.height / 4) + 10, "Close"));
            super.initGui();
        }
        
        @Override
        protected void actionPerformed(GuiButton button) throws IOException {
            if (button == ButtonClose) {
                mc.player.closeScreen();
            }
        }
        
        @Override
        public void drawScreen(int mouseX, int mouseY, float partialTicks) {
            try{
                this.drawDefaultBackground();
                this.mc.getTextureManager().bindTexture(TEXTURES);
                drawTexturedModalRect((width - 192) / 2, 50, 0, 0, 192, 192);
            } catch (NullPointerException e) {}
            super.drawScreen(mouseX, mouseY, partialTicks);
        }
        
        @Override
        public void handleMouseInput() throws IOException {
        Mouse.setGrabbed(true);
        super.handleMouseInput();
        }
    
        @Override
        public boolean doesGuiPauseGame() {
            return false;
        }
    
}

 

but i didnt found out how i let showup the cursor, somethink like setcursershown i need, i also tried from an  other poster Mouse.setgrabbed but that also does nothing

Link to comment
Share on other sites

5 hours ago, diesieben07 said:

The mouse is shown in GUIs by default, do not mess with mouse grabbing manually.

Show where you open the GUI.

@Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        if(!worldIn.isRemote) {
            BlockPos pos = playerIn.getPosition();
            Minecraft.getMinecraft().displayGuiScreen(new WastelandNewspaperGUI(number));
        }
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }

 

the number is only for the texture and that works fine

Link to comment
Share on other sites

Okay im also cunfused with my own text now. I created an working GUI with a container that shows up my mouse but it triggers in a other way :

 

playerIn.openGui(Main.instance, GUI_ENUM.GRINDBENCH.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ());

 

but i cant trigger my GUI without container like that

Link to comment
Share on other sites

i see the gray backround:

this.drawDefaultBackground();

and also my custom leave gui button

 

but i dont see the backround image from

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

drawTexturedModalRect((width - 192) / 2, height, 0, 0, 192, 192);

 

oh if the fuction is client side only means i dont need to test if worldisremote?

but to what client it will be sended i mean i dont give information about the client in this function

Edited by Schleim_time
want to add more information
Link to comment
Share on other sites

ok i found out if i remoe the if statement it also will not show me the backround image

 

if(!worldIn.isRemote) {
            Minecraft.getMinecraft().displayGuiScreen(new WastelandNewspaperGUI(number));
  }

with that it shows me all fine but expect the mouse, its also very wierd because its a client function executed server-side

Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Yes, this is known as "reachign across logical sides". It will crash on a server (NoSuchClassDefFoundError and friends) and in SP will cause strange behavior (random crashes, inexplicable behavior such as mouse cursor not showing and other weird bugs).

i added a try catch block because it sometimes crashed, i wanted to try an other method than this so i decided to use

playerIn.displayGui(); but i cant put my GUI inside, it needs an Interface but i never worked with interfaces, so i dont know what to fill in there, casting to interface didnt worked

 

Link to comment
Share on other sites

i readed now a lot about the proxy stuff but i cant really understand how to use it

 

@SidedProxy(clientSide = reference.CLIENT_PROXY_CLASS, serverSide = reference.COMMON_PROXY_CLASS)
public static commonproxy proxy;

 

im also using that proxy from my first touturials how to make mods but i dont know what the annontion exactly does, im wondering why this is the client proxy

 

public class clientproxy extends commonproxy {
    
    public void registerItemRenderer(Item item, int meta, String id) {
        ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), id));
    }
}

 

and the commonproxy is only an empty class.

 

i completly dont know how to call a class with a clientproxy because i dont know how to get the clientproxy the right way and how to use it the right way

   

Link to comment
Share on other sites

oh okay i tried a bit and i seems to understand them now, so the client proxy will execute code the commonproxy will not and both classes are defined by the annotion, so i added a void to the clientproxy calling my GUI

 

i called now the void in the proxy to open the GUI but now i have the old problem back, gray backround, button but no texture

 

@Override
        public void drawBackground(int tint) {
            this.mc.getTextureManager().bindTexture(TEXTURES);
            drawTexturedModalRect((width - 192) / 2, height, 0, 0, 192, 192);
            super.drawBackground(tint);
        }

Edited by Schleim_time
extra info
Link to comment
Share on other sites

package com.Schleimtime.Wasteland.items.newspaper;

import java.io.IOException;

import org.lwjgl.input.Mouse;

import com.Schleimtime.Wasteland.blocks.special.forgebench.Forgebenchcontainer;
import com.Schleimtime.Wasteland.blocks.special.forgebench.Forgetileentity;
import com.Schleimtime.Wasteland.util.reference;

import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class NewspaperGUI extends GuiScreen{

		public static ResourceLocation TEXTURES;
		private GuiButton ButtonClose;
		int year;
		int offy = 35;

		public NewspaperGUI(int year) {
			TEXTURES = new ResourceLocation(reference.MOD_ID+ ":textures/gui/papers/newspaper"+year+".png");
			this.year=year;
			if(year==3000) {
				offy = 17;
			}
		}
		
		@Override
		public void initGui() {
			buttonList.clear();
			this.buttonList.add(ButtonClose = new GuiButton(0, this.width / 2 - 100, this.height - (this.height / 4) + 10, "Close"));
			super.initGui();
		}
		
		@Override
	    protected void actionPerformed(GuiButton button) throws IOException {
	        if (button == ButtonClose) {
	            mc.player.closeScreen();
	        }
	    }
		
		@Override
		public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		    this.drawDefaultBackground();
	        super.drawScreen(mouseX, mouseY, partialTicks);
	    }
		
		@Override
		public void drawBackground(int tint) {
			this.mc.getTextureManager().bindTexture(TEXTURES);
	        drawTexturedModalRect((width - 192) / 2, height, 0, 0, 192, 192);
		}
	
		@Override
		public boolean doesGuiPauseGame() {
			return false;
		}
	
}

This is my GUI, i currently opening the GUI like that in the client proxy only :

 

public void openClientNewspaperGUI(int value) {
        Minecraft.getMinecraft().displayGuiScreen(new NewspaperGUI(value));
   }

 

Also my image is the size it needed, it also worked if i do this server side but than i have no mouse and thats not the good way

Edited by Schleim_time
Link to comment
Share on other sites

@Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        Main.proxy.openClientNewspaperGUI(data);
        return super.onItemRightClick(worldIn, playerIn, handIn);
    }
@Override
		public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		    this.drawDefaultBackground();
		    this.mc.getTextureManager().bindTexture(TEXTURES);
	        drawTexturedModalRect((width - 192) / 2, height, 0, 0, 192, 192);
	        super.drawScreen(mouseX, mouseY, partialTicks);
	    }

moved it all in one now but i only see the default gradient

 

and up os how i open it

Link to comment
Share on other sites

11 minutes ago, diesieben07 said:

And how do you call this method?

 

Your drawScreen method calls drawDefaultBackground, which will draw a gradient if you're "in game" (i.e. a world is loaded). It will only call drawBackground if you are not in game. You should just call drawBackground if you want that to be called.

omg im so sorry for wasting your time that much xD i accidentally switched the height variable with an other variable from my class so the modelrect was out of the screen oof now its working and thanks for explaining me the proxy

Link to comment
Share on other sites

1 hour ago, diesieben07 said:
1 hour ago, Schleim_time said:

@Override public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) { Main.proxy.openClientNewspaperGUI(data); return super.onItemRightClick(worldIn, playerIn, handIn); }

This is still reaching across logical sides.

You have to check if World#isRemote is true before calling your proxy.

Sorry, but could you explain why this is reaching across logical sides? I would've expected this to simply call an empty method on the server side, and open the GUI on the client side, based on the proxy.

Fancy 3D Graphing Calculator mod, with many different coordinate systems.

Lightweight 3D/2D position/vector transformations library, also with support for different coordinate systems.

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

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • BD303 merupakan salah satu situs slot mudah scatter paling populer dan digemari oleh kalangan slot online di tahun 2024 mainkan sekarang dengan kesempatan yang mudah menang jackpot jutaan rupiah.
  • Topics

×
×
  • Create New...

Important Information

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