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.

[1.11.2] Allow certain slots of ItemHandler only be accessible from certain sides

Featured Replies

Posted

With the old IInventory, you could specify which slots would be accessed from what side.

How can I do the same with ItemHandlers? I want to make an input slot (0) that allows the player to remove the item, but not pipes (or only from below), so that the process

of the machine doesn't get interrupted by the pipe pulling out the ingredients.

In short: I want the pipes to be able to only access the output slots (1 and 2).

 

I currently have this code:

package tschipp.pathology.tileentity.handler;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.items.ItemStackHandler;
import tschipp.pathology.item.PAItems;

public class ItemHandlerMicroscope extends ItemStackHandler {

	public ItemHandlerMicroscope() {
		super(3);
		this.setSize(3);
	}


	@Override
	public void deserializeNBT(NBTTagCompound nbt)
	{
		setSize(3);
		NBTTagList tagList = nbt.getTagList("Items", Constants.NBT.TAG_COMPOUND);
		for (int i = 0; i < tagList.tagCount(); i++)
		{
			NBTTagCompound itemTags = tagList.getCompoundTagAt(i);
			int slot = itemTags.getInteger("Slot");

			if (slot >= 0 && slot < stacks.size())
			{
				stacks.set(slot, new ItemStack(itemTags));
			}
		}
		onLoad();
	}


	@Override
	public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {

		if(slot == 0 && !stack.isEmpty() && (stack.getItem() == PAItems.bloodSyringe) || (stack.getItem() == PAItems.virusSyringe && !stack.hasTagCompound() || !stack.getTagCompound().hasKey("researched") || !stack.getTagCompound().getBoolean("researched")))
			return super.insertItem(slot, stack, simulate);
		else return stack;
	}


	public void insertSyringe(int slot, ItemStack stack)
	{
		ItemStack slotStack = this.getStackInSlot(slot);
		int count = slotStack.getCount();
		if(count == 0)
			this.setStackInSlot(slot, stack);
		else
		{
			slotStack.setCount(count + 1);
		}

	}

}

 

Any help is very much appreciated

Likely whatever feature your about to ask for is already possible. You can combine ItemHandlers already, so you'd just spilt them up and combine them as needed. 

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/farming/entities/TileEntityTanner.java#L143

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

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.