Jump to content

[1.11.2] A problem with Item handler capability


tommyte

Recommended Posts

Hello everyone,

 

I'm working on a multiblock structure with a core tile entity that should store all the data, like items. I got another tile entity in the multiblock that should be able to in- and output items to and from the inventory of that core tile entity. I tried to achieve this by returning the instance of the ItemStackHandler of the core tile entity in the getCapability method in the other tile entity. It looks like this:

//The class that should in and output to the core tile entity
public class TileEntityMultiblockItemHandler extends TileEntity implements IMultiblockTileEntity{

	private TSMultiblock block;
	
	public TileEntityMultiblockItemHandler()
	{
		
	}
	
	@Override
	public TSMultiblock getMultiblock() 
	{
		return ((IMultiblockBlock)world.getBlockState(pos).getBlock()).getMultiblock(world, pos);
	}
	
	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) 
	{
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) 
		{
			return true;
		}
		return super.hasCapability(capability, facing);
	}
	
	@Override
	public <T> T getCapability(Capability<T> capability, EnumFacing facing) 
	{
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) 
		{
			return (T) getMultiblock().getCoreEntity().getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
		}
		return super.getCapability(capability, facing);
	}

	@Override
	public void onMultiblockLoad() 
	{
		
	}
}

 

And

 

//The core tile entity
public class TileEntityFabricator extends TileEntityMachineBasic implements ITickable, IInteractionObject, ITileEntityInterface{

	private int currentFormTime;
	private int totalFormTime;
	private int energyConsumption;
	private TSEnergyStorage energy;
	private TSItemStorage inventory;
	
	public TileEntityFabricator()
	{
		totalFormTime = TSConfigHandler.runtimeFabricator;
		currentFormTime = 0;
		energyConsumption = TSConfigHandler.fabricatorConsumption;
		energy = new TSEnergyStorage(10000, 0, 0);
		inventory = new TSItemStorage(10);
	}
	
	//I left a bunch of methods out here
	
	@Override
	public boolean hasCapability(Capability<?> capability, EnumFacing facing) 
	{
		if (capability == CapabilityEnergy.ENERGY) 
		{
			return true;
		}
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) 
		{
			return true;
		}
		return super.hasCapability(capability, facing);
	}
	
	@Override
	public <T> T getCapability(Capability<T> capability, EnumFacing facing) 
	{
		if (capability == CapabilityEnergy.ENERGY) 
		{
			return (T) energy;
		}
		if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) 
		{
			return (T) inventory;
		}
		return super.getCapability(capability, facing);
	}
}

 

The problem: when I attach a hopper to the itemhandler tile entity, it inputs items, but I can't see them on the gui. Furthermore, I can get the items I put in out again with a hopper, but the items inside that I can see and access through the gui stay put. What have I done wrong?

Edited by tommyte
quick spelling corrections (:
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.

Announcements



×
×
  • Create New...

Important Information

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