sep87x Posted May 24, 2014 Posted May 24, 2014 I need to get the stack out of the player's inventory container which is currently being hovered with the mouse. Basically, I have this code set up which checks for a keybinding and invokes onKeyPressed() when the button is pressed. (The KeyBindingWrapper is a utility class I wrote for myself, it's not available in Forge) new KeyBindingWrapper("key.forcefieldmod.inventory.assign", Keyboard.KEY_Z, "key.forcefieldmod.category") { @Override public void onKeyPressed() { GuiScreen currentGuiScreen = ForgeUtils.getMinecraft().currentScreen; if (currentGuiScreen instanceof GuiInventory) { GuiInventory inv = (GuiInventory) currentGuiScreen; // get ze stack } } }; What's the best way to accomplish this? I've looked through the inventory's GUI and container class, but I haven't found fields or methods which could be of any use yet. Quote
ShaneCraft Posted May 24, 2014 Posted May 24, 2014 In GuiContainer there is a method called: isMouseOverSlot which takes a slot and a 2d vector of your mouse position(x and y). But unfortunately that method is private. You could write your own method though. private Container _container; private ItemStack _itemStack; private Minecraft _mcClient; private int _height; private int _width; //constructor: public YOURCLASS(){ _container = null; _itemStack = null; _mcClient = FMLClientHandler.instance.getClient(); /* Somehow initialize _height and _width from the player's active guiscreen. _height = ? _width = ? */ } public ItemStack getItemStack(){ if(this._mcClient != null) { _container = this._mcClient.thePlayer.openContainer; int mouseX = Mouse.getEventX() * this.width / this.mc.displayWidth; int mouseY = this.height - Mouse.getEventY() * this.height / this.mc.displayHeight - 1; for (int i = 0; i < _container.inventorySlots.inventorySlots.size(); ++i){ Slot slot = (Slot)_container.inventorySlots.inventorySlots.get(i); if (this.isMouseOverSlot(slot, mouseX, mouseY, _width, _height) && slot.func_111238_b()){ return this._itemStack = slot.getItemStack(); } } } } public boolean isMouseOverSlot(Slot slot, int xCoord, int yCoord, int guiLeft, int guiTop){ int left = guiLeft; int top = guiTop; xCoord -= top; yCoord -= left; return xCoord >= slot.xDisplayPosition - 1 && xCoord < slot.xDisplayPosition + 16 + 1 && yCoord >= slot.yDisplayPosition - 1 && yCoord < slot.yDisplayPosition + 16 + 1; } Quote
sequituri Posted May 24, 2014 Posted May 24, 2014 You can use EntityPlayer.inventory.GetItemStack() and SetItemStack(stack) to access the picked up item. Quote -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
Recommended Posts
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.