Thank you. Could you tell me the right way to return my overridden methods at getCapability?
That's what I have so far:
private final IItemHandler inv = new ItemStackHandler(4) {
@Override
protected void onContentsChanged(int slot) {
super.onContentsChanged(slot);
markDirty();
}
@Override
public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
// My checks to see if an item is valid in the slot
}
};
private final LazyOptional<IItemHandler> capItemHandler = LazyOptional.of(() -> createCapabilityHandler());
protected IItemHandler createCapabilityHandler() {
return new CombinedInvWrapper(this.inv) {
@Override
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
// Only insert, if stack is valid for the slot
return (isItemValid(slot, stack)) ? super.insertItem(slot, stack, simulate) : stack;
}
@Override
public ItemStack extractItem(int slot, int amount, boolean simulate) {
// Only pull items from the output slots
return (slot == 2 || slot == 3) ? super.extractItem(slot, amount, simulate) : ItemStack.EMPTY;
}
};
}
public <T> LazyOptional<T> getCapability(Capability<T> cap, @Nullable EnumFacing side) {
return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.orEmpty(cap, capItemHandler);
}
It's working so far, but I used the CombinedInvWrapper even tho I'm just using one IItemHandler. I figured I don't need to use different sides, I'll allow inserting/extracting on every side.
Is there any better way to do this or is my attempt fine?
Thanks so far.