Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to show Mouse in GUI


Schleim_time
 Share

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

5 minutes ago, Schleim_time said:

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

That's not what client-only means. Client-only means the method does not exist on the server, at all. Your code will crash on a server with a NoSuchMethodError. This is why you use @SidedProxy (I'm guessing your on 1.12.2 still).

 

6 minutes ago, Schleim_time said:

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

Whatever client you run it on.

Link to comment
Share on other sites

2 minutes ago, Schleim_time said:

its also very wierd because its a client function executed server-side

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

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

4 hours ago, Schleim_time said:

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

   

A common proxy makes no sense. The idea of @SidedProxy is to perform different actions depending on the physical side (dedicated server / minecraft client).

I would recommend this setup:

  • An interface "Proxy" which defines all operations that can have different implementations based on side (e.g. "open this screen" does nothing on server but calls displayGuiScreen on client).
    Note that this interface must not reference any client-only or server-only classes.
    This interface is what you use as the type for your @SidedProxy field.
  • Two implementations (ClientProxy / ServerProxy) that implement the two behaviors for each method in the interface (they both implement the interface).
    These are what you reference inside the @SidedProxy annotation.

Now you can call the methods on your interface and the correct implementation will be used (that's what @SidedProxy does, it injects your field appropriately).

 

4 hours ago, Schleim_time said:

have the old problem back, gray backround, button but no texture 

Is your texture 256x256? Please post your complete GUI class.

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

4 minutes ago, Schleim_time said:

i currently opening the GUI like that in the client proxy only :

 

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

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.

  • Thanks 1
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

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

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.