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

    • i notice a change if i add the min and max ram in the line like this for example:    # Xmx and Xms set the maximum and minimum RAM usage, respectively. # They can take any number, followed by an M or a G. # M means Megabyte, G means Gigabyte. # For example, to set the maximum to 3GB: -Xmx3G # To set the minimum to 2.5GB: -Xms2500M # A good default for a modded server is 4GB. # Uncomment the next line to set it. -Xmx10240M -Xms8192M    i need to make more experiments but for now this apparently works.
    • Selamat datang di OLXTOTO, situs slot gacor terpanas yang sedang booming di industri perjudian online. Jika Anda mencari pengalaman bermain yang luar biasa, maka OLXTOTO adalah tempat yang tepat untuk Anda. Dapatkan sensasi tidak biasa dengan variasi slot online terlengkap dan peluang memenangkan jackpot slot maxwin yang sering. Di sini, Anda akan merasakan keseruan yang luar biasa dalam bermain judi slot. DAFTAR OLXTOTO DISINI LOGIN OLXTOTO DISINI AKUN PRO OLXTOTO DISINI   Slot Gacor untuk Sensasi Bermain Maksimal Olahraga cepat dan seru dengan slot gacor di OLXTOTO. Rasakan sensasi bermain maksimal dengan mesin slot yang memberikan kemenangan beruntun. Temukan keberuntungan Anda di antara berbagai pilihan slot gacor yang tersedia dan rasakan kegembiraan bermain judi slot yang tak terlupakan. Situs Slot Terpercaya dengan Pilihan Terlengkap OLXTOTO adalah situs slot terpercaya yang menawarkan pilihan terlengkap dalam perjudian online. Nikmati berbagai genre dan tema slot online yang menarik, dari slot klasik hingga slot video yang inovatif. Dipercaya oleh jutaan pemain, OLXTOTO memberikan pengalaman bermain yang aman dan terjamin.   Jackpot Slot Maxwin Sering Untuk Peluang Besar Di OLXTOTO, kami tidak hanya memberikan hadiah slot biasa, tapi juga memberikan kesempatan kepada pemain untuk memenangkan jackpot slot maxwin yang sering. Dengan demikian, Anda dapat meraih keberuntungan besar dan memenangkan ribuan rupiah sebagai hadiah jackpot slot maxwin kami. Jackpot slot maxwin merupakan peluang besar bagi para pemain judi slot untuk meraih keuntungan yang lebih besar. Dalam permainan kami, Anda tidak harus terpaku pada kemenangan biasa saja. Kami hadir dengan jackpot slot maxwin yang sering, sehingga Anda memiliki peluang yang lebih besar untuk meraih kemenangan besar dengan hadiah yang menggiurkan. Dalam permainan judi slot, pengalaman bermain bukan hanya tentang keseruan dan hiburan semata. Kami memahami bahwa para pemain juga menginginkan kesempatan untuk meraih keberuntungan besar. Oleh karena itu, OLXTOTO hadir dengan jackpot slot maxwin yang sering untuk memberikan peluang besar kepada para pemain kami. Peluang Besar Menang Jackpot Slot Maxwin Peluang menang jackpot slot maxwin di OLXTOTO sangatlah besar. Anda tidak perlu khawatir tentang batasan atau pembatasan dalam meraih jackpot tersebut. Kami ingin memberikan kesempatan kepada semua pemain kami untuk merasakan sensasi menang dalam jumlah yang luar biasa. Jackpot slot maxwin kami dibuka untuk semua pemain judi slot di OLXTOTO. Anda memiliki peluang yang sama dengan pemain lainnya untuk memenangkan hadiah jackpot yang besar. Kami percaya bahwa semua orang memiliki kesempatan untuk meraih keberuntungan besar, dan itulah mengapa kami menyediakan jackpot slot maxwin yang sering untuk memenuhi harapan dan keinginan Anda.  
    • LOGIN DAN DAFTAR DISINI SEKARANG !!!! Blacktogel adalah situs judi slot online yang menjadi pilihan banyak penggemar judi slot gacor di Indonesia. Dengan platform yang sangat user-friendly dan berbagai macam permainan slot yang tersedia, Blacktogel menjadi tempat yang tepat untuk penggemar judi slot online. Dalam artikel ini, kami akan membahas tentang Blacktogel dan keunggulan situs slot gacor online yang disediakan.  
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
    • Situs bandar slot online Gacor dengan bonus terbesar saat ini sedang menjadi sorotan para pemain judi online. Dengan persaingan yang semakin ketat dalam industri perjudian online, pemain mencari situs yang tidak hanya menawarkan permainan slot yang gacor (sering memberikan kemenangan), tetapi juga bonus terbesar yang bisa meningkatkan peluang menang. Daftar disini : https://gesit.io/googlegopek
  • Topics

×
×
  • Create New...

Important Information

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