Jump to content

[1.7.10] Creative Tab Functionality


Pancake

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? :\

Link to comment
Share on other sites

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.  :'(

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.