Jump to content

Recommended Posts

Posted

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

Posted
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

Posted

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

Posted

oh ok i did it i changed it to world.isremote but now i can see my button and my mouse but no picture, i also have a question,

 

 Minecraft.getMinecraft().displayGuiScreen(new WastelandNewspaperGUI(number));

 

i dont specify a player to open that gui, whats happening if i play multiplayer?

Posted (edited)

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
Posted

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

Posted
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

 

Posted

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

   

Posted (edited)

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
Posted (edited)
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
Posted
@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

Posted
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

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

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



×
×
  • Create New...

Important Information

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