use of net.minecraft.world.level.block.entity.HopperBlockEntity in project MinecraftForge by MinecraftForge.
the class VanillaInventoryCodeHooks method insertStack.
/**
* Copied from TileEntityHopper#insertStack and added capability support
*/
private static ItemStack insertStack(BlockEntity source, Object destination, IItemHandler destInventory, ItemStack stack, int slot) {
ItemStack itemstack = destInventory.getStackInSlot(slot);
if (destInventory.insertItem(slot, stack, true).isEmpty()) {
boolean insertedItem = false;
boolean inventoryWasEmpty = isEmpty(destInventory);
if (itemstack.isEmpty()) {
destInventory.insertItem(slot, stack, false);
stack = ItemStack.EMPTY;
insertedItem = true;
} else if (ItemHandlerHelper.canItemStacksStack(itemstack, stack)) {
int originalSize = stack.getCount();
stack = destInventory.insertItem(slot, stack, false);
insertedItem = originalSize < stack.getCount();
}
if (insertedItem) {
if (inventoryWasEmpty && destination instanceof HopperBlockEntity) {
HopperBlockEntity destinationHopper = (HopperBlockEntity) destination;
if (!destinationHopper.isOnCustomCooldown()) {
int k = 0;
if (source instanceof HopperBlockEntity) {
if (destinationHopper.getLastUpdateTime() >= ((HopperBlockEntity) source).getLastUpdateTime()) {
k = 1;
}
}
destinationHopper.setCooldown(8 - k);
}
}
}
}
return stack;
}
Aggregations