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

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.

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;
}

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.