Jump to content

Recommended Posts

Posted

Feels like a bit of an oversight that the ItemStackHandler class doesn't have a "how many slots do you have" method, especially considering that it throws a runtime exception if you try to access a slot outside its size.

 

On top of that, there doesn't appear to be a suggested way for a block to tell its own TE to drop all of its contents without performing a cast from TileEntity to something else (either its own TE type or custom interface) as there's no ability to be certain (using generic code) to determine that "yes, I've accessed every ItemStackHandler capability the tile can provide."

 

I mean, I'm fine creating my own helper interface that I apply to my TEs so I can just do this:

	public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
        TileEntity tileentity = worldIn.getTileEntity(pos);

        if (tileentity instanceof IInvenCapHelper) {
            ((IInvenCapHelper)tileentity).dropAllItems(worldIn, pos);
        }

        super.breakBlock(worldIn, pos, state);
    }

And then manually looping through all the slots my TE knows it has for all of its ItemStackHandler instances:

	@Override
public void dropAllItems(World worldIn, BlockPos pos) {
	ItemStack stack;
	//magic number `n` because ItemStackHandler does not have a .getSize()
	for(int i=0; i < n; i++) {
		stack = inputSlots.getStackInSlot(i);
		EntityItem entityIn;
		if(stack != null) {
			entityIn = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), stack);
			entityIn.setDefaultPickupDelay();
			worldIn.spawnEntityInWorld(entityIn);
		}
	}
	//repeat for outputSlots and any other ItemStackHandler instances
}

 

Or am I missing something?

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.

Posted

Feels like a bit of an oversight that the ItemStackHandler class doesn't have a "how many slots do you have" method, especially considering that it throws a runtime exception if you try to access a slot outside its size.

It does,
getSlots

.

 

....How in the hell did I overlook that.

 

Usually
getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)

will give you a "full access" handler.

 

I think that entirely depends on how the block handles its inventory.

 

For example, if I have a block like the furnace which I want to have sided access I need to return a different capability depending on the side (or the possibility of inputting to the output slot exists).

 

Ergo:

	inputSlot = new ItemStackHandler(1);
outputSlot = new ItemStackHandler(1);

 

How would I then go about returning both in the case of a null side?

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.

Posted

Crafty.

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.

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.

Announcements



×
×
  • Create New...

Important Information

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