Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.10.2] {Solved!!!} Right-Click Item for Chest-like GUI


EscapeMC
 Share

Recommended Posts

Why on earth are you passing in the player coordinates? That makes zero sense. These are not coordinates. They are 3 values that are passed through to your GUI handler. You can use them for whatever you want. Do you use them in your GUI handler for this GUI? No? Ok, then pass 0. Or -1. Or whatever ducking number you want.

 

Omg.

Link to comment
Share on other sites

  • Replies 125
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Let me make this as copy-paste friendly, as you want it, served warm and fresh:

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn,
		EnumHand hand) {
	playerIn.openGui(Main.instance, GuiHandler.TEST_BAG, worldIn, playerIn.getPos().getX(), playerIn.getPos().getY(), playerIn.getPos().getZ());
	return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
}

 

Well, as much as I did want to figure out myself, thank you for supplying my with this! I was actually just thinking about putting playerIn.getPos().get_ and I'm glad I was thinking along the right path!

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

You weren't and this is not the right solution.

And copy-paste friendly helps nobody.

 

You can't read my mind...? I was thinking to use .getPosition thank you very much.

 

What do I need to do then if that is not the right solution?

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

You weren't and this is not the right solution.

And copy-paste friendly helps nobody.

Sorry D': I was just trying to help, normally I don't give copy-paste stuff either but this was just... To much for my brain... And also, why is it not the right solution?

If you do use them as a block position, you must pass in a block position.

I use this for a block, that's why I thought it had to be the coörds

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

Link to comment
Share on other sites

Sorry D': I was just trying to help, normally I don't give copy-paste stuff either but this was just... To much for my brain... And also, why is it not the right solution?
It's not the right solution because you are just passing in the player position arbitrarily. Why? The numbers do not even get used in the GuiHandler here...

 

Again, these parameters are merely passed through to your GuiHandler. They are not used by FML/Forge in any way. What to pass in depends entirely on what your GuiHandler does with them.

 

I use this for a block, that's why I thought it had to be the coörds

If you use it for a block, you pass in the block coordinates. Not the player position...
Link to comment
Share on other sites

What you need to do depends entirely on what you do in your GUI handler. How do you use the xyz values there? If you don't use them, it does not matter what you pass in, just use 0.

If you do use them as a block position, you must pass in a block position.

 

Alright. That makes me think. Since it is not a block, I don't need position, hm? So I change them to 0s.

 

Second: I realize that I was using tileentity in my ContainerTestBag. I changed all the TE stuff to my capability class, but I not have this error:

"Cannot make a static reference to the non-static method getCapability(Capability<IItemHandler>, EnumFacing) from the type TestBagCapabilities"

 

https://github.com/EscapeMC/ThingsMod-1.10.2/blob/master/src/main/java/com/github/escapemc/thingsmod/container/ContainerTestBag.java#L18

 

at there. How can I fix this as well?

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

No need to be sorry. I just get aggravated about this particular topic, because I see so many people using openGui without understanding wtf it does. And it's so simple... Just 3 numbers passed to your GuiHandler.

 

Second: I realize that I was using tileentity in my ContainerTestBag. I changed all the TE stuff to my capability class, but I not have this error:

"Cannot make a static reference to the non-static method getCapability(Capability<IItemHandler>, EnumFacing) from the type TestBagCapabilities"

 

https://github.com/EscapeMC/ThingsMod-1.10.2/blob/master/src/main/java/com/github/escapemc/thingsmod/container/ContainerTestBag.java#L18

 

at there. How can I fix this as well?

So, you realized you don't have a TE. But something has to hold the capability. Let's think, what could that be... If only there was something that represented an item...
Link to comment
Share on other sites

No need to be sorry. I just get aggravated about this particular topic, because I see so many people using openGui without understanding wtf it does. And it's so simple... Just 3 numbers passed to your GuiHandler.

 

Second: I realize that I was using tileentity in my ContainerTestBag. I changed all the TE stuff to my capability class, but I not have this error:

"Cannot make a static reference to the non-static method getCapability(Capability<IItemHandler>, EnumFacing) from the type TestBagCapabilities"

 

https://github.com/EscapeMC/ThingsMod-1.10.2/blob/master/src/main/java/com/github/escapemc/thingsmod/container/ContainerTestBag.java#L18

 

at there. How can I fix this as well?

So, you realized you don't have a TE. But something has to hold the capability. Let's think, what could that be... If only there was something that represented an item...

 

How would I use and ItemStack here?

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

ItemStack

implements

ICapabilityProvider

. You obtain the capability from it in the same way you would from a TileEntity. Or any other capability provider.

 

So what do I do here

		IItemHandler inven = TestBagCapabilities.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

  to fix this? (Or am I looking at the wrong line?)

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

Dude... please. It is not hard.

You call

getCapability

. On the

ItemStack

.

 

I am doing this already! (I think)

 

package com.github.escapemc.thingsmod.container;

