Posted July 3, 20169 yr 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?
July 4, 20169 yr 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
July 4, 20169 yr 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 }
July 5, 20169 yr 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.