Jump to content

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


Recommended Posts

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

Posted

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

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