Jump to content

How would you disable item drop when in gui


Thornack
 Share

Recommended Posts

@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

Link to comment
Share on other sites

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
}

 

Link to comment
Share on other sites

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

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 Terms of Use.