Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi everyone,

 

I have created a gui with a custom inventory and container. I want to make it impossible for a player to drop items onto the ground while inside this gui. Anyone know how to achieve this?

  • Author

@Override
protected void keyTyped(char key, int event){
  
   if (event == 1 || event == this.mc.gameSettings.keyBindInventory.getKeyCode())
       {
           this.mc.thePlayer.closeScreen();
       }

       this.checkHotbarKeys(key);
   }

 

To disable the dropping of items from my gui inventory using the "Q" keyboard Key, I overrode the keyTyped method and changed it to the code above so that the "Q" key cannot be used to drop items. Still have no idea how to disable dropping items via mouse drag though. Any ideas are helpful

  • Author

For the mouse drag I tried the following - I created an imaginary barrier and using the draw method just reset the mouse mosition if it goes outside my guis bounds. However it isnt foolproof the player can still try and succeed at dropping the item by dragging the mouse fast. - need a better way to do this still

 

@Override
protected void drawGuiContainerBackgroundLayer(float x, int y, int z) {
	int mousePosX = Mouse.getEventX() * this.width / this.mc.displayWidth;
	int mousePosY = Mouse.getEventY() * this.height / this.mc.displayHeight;
	if(mousePosX < 140){
		Mouse.setCursorPosition(140 * this.mc.displayWidth/this.width, Mouse.getEventY());
	}
	if (mousePosX > 284){
		Mouse.setCursorPosition(284 * this.mc.displayWidth/this.width, Mouse.getEventY());
	}
	if(mousePosY < 58){
		Mouse.setCursorPosition(Mouse.getEventX(), 58 * this.mc.displayHeight/this.height);
	}
	if(mousePosY > 190){
		Mouse.setCursorPosition(Mouse.getEventX(), 190 * this.mc.displayHeight/this.height);
	}

//Rest of drawing code
}

 

  • Author

Hey everyone so this is the solution to this problem.

 

To disable the dropping of items via mouse drag you have to override the #mouseMovedOrUp() method (not the mouse clicked method) like so

 

 

  @Override
    protected void mouseMovedOrUp(int mousePosX, int mousePosY, int movedOrUp){
    	if(mousePosX < this.guiLeft || mousePosX > this.guiLeft + this.guiWidth{
    	   return;
    	} else if (mousePosY < this.guiTop || mousePosY > this.guiTop + this.guiHeight){
    	          return;
    		} else{
    				super.mouseMovedOrUp(mousePosX,mousePosY,movedOrUp);
    			}
    }

 

 

 

To disable the dropping of items via the "Q" Key (or whichever key this functionality gets bound to) use the following in your gui class

 

 

@Override
protected void keyTyped(char key, int event){
   	  
   if (event == 1 || event == this.mc.gameSettings.keyBindInventory.getKeyCode())
       {
           this.mc.thePlayer.closeScreen();
       }
       this.checkHotbarKeys(key);
   }

 

 

 

and it works :)

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.