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

Greetings!

 

 

I've tried to make a GUI with slots that has a comparable functionality as the creative inventory screen.

I know how to work with slots, and my TileEntity extends IInventory. I placed prints in each of the methods, but no method is executed when I click on a slot which contains the same item as you're holding with your mouse. If you do that in the creative screen, it increments the stacksize of the itemstack you're holding by one.

 

Could anyone tell me if this is viable with a plain IInventory?

If not, what's the name of the class that handles the creative tabs slots? I can't find it.

 

 

Thanks in advance,

Pancake

  • Author

Alright, I couldn't find the class that manages the creative inventory, but I discovered a method in the Container Class that gets fired everytime a slot gets clicked (slotClick).

 

Now, I need to get the ItemStack the player is 'holding' with it's mouse. I tried EntityPlayer#getHeldItem and EntityPlayer#getItemInUse , neither give the desired ItemStack, and there are no other methods that return ItemStacks.

 

How can I access this ItemStack I'm talking about? I need to modify it's stacksize on specific conditions when clicking a slot.

 

Thanks in advance,

Pancake.

  • Author

~ Bump ~

 

Could someone please point me in the right direction? Still stuck on this... :'(

Assuming you are using GuiContainer, GuiContainer has a field called

field_146994_N

which is the ItemStack on the cursor right now.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

  • Author

Assuming you are using GuiContainer, GuiContainer has a field called

field_146994_N

which is the ItemStack on the cursor right now.

 

Yeah... and it's private with no getters. I suppose this is one of the situations where I'm obliged to use reflection? This doesn't feel right...

  • Author

Alright, I tried using reflection, and getting that field. It keeps returning null.

 

All relevant code:

 

public class GuiMainframeCore extends GuiContainer{
public GuiMainframeCore(InventoryPlayer inventoryPlayer,TileEntityMainframeCore entity) {
	super(new ContainerMainframeCore(inventoryPlayer,entity));
	((ContainerMainframeCore)inventorySlots).setGui(this);
	this.entity=entity;
	xSize=176;
	ySize=194;
}

public ItemStack getHeldItem(){
	try {
		Field heldItemField = GuiContainer.class.getDeclaredField("field_146994_N");
		heldItemField.setAccessible(true);
		return (ItemStack)heldItemField.get(this);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
}

 

public class ContainerMainframeCore extends Container {

private TileEntityMainframeCore entity;
private GuiMainframeCore gui;

public ContainerMainframeCore(InventoryPlayer inventoryPlayer,TileEntityMainframeCore entity){
	this.entity = entity;
	for(int i=0;i<entity.getSizeInventory();i++){
		addSlotToContainer(new Slot(entity,i,70+(i<6?0:18),10+(i<6?i:i-6)*18));
	}
	for(int x=0;x<9;x++){
		addSlotToContainer(new Slot(inventoryPlayer,x,8+18*x,150));
	}
}

@Override
public ItemStack slotClick(int slot, int mouseid, int p3,EntityPlayer player){
	if(gui!=null){
		System.out.println(gui.getHeldItem());
	}
	return super.slotClick(slot,mouseid,p3,player);
}

public void setGui(GuiMainframeCore gui){
	this.gui=gui;
}
}

 

... help.

  • Author

So... Yeah. I'm still looking for solutions. I really can't think of anything other than either:

* doing stuff in the tile entity that implements IInventory, which I tried and couldn't configure it the right way for my purposes.

* using that itemstack, which keeps returning null.

 

I'll rephrase my original question.

I want to make slots that do the same as the creative gui. They increase the held itemstack stacksize by 1 if clicked on the same item.

(I want to make some kind of shop, it will check if you have enough of a currency and then increment)

 

Please? :\

  • Author

I want to make slots that do the same as the creative gui. They increase the held itemstack stacksize by 1 if clicked on the same item.

(I want to make some kind of shop, it will check if you have enough of a currency and then increment)

 

~ Bump ~

 

I usually figure things out +-3 hours after I've posted my question on this forum. This isn't one of those times.  :'(

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.