int z = MiscTools.getZOnSide(zCoord, direction);
if ((spawn.getItem() instanceof ItemMinecart || spawn.getItem() instanceof IMinecartItem)
&& CartTools.getMinecartOnSide(worldObj, xCoord, yCoord, zCoord, 0, direction) == null) {
ItemStack cartItem = InvTools.removeOneItem(invStock, filter);
if (cartItem != null) {
EntityMinecart cartPlaced = CartTools.placeCart(getOwner(), cartItem, (WorldServer) worldObj, x, y, z);
if (cartPlaced != null) {
CartTools.getLinkageManager(worldObj).createLink(cartPlaced, lastCart);
lastCart = cartPlaced;
patternIndex++;
if (patternIndex >= getPattern().getSizeInventory())