import com.github.escapemc.thingsmod.hardlib.api.internal.CommonContainer9x5;
import com.github.escapemc.thingsmod.hardlib.api.inventory.SlotItem;
import com.github.escapemc.thingsmod.items.TestBagCapabilities;
import com.github.escapemc.thingsmod.tileentity.TileEntityTestChest;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;

public class ContainerTestBag extends CommonContainer9x5 {
    private int numRows = 2;


public ContainerTestBag(InventoryPlayer inventory) {
	super(inventory, inventory, null);
	IItemHandler inven = TestBagCapabilities.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

        for (int j = 0; j < this.numRows; ++j)
        {
            for (int k = 0; k < 9; ++k)
            {
                this.addSlotToContainer(new SlotItem(inven, k + j * 9, 8 + k * 18, 12 + j * 18));
            }
        }


	}
}

Is my Container.

 

package com.github.escapemc.thingsmod.items;

import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;

public class TestBagCapabilities implements ICapabilitySerializable {

protected ItemStackHandler inputSlot;

public TestBagCapabilities() {
	inputSlot = new ItemStackHandler(18);



}

@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
	return this.getCapability(capability, facing) != null;
}

@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
	if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
		return (T) inputSlot;
	}
	return null;
}

@Override
public NBTBase serializeNBT() {
	NBTTagCompound NBTBase = new NBTTagCompound();
	((NBTTagCompound)NBTBase).setTag("inputSlot", inputSlot.serializeNBT());
	return NBTBase;

}

@Override
public void deserializeNBT(NBTBase nbt) {
	inputSlot.deserializeNBT(((NBTTagCompound) nbt).getCompoundTag("inputSlot"));


}


}

 

My ItemStack

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

Dude... please. It is not hard.

You call

getCapability

. On the

ItemStack

.

 

I am doing this already! (I think)

 

No, you're not. You're trying to call

TestBagCapabilities.getCapability

, as if it is a static method (which it isn't).

 

*is tearing out hair* Wait??? So then what is my itemstack? And would I use .getCapability to get the capability?

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

Dude... please. It is not hard.

You call

getCapability

. On the

ItemStack

.

 

I am doing this already! (I think)

 

No you're not.

 

IItemHandler inven = TestBagCapabilities.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

 

You're calling it (statically) on

TestBagCapabilities

, not on an

ItemStack

.

 

public class TestBagCapabilities implements ICapabilitySerializable

 

My ItemStack

 

That is not an item stack, that is TestBagCapabilities which is an ICapabilitySerializable.

 

And again,

TestBagCapabilities.getCapability()

doesn't exist,

TestBagCapabilities#getCapability()

does.

 

If you want an item stack, pass the item stack from your GUI handler to your container, or get it from the player's active item.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Dude... please. It is not hard.

You call

getCapability

. On the

ItemStack

.

 

I am doing this already! (I think)

 

No you're not.

 

IItemHandler inven = TestBagCapabilities.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

 

You're calling it (statically) on

TestBagCapabilities

, not on an

ItemStack

.

 

public class TestBagCapabilities implements ICapabilitySerializable

 

My ItemStack

 

That is not an item stack, that is TestBagCapabilities which is an ICapabilitySerializable.

 

And again,

TestBagCapabilities.getCapability()

doesn't exist,

TestBagCapabilities#getCapability()

does.

 

If you want an item stack, pass the item stack from your GUI handler to your container, or get it from the player's active item.

 

Ok, this clarifies several things. Thank you Draco.

Yet still, I do not understand where my ItemStack is I need to use, and the more I look, the more confused I get.

Could you potentially go through my GitHub, highlight lines, and tell me what I need to do? I would appreciate it if you could. If not, hint me toward my next step...?

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

You need to get it from the player. 

Player#getHeldItem(EnumHand.Main)

IIRC.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

With that info, what do I need to make

		IItemHandler inven = getHeldItem(EnumHand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

 

Into? (Yes, I know what is far from correct right now. Iw as editing it and I forgot to go back)

I Love To Help People. Unless They Are The Kind Of People Who Just Doesn't Know Anything. Those People Need Some Serious Help. This Could Help But......

https://www.youtube.com/watch?v=6t0GlXWx_PY

 

ThingsMod Git: https://github.com/EscapeMC/Things-Mod-1.10.2

 

TeamMadness Mod Git: https://github.com/EscapeMC/TeamMadness-Mod-1.10.2

 

If I somehow help you, please click the "Thank You" button. If I am a total waste of time, please click the "Applaud" button.

Link to comment
Share on other sites

With that info, what do I need to make

		IItemHandler inven = getHeldItem(EnumHand.MAIN_HAND).getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

 

Into? (Yes, I know what is far from correct right now. Iw as editing it and I forgot to go back)

 

You need to call

getHeldItem

on the player. You could pass the player to the constructor of your container, or get the player from the InventoryPlayer which is already in the constructor -

inventory.player

.

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

 Share




×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.